This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Help for Timers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help for Timers" Watch "Help for Timers" New topic
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: 18541
    
    8

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: 18541
    
    8

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

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help for Timers
 
Similar Threads
Ending a Timer within itself
Help with If / Else If / Else
regarding jdbc
regarding JTable
Problem when running with browser, fine when run with "java colorswitch.ColorSwitch"