TASK 1: HANGMAN GAME (EASY VERSION)
Save your program as HW9_Hangman.java
Implement a Hangman game. The computer will choose a word and the user will guess it. For a game description (and variations of it) see the wiki page:
- medium_1000.txt – top 1000 most frequent English words of MEDIUM length (I used these for the EASY level),
- long.txt – top 2024 most frequent English words of LONG length (I used these for the MEDIUM level),
- medium_2500.txt – top 2500 most frequent English words of MEDIUM length (I used these for the HARD level),,
- The above files were downloaded from https://github.com/first20hours/google-10000-english. I removed words that were proper names, and other jargon words that were marked as misspelled by the spell checker.
- Files with sample runs: run1.txt, run2.txt, run3_error_check.txt
Requirements (must be implemented for full credit):
- The user can select the level of difficulty. The level of difficulty will affect what list will be used to pick the word from.You must support at least 3 levels that will use the words from the 3 provided txt files with words listed above.
- Once the level is selected the user can play multiple times at that level (let’s call this one ‘session’ of games). The session will end when the user enters -1.
YOU MUST USE -1 AS THE EXIT REQUEST AT ALL TIMES. DO NOT CHANGE THIS CONVENTION. IT WOULD MAKE THIS ASSIGNMENT NEEDLESSLY DIFFICULT TO GRADE.
- End of session statistics: for each session, the computer will keep track of how many games were played and how many of those were won. At the end of the section it will print the statistics (e.g.: “Your score: 2/3” would mean that the user played 3 games and he/she won 2 out of those 3).
- Robust system:
- it should not crash for bad user input at any time and
- it should be CASE INSENSITIVE to the letters entered by the user (i.e. the program should work just as well with both ‘a’ and ‘A’) and
- it should be CASE INSENSITIVE for the words in the file (i.e. if file with mix of lowercase and uppercase letters is provided, the program should work fine).
- User friendly system: the user can stop the game whenever they want:
- quit a single game: while they are guessing a word (before winning or exhausting all their bad trials). Quitting results in the game being lost.
- quit a session: after a game is won or lost, the user is given the choice to exit the session or continue with more games (in the same session).
- quit the program: at the end of each session the user can choose a new session (with a new or the same difficulty level) or to exit the program.
- Display letters tried so far (show repetitions if the user enters the same letter multiple times). SORT them in alphabetical order. You can use the sort method from the Collections class to sort an arrayList.
- Display how many bad guessed were made and what is the maximum allowed. (See sample run files above.)
- Limit of maximum bad guesses. In my implementation I allowed 12 guesses. The standard is 6
- USEFUL COMMENTS. This is a larger project. Use comments to describe the behaviour of methods, the special choice you made, code that was difficult to develop, code that uses arithmetical tricks and may not be obvious what it does. DO NOT ADD USELESS comments. (Comments that restate the obvious will only make the program more cluttered and harder to read. E.g.:
Scanner in = new Scanner(System.in); // creates a scanner object_x000D_
Extra suggestions (if working in a pair, must implement at least one of these as well)
- When displaying the letters tried so far, print vowels first and consonants after (to make it easy to check if any vowels are left).
- Keep the cumulative statistics over sessions. That is, if the user plays two sessions at level 0, record the won games and the all played games over all sessions of that level (i.e. how many games were won out of the total games played at level 0 across all sessions of level 0).
- Record in a file the player name and save player statistics. You can keep the statistics per level (as described in the bullet above), or keep just one count of games won and one count of games played.
- If you keep a file of player names, when a player gives their name, see if they are already in the file, load their recorded counts and update those counts to reflect the results from the new sessions played.
- Add more difficulty levels. This can be done by selecting more or less words from the provided files. Note that the words in files are in decreasing order of frequency usage in English and thus the top words should be easier to guess.
- Add any other variation or improvement that you would like. I hope you will use your creativity and explore to implement whatever features you think such a game should have. For example some version of the game allow the user to choose the domain for words (see this page: http://www.playhangman.com/). See other variation on the wiki page: https://en.wikipedia.org/wiki/Hangman_(game).
- Draw a scaffold and human as mistakes are made. E.g. (case that allows 12 bad guesses):
_x000D_ ------------- (1 error/bad guess)_x000D_ | _x000D_ | _x000D_ | _x000D_ | _x000D_ | _x000D_ | _x000D_ ------------- (2 errors)_x000D_ ------_x000D_ | _x000D_ | _x000D_ | _x000D_ | _x000D_ | _x000D_ | _x000D_ ------------- (3 errors)_x000D_ _x000D_ ------|_x000D_ | |_x000D_ | _x000D_ | _x000D_ | _x000D_ | _x000D_ | _x000D_ ------------- (4 errors)_x000D_ _x000D_ ------|_x000D_ | |_x000D_ | O_x000D_ | _x000D_ | _x000D_ | _x000D_ | _x000D_ ------------- (5 errors)_x000D_ _x000D_ ------|_x000D_ | |_x000D_ | O_x000D_ | |_x000D_ | _x000D_ | _x000D_ | _x000D_ ------------- (6 errors)_x000D_ ...._x000D_ ------|_x000D_ | |_x000D_ | O_x000D_ | |_x000D_ | /|_x000D_ | |_x000D_ | / _x000D_ ------------- (11 errors)_x000D_ ------|_x000D_ | |_x000D_ | O_x000D_ | |_x000D_ | /|_x000D_ | |_x000D_ | / _x000D_ ------------- (12 error)