I'm working on a Computing project that involves creating a GUI-based Hangman game. I've got most of it done, but it seems that I made a couple of logical errors on the way, and I can't seem to locate them. I was hoping that I could get some help as to finding these errors, using your impressive java skills.
Here is the code of all the classes: I'm using a BlueJ IDE
MainFrame class (main GUI):
UseMainFrame class(basically creates an instance of the MainFrame class and sets its properties)
MenuGUI class (the menu GUI that basically offers a choice of playing or exiting)
UseMenuGUI class (basically creates an instance of MenuGUI and sets its properties)
and the GameEngine class(contains many methods that will be used throughout the game)
It basically works by running UseMenuGUI and the rest follows.
Ulf Dittmer wrote:What does or does not work according to your expectations? In other words, what does it do now, and how does that deviate from what you expect it to do?
--> The area of the word to be guessed is not being updated every time a button is pressed and a guess is right
--> The area of the wrong letters is not being updated every time a button is pressed and the guess is wrong
-->I got mixed up on the for loops, and it seems to be outputting the message more than once and updating the hangman model more than once per button click
--> the hangman model resets per button click
That's not object-oriented programming. You should be adding information to the buttons, then using the button to supply the information. None of this if e.getSource() == aButton . . . else if e.getSource() == bButton . . .
And you should have an array of HangManPart objects; for every wrong letter you move one along the array, and if you get to the size of the array (ie one place beyond its end), the game is lost.
Oh wow, I really messed it up...how can I implement such procedures? Do I need to pass the char letter to the buttons as parameters?
Regarding the array, say I'm using 6 guesses, should i declare having 6 spaces and say that if it reaches arr.length()-1, the game is lost?
Just making sure I'm taking it in the right approach. How would I attach the array to the GUI? Should I do it in the same way, using a StringBuffer?