-
Notifications
You must be signed in to change notification settings - Fork 0
S21_HangmanGUI_Medium
The GUI must include the following:
- A place to enter the word to be guessed. This needs to be hidden in some way so the guesser cannot see it.
- The number of guesses the guesser has left
- The incorrect letters guessed so far
- Place for the guesser to enter in letters
- Readout for displaying the number of characters in the word and which ones the guesser has guessed.
- Indication of when the game is over.
- The GUI must progressively draw the hangman diagram as the guesser guesses wrong letters. You must use either the Java Graphics or Graphics 2D class (see Chapter 13 in the 10th edition). At a minimum, this needs to be a simple stick diagram as shown here.
To start the game compile and run Hangman
. Once the GUI is loaded a random word will be picked and you can immediately start the play. Enter your guess in the bottom right text box and click confirm when you're ready to enter your guess. Only a single letter may be guessed at a time. Previously incorrect guesses will be show to the right of where you enter your guesses and the hangman's status will be displayed above. Once the game is over or you give up, you can start a new game by selection File -> New
Hangman
is a JavaFX program where the HangmanFX.fxml
controls the layout designed in SceneBuilder and the Hangman
class loads the fxml file and creates and shows the scene on the stage. HangmanController
controls the actions for the program. The game flow is controlled through onConfirmClicked(ActionEvent)
which can be called through the player clicking the "Guess" button or clicking enter while the guessing text field is selected. The game flow follows the rules of hangman and as guesses are made and games are won or lost the correct data fields relating to the game will be updated. Once the game has finished no input is used until a new game has been started.
hangmanShapes
is an array of Shapes that make up the drawing of the hangman and are ordered from lowest index to highest index based on the order they will be drawn in the program. The current hangman shape that is shown is tracked by hangmanIndex
.
The current word being guessed is stored in word
and the letters that should be shown are stored in showChar
where the index of the array corresponds to an index of the character in the word
string. The setHangmanWord()
method uses these data structures to create the current game state of known and unknown letters of the word to the player. The POSSIBLE_WORDS
array is the word list for the program that contains all the possible words that will be randomly chosen to guess.
newGameClicked(ActionEvent)
handles when File -> New is clicked. When the method is called it resets the states where necessary and chooses a new word to be guessed.
UML Diagram:
The java documents are served from a local web server on this machine. To start the web server, navigate to the directory immediately above where the source code is checked out (i.e. ~/git ) and then use "python -m SimpleHTTPServer" in that directory.
cd ~/git
python -m SimpleHTTPServer&
Note: if you are running python 3 (which you can check via opening a terminal and typing: python --version), then the command is:
python3 -m http.server