Link to home
Start Free TrialLog in
Avatar of ildave1
ildave1

asked on

Timers

Hello!

Well, Ive been working up on something a little, just trying to get fimilier with a lot of different things that Java can do and I've run across something that I'd like to get some feedback on.

I've found a few sources such as:
http://java.sun.com/docs/books/tutorial/essential/threads/timer.html
http://java.sun.com/docs/books/tutorial/uiswing/misc/timer.html

and I have a few books.

Maybe its the thinking that Im getting confused the most about.  What I would like to do is to get an image(bad guy) to pop onto my 10x10 playing board and chase the player around.  I to set it as a timer so that every 30 seconds a bad guy comes out and every two seconds or so he'll move closer to the player.  However, if I do in fact make the bad guy chase the player around, isn't that leaning more on the AI side of the house?

10x10 board
|  |  |  |  |  |  |  |  |  |  |
|  |  |  |  |  |  |  |  |  |  |  x = the player
|  |  |  |  |  |  |  |  |  |B|  b = bad guy
|  |  |  |  |  |  |  |  |  |  |
|X|  |  |  |  |  |  |  |  |  |    in more depth this is what im looking at:  http://pastebin.com/281910

Any suggestions would be helpfull.  Expecially if you've found a great timer tutorial or an idea perhaps.

Regards,
Dave
Avatar of Mick Barry
Mick Barry
Flag of Australia image

A Swing Timer would seem the way to go, what problems are you having implement it?
You just need two timers really. One fixed to a BadGuyFactory, the role of which would be to produce bad guys every 30 seconds and a timer on the BadGuy, that decreased the delta between it and the good guy every 2 seconds
Avatar of ildave1
ildave1

ASKER

Objects:
  I think its how to combine both tasks which is getting to me.  Using a timer to have some image come up onto the board to start chasing the good guy.

CEHJ:
  BadGuyFactory?  I've seen a lot of this 'factory' stuff, expecially when it comes to U.I. or pulling system icons. Is there some place that references this?

>> that decreased the delta between it and the good guy every 2 seconds
  0_0.... So its no AI, its just math? hah!  Sounds a bit odd to implement though .
You have two actions, one that would create a new bad guy and add them to the board, and another that would move an existing bad guy.
When you create a new bad guy, you would also start the timer that would up update their position every n seconds.
SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ildave1

ASKER

I have a great idea for that!

Thanks gnoon!

Regards,
Dave
Thanks :-)