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

2013/10/29

How can i make 2 counters work?

Aermus Aermus

2013/10/29

#
For our game GTA i have 2 counters.. one for the thief points and one for the police point. In my subclass city from world i put the following add objects..
public Stad()
    {       
        super(1600, 875, 1);   
        Greenfoot.setSpeed(50);
        PlaatsSpelers();
        PlaatsObstakels();
        PlaatsBurgerautos(); 
        prepare();
        addObject (new Counter(score),86, 48);
        addObject (new Counter2(score) ,1473, 50);
        addObject (new Garage(),1336, 373);
        addObject (new Garage2(),272, 800);
    }



and for the points

 /**
     * De punten telling
     *
     */
    public void arrest()
    { removeObjects (getObjects(Counter2.class));
      score += 100;
      addObject(new Counter2(score),1473, 50);
    }
     public void gejat()
    { removeObjects (getObjects(Counter.class));
      score += 15;
      addObject(new Counter(score), 86, 48);
    }
I see the points on my 1 counter calculated by 15.. but i dont see my points calculated in counter2.. I get the error message "Constructo Counter2 in class Counter2 cannot be applied to given types;" Why is this? because it works perftectly for the first counter (counter.class) please help me..
danpost danpost

2013/10/29

#
The main thing that you need to do if you are going to have more than one Counter object is to keep references to them:
// instance fields
Counter thiefCounter, policeCounter;
// in the constructor
thiefCounter = new Counter(0);
addObject(thiefCounter, 86, 48);
policeCounter = new Counter(0);
addObject(policeCounter,1473, 50);
Now, you can refer to either one by its name.
You need to login to post a reply.