Word Guess

Exercise

Write a program called WordGuess to guess a word by trying to guess the individual characters (Also called hangman).

Fulfill the following requirements:

  • The word to be guessed and the maximum number of fails shall be provided before the process of guessing begins.
  • The word must only contain letters. If the word is invalid ask the user again until the word is valid.
  • Ensure that the person who plays the game cannot see the guess word which was typed in before the game started.
  • If the number of fails is invalid or negative ask the user again until the number is valid.
  • After each guessed character print the number of fails or print a hangman which represents the number of fails.
  • If the word was guessed correctly or the maximum number of fails are reached tell the user how the game ended.

Example Input / Output

The following console log shows an example of the different events which took place while playing the game:

Type in the word to be guessed: te!ting
The guess word is invalid (Only letters are allowed)
Type in the word to be guessed: testing
Type in the number of allowed fails: -3
The number of allowed fails is invalid (The number has to be positive)
Type in the number of allowed fails: 3

The guessing begins:
Type in one character or your guess word: t
t _ _ t _ _ _ --> 0 / 3 fails
Type in one character or your guess word: g
t _ _ t _ _ g --> 0 / 3 fails
Type in one character or your guess word: b
t _ _ t _ _ g --> 1 / 3 fails
Type in one character or your guess word: e
t e _ t _ _ g --> 1 / 3 fails
Type in one character or your guess word: testing

Congratulation!
You guessed the word with 1 fails

Source:

results matching ""

    No results matching ""