Hey everyone. I'm sure everybody in here is getting sick and tired of me and my Hangman program. It's almost finished to a point that I can start using graphics.
This time, I'm doing things right!
The code in question is posted at
http://pastebin.com/648264 The entire package so far is available for download (in case you want to compile it yourself to see what I'm talking about) at
www.geocities.com/kitaarmykruis/Hangman.zip OK, so here we go:
The program is a normal (so far!) IO-based Hangman program. We all know how that works. If a word is "hangman", the computer gives back "-------" and we have to guess the letters in the word. If we choose "a", the following is returned: "-a---a-" and if we choose "h": "ha---a-" until we get the word.
OK - so my program works like this: I've got three text files, 1.txt, 2.txt and 3.txt with different categories of words. The user selects a category and the word jumps up. (Or, well ----------!). If the user gets the word right, his/her score is added to, and this score is saved in a textfile, hangmanHighScore.txt, given that the user's score is higher than the previous high score.
If you check out the
http://pastebin.com/648264 address quickly, look at line 17. It's basically the variable asking for the user's name and it is imported from HangmanFileReader, another .java file that I wrote (available at
http://pastebin.com/648296 - the line that asks for the name is 32).
OK, so what now? Well, it reads the name, fine. But then, when you finish the word correctly, it asks you whether or not you want to play again. This poses two problems:
a) It doesn't write the new high score to the text file (the text file currently contains only one thing, the number <0>.
b) If you elect to play again, it again asks for your name. This isn't what I want. I want it to use the same name and continue with the score. It doesn't. It starts over completely.
What I've tried to do, as you can see in line 17 of the first page - is to read the name only once. The method nameInput reads the name from HangmanFileReader and returns playerName. playerName is then supposed to be taken from the method, but it says that the IOException needs to be thrown first.
Right: so I want your help with two things:
a) keeping track of the user's score and writing the high score to the text file.
b) using the player's name - asking for it only once.
Any help? Guys if I'm talking so that you can't understand, feel free to talk to me. I'll be in #Java on QuakeNet under the name georgestobbart for the next hour or so, so feel free to pop in. And again, if you want to compile the program yourself:
www.geocities.com/kitaarmykruis/Hangman.zip you'll need to open Hangman, HangmanFileReader and HangmanManager (which acts like a driver).
Thanks!
Klaas