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

2017/3/4

Game over screen with final score

JokeNotFound JokeNotFound

2017/3/4

#
Hello, So i want to display a game over screen which i created with paint at the end of the game when my timer is at zero. I also want it to show the achieved score right below the game over. My idea was to remove all objects if timer= 0 and change the background of the world. In addition i would add a simple lettering which displays the scoreboard's final number when timer=0. Also possible would be to create a Gameover screen class and if timer=0 i just do addObject("gameoverscreen"). Could anyone give me an example for that as i am a rookie programmer with greenfoot? Thank you very much in advance!!!
Super_Hippo Super_Hippo

2017/3/4

#
Do one step at a time. With which part do you have problems?
JokeNotFound JokeNotFound

2017/3/4

#
I have problems with formulation a working code because i didnt have any introduction into greenfoot programming
JokeNotFound JokeNotFound

2017/3/4

#
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
public class MyWorld extends World
{
public ScoreBoard sb;
private int time = 0;
public MyWorld()
    { sb = new ScoreBoard();
        addObject(sb, 50, 20);
         
        Greenfoot.setSpeed(50);
        prepare(); }
private void prepare()
{
    time = 3300;
    //adding objects here
}
public void act()
    {
       if (time%55 == 0) showText(""+(time/55), 50, 50);
            
        time--;
       if (time == 0)
       {
        removeObjects(getObjects(null));
        prepare();
         
       }}}
Thats my timer's code so far. My scoreboard is as follows :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.List;
public class ScoreBoard extends Actor
{
   /**
     * Act - do whatever the ScoreBoard wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() {
         
    }   
     
    public void edit(int treffer) {
        setImage(new GreenfootImage(treffer + " Treffer", 25, Color.WHITE, Color.BLACK));
    }
}
What do i do now?
Super_Hippo Super_Hippo

2017/3/4

#
Maybe something like this:
1
2
3
4
5
6
7
if (time==0)
{
    removeObjects(getObjects(null));
    setBackground("imageDrawnWithPaint.png");
    GreenfootImage scoreImg = new GreenfootImage(""+sb.getTreffer(), 20, Color.BLACK, new Color(0,0,0,0));
    getBackground().drawImage(scoreImg, getWidth/2-scoreImg.getWidth()/2, getHeight()/2-scoreImg.getWidth()/2);
}
Replace 'sb.getTreffer()' by something which returns the value you want to display. 'sb.getTreffer()' will work if you add this in your ScoreBoard class:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
private int treffer = 0;
 
public ScoreBoard()
{
    edit(0);
}
 
public void edit(int treffer)
{
    this.treffer = treffer;
    setImage(........);
}
 
public int getTreffer()
{
    return treffer;
}
You need to login to post a reply.