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

2012/11/30

Help with a Game counter.

cpiggott cpiggott

2012/11/30

#
I have created a public variable int in my Acting class called robotsDestroyed, what I want to do is, when I shoot the object I want the count to increase, but i am using the eat() method. Is there anyway to modify this so that i can add robotsDestroyed = robotsDestroyed +1; That way in the Act() method I can do: if(robotsDestroyed ==8){//end game} Im having trouble getting it to count basically. If you can think of any other way to do this, i would appreciate the help!
erdelf erdelf

2012/11/30

#
Where is the int saved?
danpost danpost

2012/12/1

#
There are at least three ways to do this: (1) put the variable 'robotsDestroyed' in the world class (where all robots created can access and change the value); (2) make the variable 'robotsDestroyed' a static int in the Acting class (where all robots share the one field); or, (3) create a counter (actor) object to hold the value of 'robotsDestroyed' (where all robots created can access and change the value and the value can be displayed).
-nic- -nic-

2012/12/1

#
btw you could use robotsDestroyed += 1; or robotsDestroyed++; instead of robotsDestroyed = robotsDestroyed +1;
You need to login to post a reply.