aspose file tools*
The moose likes Beginning Java and the fly likes Finishing touches to a Hangman game: kindly asking for ideas to help debug my logical errors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Finishing touches to a Hangman game: kindly asking for ideas to help debug my logical errors" Watch "Finishing touches to a Hangman game: kindly asking for ideas to help debug my logical errors" New topic
Author

Finishing touches to a Hangman game: kindly asking for ideas to help debug my logical errors

Claude Frendo
Greenhorn

Joined: Mar 03, 2011
Posts: 3
Hi community,

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.

Thanks in advance,

Claude Frendo
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42906
    
  69
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?

There's at least one empty catch block, which is generally not a good idea. At least write something to the console so you'll know a problem occurred.

By the way, you can make the code a lot shorter if you keep the JButtons in an array, instead of in separate variables.
Claude Frendo
Greenhorn

Joined: Mar 03, 2011
Posts: 3
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

Those are the things I've noticed so far.

Edit: typo


Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40027
    
  28
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.
Claude Frendo
Greenhorn

Joined: Mar 03, 2011
Posts: 3
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Finishing touches to a Hangman game: kindly asking for ideas to help debug my logical errors