• Post Reply Bookmark Topic Watch Topic
  • New Topic

Restart it...

 
Sammer Meer
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I made a simple game (the famous snake game).. and ofcourse im moving on a panel using a thread.. I want that when i press on a certain button, the game restarts.. i.e. the current thread to stop and restart. how can i do it? (my class implements Runnable)
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would probably be easiest to let the thread die and start another instance of the same class. I'm not sure how you start a game in the UI, maybe a button? Your button listener could do "new Thread(gameRunner).run()" to start up a new thread every time the user hits "play".
One could make the game thread finish one game and block attempting to synchronize on something already held by the main program, then release it with notify from the main program. Certainly possible, and probably a good education in thread workings, but surely more work!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!