90 pts |
Hangman |
Due: Nov 1 |
Use PHP to produce an on-line hangman game like this one. The game chooses a word of at least five characters at random, and the player tries to figure out what word has been chosen by guessing letters. They player must find the word with no more than six incorrect guesses.
The word is initially shown as a sequence of blanks, one for each letter. When a letter is guessed, if it occurs in the chosen word, the blank(s) where that letter resides are replaced with the letter. If it does not appear in the word, it counts as a wrong guess, and one part is added to the stick figure on the stick gallows. The figure has six parts. If a wrong guess is made after the figure is fully drawn, the player loses. If all the letters are guessed, the player wins.
The words are chosen from a list available at here. The file is simply a list of words, one per line. It does include names. You will need to download a copy and store it somewhere in your own account; the security settings used for PHP prevent us from sharing a copy.
My code to choose a word at random performs the following steps:
The stick figures are a sequence of GIF images. You may use mine, located at http://sandbox.mc.edu/~bennet/php/leccode/imgs/hang0.gif through http://sandbox.mc.edu/~bennet/php/leccode/imgs/hang6.gif, or you may make prettier ones.