first commit

This commit is contained in:
maddie 2021-03-18 20:11:30 +00:00
commit 98ac678602
3 changed files with 21194 additions and 0 deletions

13
README.md Normal file
View File

@ -0,0 +1,13 @@
# Hangman
## Description
A CLI version of the popular children's game Hangman. Includes 20,000+ words!
## How To Use
- Navigate inside tilde.town to /maddie/git/hangman/
- python3 hangman.py
- Have fun!
## Future Plans
Fix some bugs and add replay feature; but this should be a working copy that works on Python3. It was originally written in 2.7.3 back in 2011.

71
hangman.py Normal file
View File

@ -0,0 +1,71 @@
#!/usr/bin/env python
"""
An implementation of the game Hangman.
"""
import random
word_file = open("words.txt")
words = word_file.readlines()
word = random.choice(words).strip()
correct_guesses = []
incorrect_guesses = []
print("""
_ _
| | | |
| |__| | __ _ _ __ __ _ _ __ ___ __ _ _ __
| __ |/ _` | '_ \ / _` | '_ ` _ \ / _` | '_ \
| | | | (_| | | | | (_| | | | | | | (_| | | | |
|_| |_|\__,_|_| |_|\__, |_| |_| |_|\__,_|_| |_|
__/ |
|___/
With over 20,000+ words!""")
def print_string():
string = ""
for letter in word:
if letter in correct_guesses:
string += letter.upper() + " "
else:
string += "_ "
print(string)
def main():
print("")
while len(incorrect_guesses) < 6:
print("")
print_string()
guess = raw_input("Your guess: ").lower()
if guess in correct_guesses or guess in incorrect_guesses:
print("You've already guessed: " + guess)
if guess in word:
print("You guessed correctly! " +
guess.upper() + " is in the word.")
correct_guesses.append(guess)
won = True
for letter in word:
if letter not in correct_guesses:
won = False
if won:
print("Congratulations you discovered the mystery word and won!")
break
else:
incorrect_guesses.append(guess)
print("Incorrect! " + guess.upper() +
" is not in the word! You have " +
str(6 - len(incorrect_guesses)) +
" guesses left.")
print("The mystery word was " + word.upper() + ".")
print("Game Over!")
if __name__ == "__main__":
main()

21110
words.txt Normal file

File diff suppressed because it is too large Load Diff