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

2012/2/12

hello everyone question on declaring this here

1
2
3
danpost danpost

2012/2/12

#
You could change the text for the button to read " Click here to \n TRY AGAIN ".
danpost danpost

2012/2/12

#
No, you do not have to replace your scoreboard, unless you want to.
programmer22 programmer22

2012/2/12

#
oh so i would put the button beside try again so it would be like this GAME OVER Score:100 (button)->click here TRY AGAIN like that right?
danpost danpost

2012/2/12

#
You can make it almost anyway feasable. Whatever you like. It might be nice to have a little spacer between the two, and have the words 'Click here to' above TRY AGAIN. (just a suggestion)
programmer22 programmer22

2012/2/12

#
how can i make the click here part appear at the end thats what im getting at
danpost danpost

2012/2/12

#
In your button constructor, right now you have just the words 'Try again'. Just change the string to " Click here to \n TRY AGAIN ". It will be a part of the button.
programmer22 programmer22

2012/2/12

#
-.- j was goanna make the button say click here to then put it beside the try again but i think ima leave it at try again ok... Just answer this one question how do i make it apear at the end like if i wanted it to apear after the crab is eaten how do i do that?
danpost danpost

2012/2/12

#
Look at (2b) on my last post on page 1 of this discussion.
programmer22 programmer22

2012/2/12

#
 public void getEaten()
    {
        //  Code for sound (if you want)
        //  Code to remove crab (if you want)
        CrabWorld gw = (CrabWorld) getWorld();
        ScoreBoard scoreboard = new ScoreBoard(counter.getValue());   
        gw.addObject(scoreboard, 273, 302);
        gw.removeObject(this);  
        return;
    }
how can i get it to do that isnt their some silmplier way look how i did this one because im pretty sure when the crab gets eatten it adds the score board can i put like Button button = new Button then gw.addObject(Button, 260,290); ?
danpost danpost

2012/2/12

#
The code in your CrabWorld act() method would be something like:
if (getObjects(Crab.class) == null)
{
    if (getObjects(Scoreboard.class) == null) addObject(new Scoreboard(), xSb, ySb); // replace xSb and ySb
    if (getObjects(Button.class) == null) addObject(new Button(), xBt, yBt); // replace xBt and yBt
    return;
}
danpost danpost

2012/2/12

#
public void getEaten()
{
    CrabWorld gw = (CrabWorld) getWorld();
    gw.removeObject(this);
}
This is all you need here.
programmer22 programmer22

2012/2/12

#
   public void act()
{ 
          addWorms(20);
          if (getObjects(Crab.class) == null)
          {
              if (getObjects(Button.class) == null) addObject(new Button(), getWidth()/2, getHeight()/2);  
              return;
          }
             
          
          
}  
this is my crab world act
programmer22 programmer22

2012/2/12

#
 public void getEaten()
    {
        //  Code for sound (if you want)
        //  Code to remove crab (if you want)
        
        CrabWorld gw = (CrabWorld) getWorld();
        ScoreBoard scoreboard = new ScoreBoard(counter.getValue());   
        gw.addObject(scoreboard, 273, 302);
        gw.removeObject(this);  
        return;
    }
this is my crab eaten
programmer22 programmer22

2012/2/12

#
now that you can see both of those can you tell me exactly where to put things
danpost danpost

2012/2/12

#
Use the code I provided immediately above for the world class act method and the crab class getEaten method. Remove the line addWorms(20); from the act method of the world (unless you want 20 worms added each and every act cycle; you would have zillions in no time; back to that in a minute). Add a method in the world class, called 'prepare()'
public void prepare()
{
    removeObjects(getObjects(null));
    addObject(new Crab(), xC, yC);
    addObject(new Lobster(), xL, yL);
    addWorms(20);
    counter = new Counter();
    addObject(counter, xK, yK);
    //  if I missed anything, add them also
}
Now back to the addWorms (that you had in act(). If you want to add more worms, when the worm supply drops, then add this to the act() method of the CrabWorld class
if (getObjects(Worm.class).size() < 5) addWorms(20);
There are more replies on the next page.
1
2
3