-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.py
156 lines (128 loc) · 5.49 KB
/
Game.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# This is a program that plays hangman on the command line
# 1: Set A word
# 2: Set a Theme
# 3. Display the # of body parts
# 4. Display the word spaces
# 5. Display used letter
# 6. Display Correct Letter
# 7. End Game
import random
from time import sleep
people = ['Naval Ravikant', 'Paul Graham', 'Kevin Hart', 'Albert Einstein', 'Kanye West', 'Elon Muskrat', 'Neil deGrasse Tyson']
animals = ['Cat', 'Dog', 'Flamingo', 'Dodo Bird', 'Gazelle']
place = ['France', 'Wakanda', 'Burkina Faso', 'Canada']
tv_shows_and_movies = ['The Blacklist', 'Forrest Gump', 'The Social Network', 'The Office', 'How I Met Your Mother', 'Kung Fu Panda']
themes = [people, animals, place, tv_shows_and_movies]
theme_choice = random.choice(themes)
word = random.choice(theme_choice)
word = word.lower()
if len(theme_choice) == 7:
print("The Theme is People")
elif len(theme_choice) == 6:
print('The Theme is Tv Shows and Movies')
elif len(theme_choice) == 5:
print('The Theme is Animal')
else:
print('The theme is Places')
print("Your Hangman has 11 parts: 1 head , 1 body , 2 arms, 2 feet, 1 fedora, 2 eyes, 1 nose and 1 mouth!")
numspaces = ""
if " " not in word:
numspaces = len(word) * "_ "
print(numspaces)
else:
word = word.split()
count = 0
while count <= (len(word) - 1):
numspaces += (len(word[count]) * "_ ") + " "
count += 1
print(numspaces)
def guesses(word_choice, spaces):
win = False
lose = False
if type(word_choice) == list:
word_choice = " ".join(str(word) for word in word_choice)
list_word_choice = word_choice.split() #helpful for determining if it's a single word answer or multiple
incorrect_guesses = []
while win == False and lose == False:
hangman_parts = 11 - len(incorrect_guesses)
if "_" not in spaces: #determines if the game is over
win = True
print()
print("You Won!")
elif hangman_parts <= 0:
lose = True
print()
print('You Lost.')
else:
print()
print("Make the wrong choice, just type '!back' to go to the guess selection")
word_or_letter = input('Would you like to guess: W for Word, L for Letter, or D for Dub/Solution: ')
if word_or_letter.upper() == 'L':
letter = (input("What letter would you like to guess: ")).lower()
if letter == '!back':
pass
elif letter in word_choice:
letter_index = [i*2 for i, n in enumerate(word_choice) if n == letter] #as letter are spaced out in spaces, the index will be *2 the amount
spaces = list(spaces)
count = 0
for index in letter_index:
spaces[letter_index[count]] = letter
count += 1
else:
incorrect_guesses.append(letter)
incorrect_guess(hangman_parts, incorrect_guesses, spaces)
spaces = "".join(spaces)
print(spaces)
elif word_or_letter.upper() == 'W':
word_guess = input('What Word will you like to guess: ')
word_index = [word_choice.find(word_guess)]
if word_guess in list_word_choice:
word_guess = list(word_guess)
word_guess = " ".join(word_guess) # eg. a p p l e
word_index = [i*2 for i in word_index]
replace_index = int(word_index[0])
spaces = list(spaces)
spaces[replace_index] = word_guess
del spaces[replace_index+1: (replace_index + len(word_guess))]
else:
incorrect_guesses.append(word_guess)
incorrect_guess(hangman_parts, incorrect_guesses, spaces)
spaces = "".join(spaces)
sleep(1)
print(spaces)
elif word_or_letter.upper() == 'D':
solution_guess = input("What phrase do you think will get you the win? ")
solution_guess = solution_guess.lower()
if solution_guess == word_choice:
solution_guess = list(solution_guess)
solution_guess = " ".join(solution_guess)
solution_guess = solution_guess.upper()
print()
print(solution_guess)
print()
print("You Won!")
break
else:
incorrect_guesses.append(solution_guess)
incorrect_guess(hangman_parts, incorrect_guesses, spaces)
spaces = "".join(spaces)
sleep(1)
print(spaces)
else:
print()
print("Sorry, that is not an option. You must type either 'W', 'L' or 'D'.")
print()
def incorrect_guess(hangman_parts, incorrect_guesses, spaces):
hangman_parts -= 1
print("Your hangman has...")
sleep(1)
if hangman_parts == 1:
print("%d part left!" % hangman_parts)
else:
print("%d parts left!" % hangman_parts)
sleep(1)
print("Sorry, that was incorrect")
sleep(1)
print("These are your incorrect guesses: %s" % incorrect_guesses)
print()
guesses(word, list(numspaces))