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
programmer22 programmer22

2012/2/12

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
/**
 * Write a description of class Button here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Button extends Actor
{
    public Button()
    {
        setImage(new GreenfootImage(" Try again ", 30, Color.BLACK, Color.RED));
    }

    public void act()
    {
        if(Greenfoot.mouseClicked(this))
        {
            CrabWorld gw = (CrabWorld) getWorld();
            gw.removeObject(this);
            gw.removeObject(ScoreBoard);
            gw.removeObject(Counter);
            gw.removeObject(Lobster);
            gw.prepare();
            

        }   
    }}         
it says it cant find the variable for scoreboard counter and lobster and my goal is to remove these items because it just leaves them their and when you hit reset it just resets it with eveything their still but with the begining characters aswell anyways heres the code
danpost danpost

2012/2/12

#
Im back! You do not have to remove anything . Just call the prepare() method here. Back in the world class, in the prepare method, insert a new first line to the method
removeObjects(getObjects(null));
and make sure that a line is in the prepare method to add the crab also.
programmer22 programmer22

2012/2/12

#
aw sick man it worked but ok get this at the end i have a score board right is their anyway i can make the Try again we made stick on the board instead of the string i put their saying try again or would i just have to make the new try again apear in that spot at the end?
programmer22 programmer22

2012/2/12

#
also is their anyway to increase the text size?
danpost danpost

2012/2/12

#
The button can be anywhere you want it to be. Just change the location to where you want it to be within the addObject statement that puts the button into the world. If you already have the words 'try again' on the scoreboard, you could place the button over the words.
danpost danpost

2012/2/12

#
If your reference is to the 'Try again' button, yeah. In the constructor, change the font size (30) to a larger number.
programmer22 programmer22

2012/2/12

#
lol yeah thats what i just figured out messing with it and ive been trying to get it to the perfect size to cover the words how could i make that apear do the same thing as the scoreboard on how i make that apear?
programmer22 programmer22

2012/2/12

#
ok so how can i make my "restart try again " (not the one on the score board one you made) appear at the end when the crab gets eaten ?
danpost danpost

2012/2/12

#
A simple score class would be something like
import greenfoot.*;
import java.awt.Color;

public class Scoreboard extends Actor
{
    score = 0;

    public Scoreboard()
    {
	updateImage();
    }

    private void updateImage()
    {
        setImage(new GreenfootImage("Score: " + score, 14, Color.black, new Color(0, 0, 0, 0)));
    }

    public void add(int change)
    {
	score += change;
	updateImage();
    }

    public int getScore()
    {
	return score;
    }
}
programmer22 programmer22

2012/2/12

#
no no no i meant like how can i make the one score board appear at the end the one weve been working on
programmer22 programmer22

2012/2/12

#
umm maybe this will help explain like crab gets eaten this appears at this xlocation,ylocation
danpost danpost

2012/2/12

#
Sorry, ignore the above. I see you already have a counter for while the game is in progress. I now see that the scoreboard is for the end (more of a game over scoreboard). A scoreboard class for such would be something like
import greenfoot.*;
import java.awt.Color;

public class Scoreboard extends Actor
{
    public Scoreboard()
    {
        setImage(new GreenfootImage (" GAME \n OVER \n \n End Score: " + score + " ", 24, Color.black, Color.cyan));
    }
}
programmer22 programmer22

2012/2/12

#
ok so what does that do? i dont understand i already have a end scoreboard i just want to put the new try again over the game over try again how can i make that appear then at the end?
danpost danpost

2012/2/12

#
1) In your getEaten() method in the crab class, you remove the crab. 2) In your act() method in the crabworld class, you check to see if a crab is in the world a) if so, do nothing special b) if not, add the scoreboard and add the button 3) When button is clicked, the prepare() method in the world is called and all the objects are removed and replaced.
programmer22 programmer22

2012/2/12

#
so i should replace my score board with that?
There are more replies on the next page.
1
2
3