Thread Hangman: quiz of the week #17
(6 answers)
Opened by Crian at 2004-05-28 22:26
Ich beteilige mich bei "Quiz of the week", diese Woche war folgende Aufgabe zu lösen:
Quiz of the Week #17 The given problem was: The Game of Hangman The goal of the game is to guess a word with a certain (limited) number of guesses. If we fail the "man" gets "hanged," if we succeed he is set free. (We're not going to discuss the lesson's of life or justice this game teaches to the 8 year olds who play it regularly). The game starts out with one person (not the player) choosing a "mystery" word at random and telling the player how many letters the mystery word contains. The player then guesses letters, one at a time, and the mystery word's letters are filled in until a) the entire word is filled in, or b) the maximum number of guesses are reached and the the player loses (man is hanged). Write a perl program which lets the user play hangman. The program should take the following arguments: 1) the dictionary file to use 2) the maximum number of guesses to give the player. The program must then chose a mystery word from the dictionary file and print out as many underscores ("_") as there are letters in the mystery word. The program will then read letters from the user one at a time. After each guess the program must print the word with properly guessed letters filled in. If the word has been guessed (all the letters making up the word have been guessed) then the program must print "LIFE!" and exit. If the word is not guessed before the maximum number of guesses is reached then the program must print "DEATH!" and exit. Example interaction: Code: (dl
)
1 % ./hangman /usr/share/dict 5 NOTES ------ 1) The dictionary file will contain one word per line and use only 7-bit ASCII characters. It may contain randomly generated words. The dictionary will contain only words longer than 1 character. The size of the dictionary may be very large. See http://perl.plover.com/qotw/words/ for sample word lists. 2) The dictionary file used for the test (or the program for generating it) will be made available along with the write-up. 3) If a letter appears more than once in the mystery word, all occurrences of that letter must be filled in. So, if the word is 'bokonon' and the player guesses 'o' the output must be '_o_o_o_'. It was remarked from someone, that these rules are not the original game rules (because normaly you get only a bad point for wrong guesses or right guesses you have already asked. s--Pevna-;s.([a-z]).chr((ord($1)-84)%26+97).gee; s^([A-Z])^chr((ord($1)-52)%26+65)^gee;print;
use strict; use warnings; Link zu meiner Perlseite |