Hangman
#1 is the traditional game of Hangman. One player, the hangman chooses a
word kept secret from the other player, the convict. The convict
guesses letters in the unknown word - he gets to see each correct guess placed
wherever it occurs in the secret word. Each incorrect guess adds
another piece to the gallows and an effigy of the hanging convict. If he
completes the word before the picture is complete, he goes free.
Otherwise, the convict is the big loser.
This game provides the framework for a future version with computer play. Here we'll define the basic drawing strategy, an array of 9 TPiece objects defining the gallows and hanging man. A TList component is an ideal place to keep a list of objects - HangManList is a TList containing the parts of the drawing in the order that they should be drawn.
Initially we get a "secret" word from the hangman - The passwordchar property is optionally used to hide the word from prying eyes as it is being entered - the same technique used in password dialogs. Then the "convict" makes letter guesses until he wins (completes the secret word) or loses (completes the drawing).
The CheckALetter procedure takes the convict's guess and either fills in the correct letter or draws one more piece and then checks if the letter was a winning or losing move. A simple ShowMessage call displays winning or losing messages.
| A future computer play version will use a dictionary to let the computer take the role of convict or hangman. | |
| I'm not sure if there is an "official" number of wrong guesses before the drawing is complete - ours has 9, but a harder version could end at 7 by , for example, drawing both arms or both legs as a result of a wrong guess. |
Modified: November 07, 2008