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

2012/1/1

Scoreboard

1
2
danpost danpost

2012/1/3

#
The if(seeLobster()) part would be in the act method of your crab class. The public boolean seeLobster() part would also be in your crab class as a seperate method (like right after the act(){ } method. I used the curly brackets to indicate the it would go after the matching bracket to the one immediately after public void act()
programmer22 programmer22

2012/1/4

#
well i added the boolean lobster part but the if(seeLobster()) i dont have becaue when i put it in the act method it messes everything up so heres what i have so far : import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.util.List; // needed to create a list and use its methods public class Crab extends Actor { /** * Act - do whatever the Crab wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { moveAndTurn(); eat(); } public boolean seeLobster() { return (getOneIntersectingObject(Lobster.class) != null); } public void moveAndTurn() { move(4); if (Greenfoot.isKeyDown("right")) { turn(-10); } if (Greenfoot.isKeyDown("left")) { turn (10); } } public void eat() { Actor worm; worm = getOneObjectAtOffset (0, 0, Worm.class); if (worm != null) { World world; world = getWorld(); world. removeObject(worm); List<Counter> counters = world.getObjects (Counter.class); Counter counter = counters.get (0); counter.add(1); Greenfoot.playSound("eating.wav"); } } } ALSO do i still have to enter that part about the game over if i have the see lobster part or do i need both and if i need it where would i put that?
danpost danpost

2012/1/4

#
What I was meaning was to add within act:
if (seeLobster())
{
    GameWorld gw = (GameWorld) getWorld();
    Scoreboard scoreboard = new Scoreboard();
    gw.addObject(scoreboard, gw.getWidth() / 2, gw.getHeight() / 2);
    Greenfoot.stop();
}
Or, if you wanted to, you could do it this way: In act:
if (seeLobster()) getEaten();
and below act, create another method
public void getEaten()
{
    //  Code for sound (if you want)
    //  Code to remove crab (if you want)
    GameWorld gw = (GameWorld) getWorld();
    Scoreboard scoreboard = new Scoreboard();
    gw.addObject(scoreboard, xLocation, yLocation);
    Greenfoot.stop();
}
programmer22 programmer22

2012/1/12

#
dude tytyty finnaly it works but heres a question how can i make it get the score from the counter?
danpost danpost

2012/1/12

#
You need to be a bit more specific. Where is your counter? How is it declared? Are you trying to get the score TO the scoreboard? Usually, the score is kept within the scoreboard class, and a reference to the scoreboard is kept in the world class. That way, methods such as getScore(), bumpCounter(int), and other counter related methods can be placed there and the act method will update the scoreboard image (if the score is in view the whole game-set).
You need to login to post a reply.
1
2