• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help for Timers

 
Jean Fontaine
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 20990
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 20990
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic