How can i get my game to stop when the class has been eaten or the player has completed the game???
(This is prbably easy to you guys...)
if (getObjects(ClassName.class).isEmpty())
{
Greenfoot.stop();
return;
}import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class snowman here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Wombat extends Animal
{
public void act()
{
move();
checkKeypress();
if (canSee(Leaf.class))
{
eat(Leaf.class);
}
if (canSee(Ant.class))
{
eat(Ant.class);
}
}
public void eat()
{
Actor Ant;
Ant = getOneObjectAtOffset(0, 0, Ant.class);
if (Ant != null)
{
World world;
world = getWorld();
world.removeObject(Ant);
Greenfoot.playSound("slurp.wav");
}
{
Greenfoot.stop();
return;
}
}
public void lookForAnt()
{
if (canSee(Ant.class))
{
eat(Ant.class);
Greenfoot.playSound("slurp.wav");
}
if (canSee(Leaf.class))
{
eat(Leaf.class);
Greenfoot.playSound("slurp.wav");
}
}
public void checkKeypress()
{
if(Greenfoot.isKeyDown("left"))
{
turn(-4);
}
if(Greenfoot.isKeyDown("right"))
{
turn(4);
}
}
}//Do something like this...
public GameOver(int score) {
Greenfoot.stop();
GreenfootImage text = new GreenfootImage("Game Over\nCoins: " + score, 40, Color.RED, new Color(0, 0, 0, 0));
GreenfootImage image = new GreenfootImage(text.getWidth() + 20, text.getHeight() + 20);
image.setColor(new Color(255, 255, 255, 128));
image.fill();
image.drawImage(text, 10, 10);
setImage(image);
Home home = new Home();
Greenfoot.setWorld(home);
}if (getObjects(Ant.class).isEmpty() && getObjects(Leaf.class).isEmpty())
//my wombat class
import greenfoot.*;
public class Wombat extends Animal
{
public void act()
{
move();
checkKeypress();
if (canSee(Leaf.class))
{
eat(Leaf.class);
}
if (canSee(Ant.class))
{
eat(Ant.class);
}
}
public void GameOver(int score)
{
Greenfoot.stop();
GreenfootImage text = new GreenfootImage("Game Over\nCoins: " + score, 40, Color.RED, new Color(0, 0, 0, 0));
GreenfootImage image = new GreenfootImage(text.getWidth() + 20, text.getHeight() + 20);
image.setColor(new Color(255, 255, 255, 128));
image.fill();
image.drawImage(text, 10, 10);
setImage(image);
Home home = new Home();
Greenfoot.setWorld(home);
}
public void eat()
{
Actor Ant;
Ant = getOneObjectAtOffset(0, 0, Ant.class);
if (Ant != null)
{
World world;
world = getWorld();
world.removeObject(Ant);
Greenfoot.playSound("slurp.wav");
}
{
Greenfoot.stop();
return;
}
}
public void lookForAnt()
{
if (canSee(Ant.class))
{
eat(Ant.class);
Greenfoot.playSound("slurp.wav");
}
if (canSee(Leaf.class))
{
eat(Leaf.class);
Greenfoot.playSound("slurp.wav");
}
}
public void checkKeypress()
{
if(Greenfoot.isKeyDown("left"))
{
turn(-4);
}
if(Greenfoot.isKeyDown("right"))
{
turn(4);
}
}
}import java.awt.Color;
public void lookForLeaf()
{
if (canSee(Leaf.class))
{
eat(Leaf.class);
leavesEaten = leavesEaten + 1;
}
}