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

2017/6/25

How can I set a Endscreenimage when my actor gets destroyed by a bomb?

Laserbrot Laserbrot

2017/6/25

#
First of all I created a Bombermangame in which the bomb destroys the two players with: "public void spielerEntfernen() { getWorld().removeObjects(getNeighbours(getRadius(), false, Player1.class)); getWorld().removeObjects(getNeighbours(getRadius(), false, Player2.class)); } " This method is written down in my bomb.class where the method spielerEntfernen() is written in act() . Now I want to set a Endscreen on which stands "Player1/Player2 won" (The two pictues are already created), when one of these players gets removed by the bomb. Thanks you in Advance.
danpost danpost

2017/6/25

#
You could simply put the following in your World subclass act method:
if (getObjects(Player1.class).isEmpty() && getObjects(Player2.class).isEmpty())
{
    // show no one wins
    Greenfoot.stop();
}
else if (getObjects(Player1.class).isEmpty())
{
    // show player2 wins
    Greenfoot.stop();
}
else if (getObjects(Player2.class).isEmpty())
{
    // show player1 wins
    Greenfoot.stop();
}
danpost danpost

2017/6/25

#
You could also write it like this in the act method:
if (getObjects(Player1.class).isEmpty() || getObjects(Player2.class).isEmpty())
{
    showGameOver();
    Greenfoot.stop();
}
and add the following method to the World subclass:
private void showGameOver()
{
    GreenfootImage gameOverImage = null;
    if (getObjects(Player1.class).isEmpty() && getObjects(Player2.class).isEmpty())
    {
        gameOverImage = << no one wins image >>;
    }
    else if (getObjects(Player1.class).isEmpty())
    {
        gameOverImage = << player2 wins image >>;
    }
    else if (getObjects(Player2.class).isEmpty())
    {
        gameOverImage = << player1 wins image >>;
    }
    // show gameOverImage here
}
You need to login to post a reply.