Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS 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:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Creating menu for a Java snake game

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am a beginner to Java programming and I am trying to create a menu for a simple Snake game which will contain three buttons(New Game, Difficulty, Quit). I created a class for the menu and a class for the mouse input. I also used an enum to store the states of the game (MAIN_MENU, DIFFICULTY_MENU and GAME) and a variable called state which stores the current state.
The main issue is that although the state of the game changes when I press the New Game button,  the game itself doesn't start. I have tried countless ways to make it work ranging from adding game state checks inside the methods that are involed in rendering the gameplay to actually calling those methods when the button is pressed but none of them worked. I also tried adding JButtons to create the menu and I managed to make them dissappear when the New Game was pressed but the game wouldn't start either. Any help would be greatly appreciated. Here's some of the code(if it's too much please let me know and i will post only specific parts of it):

 
Oddo Razvan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there anybody who could help me find a solution to this problem? I know that it might not be something very complicated but I don't think that I can figure it out on my own at the moment.  
 
Oddo Razvan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would like to ask the moderators to move my post to another area if they consider that there are more chances of getting a reply and if that is not against the posting rules of the forum. Thank you!
 
Marshal
Posts: 74085
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's try our GUIs forum.

And welcome to the Ranch
 
Oddo Razvan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, is there anybody who could help me figure out how to start the game when the button is pressed? So far I have only been able to make the "Quit" button work.
L.E.
I run the code a couple more times and I discovered that if I minimize the window after pressing "New Game" and then reopen it the game refreshes and can be played afterwards. Any ideas on why it works this way and how I can "refresh" the JFrame immediately after pressing the menu button?
reply
    Bookmark Topic Watch Topic
  • New Topic