Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Threads

 
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 22
Scala IntelliJ IDE Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Don't touch me. And dont' touch this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic