This site requires JavaScript, please enable it in your browser!
Greenfoot back
charliejustshrekedyou
charliejustshrekedyou wrote ...

2019/3/23

How do I end my game when my lives counter == 0??

How do I apply if statements in order to end the game? public class Counter extends Actor { int health = 5; /** * Act - do whatever the Counter wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { setImage(new GreenfootImage("Lives : " + health, 24, Color.BLUE, Color.BLACK)); } public void loseHealth(int amount) { health += amount; setImage(new GreenfootImage("Lives : " + health, 24, Color.BLUE, Color.BLACK)); } }
Super_Hippo Super_Hippo

2019/3/23

#
At the end of the "loseHealth"-method, add this line:
if (health<1) Greenfoot.stop();
Btw, change "public void act()" to "public Counter()".
cool, thanks!
You need to login to post a reply.