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

2018/5/28

How to show a you lose screen at zero points.

AliZahid28 AliZahid28

2018/5/28

#
In my game if the car hits the house it gets a gameover/you win screen. I used this code to do that.
1
2
3
4
5
6
7
if (isTouching(House.class))
       {
          World myWorld = getWorld();
          
          GameOver gameover = new GameOver();
          myWorld.addObject(gameover, myWorld.getWidth()/ 2, myWorld.getHeight() / 2);
       }
I tried to do something similar with the counter.
1
2
3
4
5
6
7
if (counter=0)
       {
          World myWorld = getWorld();
          
          YouLose youlose = new YouLose();
          myWorld.addObject(youlose, myWorld.getWidth()/ 2, myWorld.getHeight() / 2);
       }
It says can not find symbol variable counter. So how can I make it so that if the counter = 0 it shows the you lose screen.
Yehuda Yehuda

2018/5/28

#
More information is necessary to give a detailed explanation for your scenario. Where is the counter variable and where are you trying to access it from? Why do you not just have the game over code in the class that has the counter variable?
1
2
3
4
5
6
7
8
9
// if it's an Actor
if (counter == 0) {
    getWorld().addObject(new YouLose(), getWorld().getWidth() / 2, getWorld().getHeight() / 2);
}
 
// if it's a World
if (counter == 0) {
    addObject(new YouLose(), getWidth() / 2, getHeight() / 2);
}
You need to login to post a reply.