As of right now I have code that randomly places an object somewhere on the screen. I want the whole code to stop when all of them are removed
public void act() { if (getObjects(Zombie.class).isEmpty()) Greenfoot.stop(); }
public void Worm(){ // automaticalay randomize different placed worms on screen while( i < 10){ x = Greenfoot.getRandomNumber(560); y = Greenfoot.getRandomNumber(560); Worm W1 = new Worm(); addObject (W1,x,y); i++; } } public void Stop(){ if(getObjects(Worm.class).isEmpty()){ Greenfoot.stop(); } }
public void act() { if (getObjects(Zombie.class).isEmpty()) Greenfoot.stop(); }
public void act(){//stop the game when all worms are eaten or crab is removed List numL= getObjects(Lobster.class); if (getObjects(Worm.class).isEmpty()){ removeObjects(numL); List numC= getObjects(Crab.class); removeObjects(numC); setBackground("win.png"); Greenfoot.stop(); } if (getObjects(Crab.class).isEmpty()){ removeObjects(numL); List numW= getObjects(Worm.class); removeObjects(numW); setBackground("lose.png"); Greenfoot.stop(); } }
return;
private int rotate=0; public void checkEdge(){ //see if the Lobster is at the edge if(isAtEdge()){ rotate=rotate+90; setRotation(rotate); turn(-15); } public void turnCrab(){//constantly turn the Lobster in a small area if(one==false){ turn(15); y=getY(); one=true; } x=getY(); if(rotate%180!=0 && x==y+20){ turn(15); }
setRotation(getRotation()+90); // or just turn(90);
if (isAtEdge) turn(90);