Skip to content

Hangman is a classic game in which a player thinks of a word and the other player tries to guess that word within a certain amount of attempts. This is an implementation of the Hangman game, where the computer thinks of a word and the user tries to guess it.

License

Notifications You must be signed in to change notification settings

Kevin-MrYe/Hangman_game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hangman_game

Milestone 1

In this milestone, the ask_letter() function was implemented, which will ask the user for a letter. The flow chart is as follows: This is an image

Milestone 2

In this milestone, the attributes were added to the init method. Then the ask_letter() function was updated to whether the typed letter has been tried already.

1.word: The word to be guessed picked randomly from the word_list

2.word_guessed: A list of the letters of the word, with '_' for each letter not yet guessed

3.num_letters: The number of UNIQUE letters in the word that have not been guessed yet

4.num_lives: The number of lives the player has

5.list_letters: A list of the letters that have already been tried

The flow chart is as follows: This is an image

Milestone 3

In this milestone, the check_letter() function was implemented, which will check if the letter is in the word. If it is, it replaces the '_' in the word_gressed list with the letter. If it is not, it reduces the number of lives by 1.

  1. Using the if letter in word: to check if the letter is in word.
  2. Using the following code to replace the '_' in the word_gressed list with the letter
for i in range(0,len(self.word)):
     if self.word[i] == lower_letter:
         self.word_gessed[i] = lower_letter

The flow chart is as follows: This is an image

Milestone 4

In this milestone, ask the user to enter a letter until the user guesses the word. In addition, whenever the user lose a life, an additional part of hangman will be visualised. A list name show_status will store the visualizations which correspond to num_lives. The core code is as follows:

game = Hangman(word_list, num_lives=6)
    while True:
        game.ask_letter()
        if '_' not in game.word_gessed:
            print("Congratulation! You won!")
            exit()
        elif game.num_lives == 0:
            print(f"You lost! The word was {game.word}")

About

Hangman is a classic game in which a player thinks of a word and the other player tries to guess that word within a certain amount of attempts. This is an implementation of the Hangman game, where the computer thinks of a word and the user tries to guess it.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages