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

2012/6/14

If Counter =...

Prudene Prudene

2012/6/14

#
I need a code that shows a text if a counter gets set to 0.
trash1000 trash1000

2012/6/14

#
This forum is to ask for help and not for someone else do all of your work. Other than that you did not explain how you want to implement your counter, so there's nothing to start on helping you with...
if(counter == 0) {
    System.out.println("Counter was set to 0");
}
See? That wasn't that helpful I guess.
Prudene Prudene

2012/6/14

#
Ok, sorry about that. The counter I made up:
public class GoodCounter  extends Actor
{
    private int totalCount = 100;

    public GoodCounter()
    {
        setImage(new GreenfootImage("100", 50, Color.ORANGE, Color.BLACK));
    }
public void bumpCount(int amount)
{
{
    totalCount += amount;
    setImage(new GreenfootImage("" + totalCount, 50, Color.ORANGE, Color.BLACK));
}
}
}
I set the bumpCount in another class to "-5" so that everytime an action takes place, the counter loses 5 points, Now i want the counter image to become a text like "You lose" if it reaches 0 points.
trash1000 trash1000

2012/6/15

#
public void bumpCount(int amount) {
    totalCount += amount;
    if(totalCount > 0) {
        setImage(new GreenfootImage("" + totalCount, 50, Color.orange, Color.black));
    }
    else {
        setImage(new GreenfootImage("You lose!", 50, Color.orange, Color.black));
    }
}
First you change the counter value with the given parameter. Then you check if the counter is still greater than 0, if not you set the image to the lose message.
Prudene Prudene

2012/6/18

#
Thanks! Thanks a lot! :DD I know this is a bit late, but that really helped me with my project :)
You need to login to post a reply.