Computer Science Canada Help With Java Hangman!! |
Author: | robs247 [ Sun May 19, 2013 5:40 pm ] | ||||
Post subject: | Help With Java Hangman!! | ||||
Hi I'm new here and was wondering if anybody knows how to create a java hangman game for HSA consoles. It's a project for school and the teacher hasn't taught us how to read the strings and check if a letter guessed is in the word or not. I need help with that. Here's my program so far. Here's the project outline: Your CPT involves designing a game of hangman. Requirements: 1. Predefined categories should be set up using multiple data files. Populate the data files with predefined lists of words. 2. Allow the user to choose from the list of predefined categories. 3. Randomly select a word from the predefined category list. 4. The progress of the game should be displayed to the user in a graphical format. Use the draw commands. 5. The user should be informed when they win or lose a game. 6. Allow the user to try a new game. Bonus: Keep a list of high scores. Evaluation: Your program will be evaluated based on the following criteria: Functionality. Does it work? Attractive output. Internal documentation (comments, variable names). Effective use of programming structures. Efficiency. Error traps. Try again option. Creativity. Effort. My program so far:
there are eight words in each text file and they are randomly chosen. Thanks a lot for helping! Mod Edit: Please wrap you code in either of the following in order to preserve whitespace (indentation) and to highlight the syntax.
|
Author: | Zren [ Sun May 19, 2013 6:24 pm ] | ||||
Post subject: | RE:Help With Java Hangman!! | ||||
You seem to repeating code a lot. Perhaps you could try moving the game logic (guessing a single word) to it's own function. Pass the current word you're using as a parameter. Eg:
Note that Collections.shuffle will randomly sort the array it's given. It "returns" void. As for reading a variable amount of words from file. You could have the first line of the file contain the number of words in the file. Then create an array that large and store the string in it. OR you could use an ArrayList which will allocate an ever increasing amount of memory/resize the array every time you reach the limit. In the loop below, we first call fin.readline() and assign it to the 'line' variable. Then we do the comparison with the value we assigned. To explain, it's sort of like if we replaced line = fin.readline() with the function assignVariable(line, fin.readline()) which returned the second parameter after the asignment. Note: All operations you write are really just functions that we assign syntax to make it easier to write in.
|
Author: | robs247 [ Tue May 21, 2013 12:51 pm ] |
Post subject: | Re: Help With Java Hangman!! |
I don't know what that does. I use java hsa console, so if u know it then it would be much appreciated |
Author: | Zren [ Tue May 21, 2013 6:38 pm ] |
Post subject: | RE:Help With Java Hangman!! |
Oh crap. Didn't realize you're using Ready To Program. I also misstook your "read the strings" to be File IO, but you seem to already have that done. I never used RTP but you could probably check out the documentation aka javadocs, whiiiiich don't appear to be online anywhere. Perhaps someone else knows where they are? |