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

2019/6/2

Error when changing World

1
2
3
gacha321 gacha321

2019/6/3

#
This is my GoldWorld's code
        private Counter theCounter;
        Petani p;
 
    /**
     * Constructor for objects of class GoldWorld.
     * 
     */
    public GoldWorld()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(700, 600, 1); 
        drawMap();
        theCounter = new Counter();
        addObject(theCounter, 50, 20);
        prepare();
        if(p == null)
            p = new Petani();
            addObject(p, 70, 400);
    }
    
    public Counter getCounter(){
        return theCounter;
    }
    
gacha321 gacha321

2019/6/3

#
OMG I fix the problemm!!!
public class Counter extends Actor
{
    private int count = 0;
    
    public Counter(){
        setImage(new GreenfootImage("Gold : 100", 20, Color.WHITE, Color.BLACK));  
    }
    /**
     * Act - do whatever the Counter wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void walkCount (int amount) 
    {
        // Add your action code here.
        count += amount;
        setImage(new GreenfootImage("Gold : " + (100+count),20, Color.WHITE, Color.BLACK)); 
    }    
    
    public int getValue(){
        return count;
    }
}
I'm so happyyy thank you so much for your helpppp you're really really kindd, I hope I can meet you someday :)
Oof
You need to login to post a reply.
1
2
3