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

2021/1/17

One instruction class?

BlueHand BlueHand

2021/1/17

#
I have a game with one rocket, 3 asteroids, one planet, and two counters. One counter records the collisions between the rocket and asteroids. How do I keep this counter separate from the other with only one counter and instructions class?
danpost danpost

2021/1/17

#
BlueHand wrote...
I have a game with one rocket, 3 asteroids, one planet, and two counters. One counter records the collisions between the rocket and asteroids. How do I keep this counter separate from the other with only one counter and instructions class?
Give them names you can refer them as by adding fields to your MyWorld class:
public class MyWorld extends World
{
    Counter scoreCounter = new Counter();
    Counter collisionCounter = new Counter();
    ...
    
    public MyWorld()
    {
        super(600, 400, 1);
        addObject(scoreCounter, 100, 25);
        addObjject(collisionCounter, 100, 50);
        ...
    }
    
    ...

    public Counter getCollisionCounter()
    {
        return collisionCounter;
    }
    
    public Counter getScoreCounter()
    {
        return scoreCounter;
    }
}
BlueHand BlueHand

2021/1/17

#
Sorry, I meant: how do I add different labels to them? There's only one counter class so I'm not sure how to do that.
danpost danpost

2021/1/17

#
BlueHand wrote...
Sorry, I meant: how do I add different labels to them? There's only one counter class so I'm not sure how to do that.
Add a String parameter to Counter class constructor.
You need to login to post a reply.