| Author |
Help for Timers
|
Jean Fontaine
Greenhorn
Joined: Apr 12, 2011
Posts: 12
|
|
Hi everybody !
I need some help with this little program I'm writing :
It's in three classes, two objects and a jFrame. Its a fight between an ally (Dinoz) and an opponent (monster or goupignon);
We get their stats using get and set methods. Everything seems good.Then I make a timer :
What I want is that using the boolean DinozTurn the timer decides wether making the monster or the dinoz attack (dinozturn = false makes monster attack and dinozturn = true makes dinoz attack)
But what happens is that only the monster's HP goes down, 4 by 4 forever. Only the monster.
My second problem is that if Itry to put a while that says : while (dinozHP >= 0 && monsterHP >= 0) {do the above code}, then the monster's HP goes straight to -4
... Why ?
Thank you for your help !
Oracion
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
Jean Fontaine wrote:But what happens is that only the monster's HP goes down, 4 by 4 forever. Only the monster.
Do you say that based on having stepped through the code with a debugger, or based on what you see in your GUI? Remember that no matter how many times you change the GUI in that code, you won't see the result until you return from the actionPerformed method.
|
 |
Jean Fontaine
Greenhorn
Joined: Apr 12, 2011
Posts: 12
|
|
Thanks for your reply but my mom helped me figure out what was wrong !
I was basing on what I saw, and after a few expermiments I found out that the first part of code wasn't happening at all : DinozHP wasnt ever going down !
Its because of this part of the code :
and
: I just neede to change the = of assignation to the == of comparison !
!
Thanks anyways !
Oracion
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
Which is why you shouldn't write code like that in the first place. Just use boolean values as themselves, you don't have to compare them to true or false. So for example not
but
And not
but
|
 |
 |
|
|
subject: Help for Timers
|
|
|