public int lifeCounter = 3;
import greenfoot.*;
public class Space extends World
{
int lifeCounter = 3;
public Space()
{
super(500, 550, 1);
// intro.play();
populate();
}
public void populate()
{
// populate code
}
public void act()
{
checkLifeStatus();
}
private void checkLifeStatus()
{
if (getObjects(Player.class).isEmpty())
{
lifeCounter--;
if (lifeCounter == 0) gameOver();
addObject(new Player(), 250, 510);
}
}
private void gameOver()
{
System.out.println("GAME OVER");
Greenfoot.stop();
}
}import greenfoot.*; // imports Actor, World, Greenfoot, GreenfootImage
/**
* Write a description of class Space here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Space extends World
{
public int lifeCounter = 3;
GreenfootSound intro = new GreenfootSound("pacman_beginning.wav");
/**
* Constructor for objects of class Space.
*/
public Space()
{
super(500, 550, 1);
//intro.play();
populate();
}
public void act()
{
checkLifeStatus(lifeCounter);
}
private void gameOver()
{
System.out.println("GAME OVER");
Greenfoot.stop();
}
private void checkLifeStatus(int lifeCounter){
if (getObjects(Player.class).isEmpty());
{
lifeCounter -- ;
if (lifeCounter == 0) gameOver();
addObject(new Player(), 250, 510);
}
}
/**
* Prepare the world for the start of the program. That is: create the initial
* objects and add them to the world.
*/
private void populate()
{
Player player = new Player();
addObject(player, 250, 510);
Tetrimino tetrimino0 = new Tetrimino(0);
tetrimino0.setSpeed(2);
addObject(tetrimino0,30,50);
Tetrimino tetrimino1 = new Tetrimino(1);
tetrimino1.setSpeed(4);
addObject(tetrimino1,30,100);
Tetrimino tetrimino2 = new Tetrimino(2);
tetrimino2.setSpeed(1);
addObject(tetrimino2,30,150);
Tetrimino tetrimino3 = new Tetrimino(3);
tetrimino3.setSpeed(3);
addObject(tetrimino3,30,200);
Invader invader0 = new Invader(0);
invader0.setSpeed(4);
addObject(invader0,30,300);
Invader invader1 = new Invader(1);
invader1.setSpeed(8);
addObject(invader1,30,350);
Invader invader2 = new Invader(2);
invader2.setSpeed(2);
addObject(invader2,30,400);
Invader invader3 = new Invader(3);
invader3.setSpeed(6);
addObject(invader3,55,450);
}
}