Hi
I am working with Frogger for school, and I need a live counter. I came far, but I don't know how to make the lives go down or up.
Please help me.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | import greenfoot.*; import java.awt.Color; public class Lifeboard extends Actor { int lives = 3 ; public Lifeboard() { updateBoard(); } private void updateBoard() { setImage( new GreenfootImage( "Lives remaining: " + lives, 20 , Color.black, new Color( 0 , 0 , 0 , 0 ))); } public void add( int addVal) { if (lives == 0 && addVal == - 1 ) { // ^ (lost a life and no lives remaining) // play sound, showGameOver/Final score // whatever you want to do for ending game Greenfoot.stop(); return ; } lives += addVal; updateBoard(); } public int getLivesLeft() { return lives; } public void livesDown(){ lives = lives - 1 ; if ( lives == 0 ){ Greenfoot.stop(); return ; } } } |