there may be a few mistakes that you could point out where they are in the code because im battling to make the life counter.i would be very grateful for any such advice that may help ;-)
import greenfoot.*;
/**
* all history of bobsworld.
*
* @author (A.T.P)
* @version (2.4.2)
*/
public class BobWorld extends World
{
/**
* Constructor for objects of class BobWorld.
*
*/
public BobWorld()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(700, 500, 1);
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()
{
Bob bob = new Bob();
addObject(bob,29,35);
Score score = new Score();
addObject(score,45,15);
bob.setLocation(94, 251);
bob.setLocation(106, 232);
bob.setLocation(67, 185);
bob.setLocation(72, 162);
bob.setLocation(76, 177);
bob.setLocation(75, 177);
bob.setLocation(75, 175);
bob.setLocation(85, 204);
BobFood bobfood = new BobFood();
addObject(bobfood, 468, 205);
bob.setLocation(86, 204);
bob.setLocation(100, 191);
bob.setLocation(98, 191);
bob.setLocation(134, 168);
bob.setLocation(95, 206);
bobfood.setLocation(451, 210);
BobEater bobeater = new BobEater();
addObject(bobeater, 81, 140);
BobEater bobeater2 = new BobEater();
addObject(bobeater2, 74, 334);
bob.setLocation(201, 235);
bobfood.setLocation(451, 181);
bob.setLocation(202, 235);
bob.setLocation(203, 235);
bob.setLocation(207, 216);
bobeater.setLocation(84, 142);
bobeater.setLocation(85, 150);
bobeater2.setLocation(76, 315);
BobFood bobfood2 = new BobFood();
addObject(bobfood2, 465, 46);
BobFood bobfood3 = new BobFood();
addObject(bobfood3, 468, 314);
BobFood bobfood4 = new BobFood();
addObject(bobfood4, 286, 95);
BobFood bobfood5 = new BobFood();
addObject(bobfood5, 306, 289);
BobFood bobfood6 = new BobFood();
addObject(bobfood6, 326, 201);
BobFood bobfood7 = new BobFood();
addObject(bobfood7, 552, 103);
BobFood bobfood8 = new BobFood();
addObject(bobfood8, 541, 263);
BobFood bobfood9 = new BobFood();
addObject(bobfood9, 139, 34);
BobFood bobfood10 = new BobFood();
addObject(bobfood10, 181, 340);
BobFood bobfood11 = new BobFood();
addObject(bobfood11, 69, 213);
BobFood bobfood12 = new BobFood();
addObject(bobfood12, 182, 124);
Instructions instructions = new Instructions();
addObject(instructions, 272, 395);
instructions.setLocation(282, 389);
bobeater2.setLocation(76, 304);
BobEater bobeater3 = new BobEater();
addObject(bobeater3, 73, 312);
BobEater bobeater4 = new BobEater();
addObject(bobeater4, 389, 100);
BobEater bobeater5 = new BobEater();
addObject(bobeater5, 545, 202);
bobeater3.setLocation(76, 312);
bobeater3.setLocation(346, 329);
bobeater3.setLocation(344, 329);
score.setLocation(44, 15);
score.setLocation(27, 18);
score.setLocation(27, 24);
removeObject(bobfood6);
removeObject(bobfood);
removeObject(bobfood9);
bobfood3.setLocation(469, 313);
removeObject(bobfood3);
bobfood4.setLocation(286, 98);
removeObject(bobfood4);
bobfood12.setLocation(198, 87);
bobfood5.setLocation(306, 260);
bobfood2.setLocation(396, 179);
bobfood2.setLocation(405, 167);
bobfood8.setLocation(491, 312);
bobfood8.setLocation(491, 310);
bobfood7.setLocation(543, 57);
bobfood10.setLocation(154, 340);
bobfood11.setLocation(56, 214);
bobfood11.setLocation(56, 215);
bobfood5.setLocation(307, 257);
bobfood2.setLocation(434, 132);
bobfood2.setLocation(416, 116);
bobeater4.setLocation(402, 115);
bobeater4.setLocation(378, 98);
bobfood2.setLocation(421, 136);
bobfood2.setLocation(421, 135);
instructions.setLocation(361, 489);
bobfood8.setLocation(573, 404);
bobfood5.setLocation(326, 395);
bobfood10.setLocation(154, 340);
bobfood10.setLocation(154, 340);
bobfood10.setLocation(154, 340);
bobfood10.setLocation(154, 340);
bobfood10.setLocation(154, 340);
bobfood10.setLocation(154, 340);
bobfood10.setLocation(154, 340);
bobfood10.setLocation(154, 340);
bobfood10.setLocation(154, 340);
bobfood10.setLocation(154, 340);
bobfood10.setLocation(154, 340);
bobfood10.setLocation(154, 340);
bobfood10.setLocation(154, 340);
bobfood10.setLocation(154, 340);
bobfood10.setLocation(50, 426);
bobfood11.setLocation(67, 217);
bobfood2.setLocation(378, 245);
bobeater3.setLocation(378, 363);
bobeater2.setLocation(86, 306);
bobeater.setLocation(154, 80);
bobeater3.setLocation(381, 411);
bobeater3.setLocation(384, 430);
bobeater2.setLocation(110, 341);
score.setLocation(52, 23);
score.setLocation(51, 22);
score.setLocation(50, 16);
}
}
public Bob(Counter counter)
public Bob()
import greenfoot.*;
/**
* a bob in the game will eat the Bobfood on your command.
*
* @author (A.T.P)
* @version (2.4.2)
*/
public class Bob extends Beings
{
private int points = 0;
private Score Score;
public Bob(Score pointScore)
{
Score = pointScore;
}
/**
* Act - do whatever the Bob wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move(3);
checkKeys();
tryToEat();
}
/**
* once reached world edge you must turn away
*/
public void turnAtWorldEdge()
{ if (atWorldEdge())
{
turn(4);
}
}
/**
* check whether the keys are being pressed or not if they are follow the command
*/
public void checkKeys()
{
if( Greenfoot.isKeyDown("left"))
{
turn(-6);
}
if( Greenfoot.isKeyDown("right"))
{
turn(6);
}
if( Greenfoot.isKeyDown("up"))
{
move(5);
}
if( Greenfoot.isKeyDown("down"))
{
move(-5);
}
}
/**
* Check whether we can see Bobfood.if we can,eat it.
*/
void tryToEat()
{
if(canSee(BobFood.class))
{
eat(BobFood.class);
Greenfoot.playSound("slurp.wav");
Score.add(5);
createNewBobFood();
}
}
/**
* add new BobFood into the world at a random location
*/
private void createNewBobFood()
{
BobFood newBobFood;
newBobFood=new BobFood();
World world;
world=getWorld();
int worldWidth = world.getWidth();
int worldHeight = world.getHeight();
int x = Greenfoot.getRandomNumber(worldWidth);
int y = Greenfoot.getRandomNumber(worldHeight);
world.addObject(newBobFood,x,y);
}
/**
* adds the method gameover when that happens a sound is produced
*/
public void gameOver()
{
Greenfoot.playSound("game-over.wav");
Greenfoot.stop();
}
}
there is no bob(counter counter)public Bob(Score score)
public Bob()
Bob bob = new Bob()
Bob bob = new Bob(score)
Score score;