hello actually i have something to ask ....how can i end a game with multiple of object for example : in MyWorld i have butterfly,elephant etc and after all the actor clicked and removed another actor appear represent that game already over...
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Banana here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Banana extends Actor
{
private static final int EAST = 0;
private static final int WEST = 1;
private int direction;
/**
* Act - do whatever the Banana wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if ( canMove() )
{
move();
}
else
{
turnRandom();
}
if(Greenfoot.mouseClicked(this))
{
getWorld().removeObject(this);
System.out.println("bagus! dah habis");
Greenfoot.playSound ( "15 FUNKY.mp3");
}
}
public void move()
{
if (!canMove()) {
return;
}
switch(direction) {
case EAST :
setLocation(getX() + 1, getY());
break;
case WEST :
setLocation(getX() - 1, getY());
break;
}
}
public boolean canMove()
{
int x = getX();
int y = getY();
switch(direction) {
case EAST :
x++;
break;
case WEST :
x--;
break;
}
if ( x == 599 || x == 0 )
{
return false;
}
else
{
return true;
}
}
public void turnRandom()
{
// get a random number between 0 and 3...
int turns = Greenfoot.getRandomNumber(10);
// ...an turn left that many times.
for(int i=0; i<turns; i++) {
turnLeft();
}
}
public void turnLeft()
{
switch(direction) {
case EAST :
setDirection(WEST);
break;
case WEST :
setDirection(EAST);
break;
}
}
public void setDirection(int direction)
{
this.direction = direction;
switch(direction) {
case EAST :
setRotation(0);
break;
case WEST :
setRotation(0);
break;
default :
break;
}
}
{
}
}