Jump to content

Java hangman game, file reader not working

Panda Bruv

hello, I am a junior in high school. My teacher wants us to do something for some sort of project. She said I could make a hangman game. I have it pretty much working but I don't know why it is reading as null and just generally why it doesn't work how its supposed to.

it's in a pastebin for your convenience.

 

http://pastebin.com/XPgVFeg7

 

thanks, 

matt

Link to comment
Share on other sites

Link to post
Share on other sites

Not able to try it now but you declare scan as an instance variable then create another scan inside the main method, are you getting them mixed up somewhere?

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

I don't think so. The first scan is for a file reader and the second is for user input from the console (I can't do gui's) and the instance variable scan isn't static so it shouldn't show up in  the main method as usable unless I use an implicit parameter.

Link to comment
Share on other sites

Link to post
Share on other sites

The problem is that you never call makeDashes so mine.dashes is always null.

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

Okay, so I got it working, but I still can't figure out why I don't get the prompt to play again sometimes. And when the word is complete( if the word is "you" and all chars 'y', 'o', and 'y' are entered it doesn't tell you you won. I don't know how to fix this, perhaps because I got 5 or less hours of sleep for the past week..

Link to comment
Share on other sites

Link to post
Share on other sites

Okay, there are a few problems then.

 

The first is following the once variable, it is only set in 2 areas...initially it is set to false at the beginning and then it is set to true when you ask for a new game.  This is fine the first time you complete the game, but the second time you complete the game once will already be true and thus not ask you to play again.

 

So you actually want to set once to false during mine reset....another less critical mistake, which should be corrected because it isn't good to have variables named the same as functions...which you have done with "again"

 

 

The reason your game doesn't tell you that you win can be found by working backwords a bit....as follows

 

you want the "you win!" to show up.  The only way to show up is guess saying you won

The only way guess will say you won is when s == word (ignoring case).

S is input by the user, so entering in "y" then "o" then "u" will only match the single letters against the "you", so it will always be false unless the user types in the word.

I am guessing you should put dashes.equalsIgnoreCase(word) instead of s.equal.....

0b10111010 10101101 11110000 00001101

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×