I just published my source code
I do not understand the Java Lang Runtime JavaScript error
Thank you for your help
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Smiley here. * * @author (your name) * @version (a version number or a date) */ public class Tie extends Actor { private static final int SPEED = 2; private int deltaX; private int deltaY; private DeathStar home; public Tie(DeathStar home) { deltaX = 0; deltaY = 0; } public void act() { hitFire(); randomFly(); } public void hitFire() { Actor laser = getOneIntersectingObject(Laser.class); if (laser != null) { getWorld().removeObject(this); } else if (isAtEdge() != false) { getWorld().removeObject(this); } } public void randomFly() { if (randomChance(50)) { deltaX = adjustSpeed(deltaX); deltaY = adjustSpeed(deltaY); } fly(); } public void fly() { setLocation(getY() + deltaX, getY() + deltaY); } private int adjustSpeed(int speed) { speed = speed + Greenfoot.getRandomNumber(2*SPEED - 1) - SPEED + 1; return capSpeed(speed); } private int capSpeed(int speed) { if (speed < -SPEED) return -SPEED; else if (speed > SPEED) return SPEED; else return speed; } private boolean randomChance(int percent) { return Greenfoot.getRandomNumber(100) < percent; } }
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Counter here. * * @author (your name) * @version (a version number or a date) */ public class Counter extends Actor { private int value = 0; private String text; public Counter() { this(""); } public Counter(String prefix) { text = prefix; int imageWidth = (text.length() + 2) * 10; setImage(new GreenfootImage(imageWidth, 16)); updateImage(); } public void increment() { value++; updateImage(); } public void updateImage() { GreenfootImage image = getImage(); image.clear(); image.drawString(text + value, 1, 12); } }
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class DeathStar here. * * @author (your name) * @version (a version number or a date) */ public class DeathStar extends Actor { private int ties = 0; private int maxTies = 50; private int imperials = 0; private int maxImperials = 10; private Counter tieCounter; private Counter imperialCounter; public DeathStar() { } public DeathStar(int numberOfTies, int numberOfImperials) { maxTies = numberOfTies; maxImperials = numberOfImperials; } public void act() { if (ties < maxTies) { if (Greenfoot.getRandomNumber(100) < 10) { getWorld().addObject(new Tie(this), getX(), getY()); ties++; } } if (imperials < maxImperials) { if (Greenfoot.getRandomNumber(100) < 10) { getWorld().addObject(new Imperial(this), getX(), getY()); imperials++; } } } public void countTie() { if (tieCounter == null) { tieCounter = new Counter("Tie : "); int x = getX(); int y = getY() + getImage().getWidth()/2 + 8; getWorld().addObject(tieCounter, x, y); } tieCounter.increment(); } public void countImperial() { if (imperialCounter == null) { imperialCounter = new Counter("Imperial : "); int x = getX(); int y = getY() + getImage().getWidth()/2 + 16; getWorld().addObject(imperialCounter, x, y); } imperialCounter.increment(); } }
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Smiley here. * * @author (your name) * @version (a version number or a date) */ public class Tie extends Actor { private static final int SPEED = 2; private int deltaX; private int deltaY; private DeathStar home; public Tie(DeathStar home) { deltaX = 0; deltaY = 0; } public void act() { randomFly(); hitFire(); } public void hitFire() { Actor laser = getOneIntersectingObject(Laser.class); if (laser != null) { getWorld().removeObject(this); } else if (isAtEdge() != false) { getWorld().removeObject(this); } } public void randomFly() { if (randomChance(5)) { deltaX = adjustSpeed(deltaX); deltaY = adjustSpeed(deltaY); } fly(); } public void fly() { setLocation(getX() + deltaX, getY() + deltaY); } private int adjustSpeed(int speed) { speed = speed + Greenfoot.getRandomNumber(2*SPEED - 1) - SPEED + 1; return capSpeed(speed); } private int capSpeed(int speed) { if (speed < -SPEED) return -SPEED; else if (speed > SPEED) return SPEED; else return speed; } private boolean randomChance(int percent) { return Greenfoot.getRandomNumber(100) < percent; } }
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Counter here. * * @author (your name) * @version (a version number or a date) */ public class Counter extends Actor { private int value = 0; private String text; public Counter() { this(""); } public Counter(String prefix) { text = prefix; int imageWidth = (text.length() + 2) * 10; setImage(new GreenfootImage(imageWidth + 20, 16)); updateImage(); } public void increment() { value++; updateImage(); } public void updateImage() { GreenfootImage image = getImage(); image.clear(); image.setColor(Color.WHITE); Font font = image.getFont().deriveFont(30); image.setFont(font); image.drawString(text + value, 1, 12); } }
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Missile here. * * @author (your name) * @version (a version number or a date) */ public class FalconLaser extends Actor { /** * Act - do whatever the Missile wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public Counter tieCounter; public Counter imperialCounter; public FalconLaser() { setRotation(270); tieCounter = new Counter("Ties : "); imperialCounter = new Counter("Imperials : "); } protected void addedToWorld(World world) { world.addObject(tieCounter, 150, 150); world.addObject(imperialCounter, 150, 200); } public void act() { move(5); destroyTie(); destroyImperial(); } public void destroyTie() { Tie tie = (Tie) getOneIntersectingObject(Tie.class); if (tie != null) { getWorld().removeObject(tie); getWorld().removeObject(this); tieCounter.increment(); } } public void destroyImperial() { Imperial imperial = (Imperial) getOneIntersectingObject(Imperial.class); if (imperial != null) { getWorld().removeObject(imperial); getWorld().removeObject(this); imperialCounter.increment(); } } }