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
![Twitter](/assets/twitter-4e19209ef84344ee0c433f4c7bad8d49.png)
![Twitter.hover](/assets/twitter.hover-1fb19a5bafc50deace8f88eaec867845.png)
1 2 3 4 | public void act() { if (getObjects(Zombie. class ).isEmpty()) Greenfoot.stop(); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | 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(); } } |
1 2 3 4 | public void act() { if (getObjects(Zombie. class ).isEmpty()) Greenfoot.stop(); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 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(); } } |
1 | return ; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 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 ); } |
1 2 3 4 | setRotation(getRotation()+ 90 ); // or just turn( 90 ); |
1 | if (isAtEdge) turn( 90 ); |