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

2016/3/30

Game Over Screen

1
2
danpost danpost

2016/3/30

#
Well, sort of -- it is just the condition that would be similar (but not quite the same). Line 3 asks if there is a GameOver object in the world -- you would need to ask if there are no players in the world.
Sir_brandon_ Sir_brandon_

2016/3/30

#
so something more like this public void started() { if ( ! getObjects(Whatevertheplayersnameis.class).isEmpty() ) Greenfoot.stop(); //example }
danpost danpost

2016/3/30

#
Sir_brandon_ wrote...
so something more like this public void started() { if ( ! getObjects(Whatevertheplayersnameis.class).isEmpty() ) Greenfoot.stop(); //example }
Yeah. But just what is between the parenthesis is what you will take from for your code in the act method. You will not be using the quoted code at all (no need for the 'started' method in your world class because you are using a different type World object for the game over screen -- not an Actor object). I was trying to say that you need to use the 'getObjects' method to list the players in the world and then ask if the list is empty to determine when to proceed to the GameOverScreen world.
Sir_brandon_ Sir_brandon_

2016/3/30

#
ok i put it in but it did nothing so i put it in both worlds GameOverScreen:
import greenfoot.*;

/**
 * Write a description of class GameOverScreen here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class GameOverScreen extends World
{

    /**
     * Constructor for objects of class GameOverScreen.
     * 
     */
    public GameOverScreen()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(600, 400, 1); 
        if ( ! getObjects(Player_p1.class).isEmpty() ) Greenfoot.stop();
        prepare();
    }

    /**
     * Prepare the world for the start of the program. That is: create the initial
     * objects and add them to the world.
     */
    private void prepare()
    {
        Back_button back_button2 = new Back_button();
        addObject(back_button2, 294, 333);
        GameOverText gameovertext = new GameOverText();
        addObject(gameovertext, 309, 175);
        gameovertext.setLocation(300, 176);
    }
}
and in Playerx2 :
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class CrabWorld here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Playerx2 extends World
{

    /**
     * Constructor for objects of class CrabWorld.
     * 
     */
    public Playerx2()
    { 
        super(1000, 660, 1);
        if ( ! getObjects(Player_1.class).isEmpty() ) Greenfoot.stop();
        prepare();
danpost danpost

2016/3/30

#
Remove line 20 from GameOverScreen class and remove line 19 from Playerx2 class. (a) you are not going to 'stop' the scenario if no players are in the world (b) you need to check on both players (c) this code needs to be in an act method of your game world
if (getObjects(Player_1.class).isEmpty() && getObjects(Player_2.class).isEmpty()) Greenfoot.setWorld(new GameOverScreen());
Sir_brandon_ Sir_brandon_

2016/3/30

#
ok i did that but, it still cept playing the world and wont go to the GameOverScreen world. Did i put the code in right?
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class CrabWorld here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Playerx2 extends World
{

    /**
     * Constructor for objects of class CrabWorld.
     * 
     */
    public Playerx2()
    { 
        super(1000, 660, 1);
        if (getObjects(Player_1.class).isEmpty() && getObjects(Player_2.class).isEmpty()) Greenfoot.setWorld(new GameOverScreen());
        prepare();
    }
danpost danpost

2016/3/30

#
danpost wrote...
(c) this code needs to be in an act method of your game world
You placed the code in the constructor of the world -- not in the act method.
Sir_brandon_ Sir_brandon_

2016/3/30

#
thanks :)
You need to login to post a reply.
1
2