File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threads

 
Duran Harris
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi...so I'm busy messing around with threads and I decided to make a small game.It's not working well so far though.My cat thread isn't running.Also I'm not sure that I've used wait() and notify() correctly.

The idea is that I create a Mouse and cat class.Then I create a single Cat and multiple Mouse threads.When a mouse is created it gets put in a static hash map.I use math.random() in the Cat thread to create a random chance of the cat catching(and killing) a mouse.Not quite sure how I should go about this..Oh yes..also the idea is that there should only be one mouse running around at a time.The game is meant to end either when cheese=0 OR when the mice have all been killed...
I just can't seem to get the Cat thread to output anything....any suggestions??



[ December 29, 2008: Message edited by: Duran Harris ]
 
Anthony Accioly
Greenhorn
Posts: 16
IntelliJ IDE Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

Your program had several issues...
1) The program was freezing because everyone was waiting at the cat monitor
2) You forgot to interrupt the mouse thread once you killed it
3) The static HashMap approach wasen't really working

Here is a version of the program that seens to be working allright for me:



ps: There is a game development forum here at the saloon .

Cheers

[ December 29, 2008: Message edited by: Anthony Accioly ]
[ December 29, 2008: Message edited by: Anthony Accioly ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic