-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject.py
216 lines (180 loc) · 5.74 KB
/
project.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
import random
import re
films = [
'The Godfather (1972)',
'The Shawshank Redemption (1994)',
'The Godfather, Part II (1974)',
'The Dark Knight (2009)',
'12 Angry Men (1957)',
'Schindler\'s List (1993)',
'The Lord of the Rings: The Return of the King (2003)',
'Pulp Fiction (1994)',
'The Good, the Bad, and the Ugly (1966)',
'The Lord of the Rings: The Fellowship of the Ring (2001)',
'Fight Club (1999)',
'Forrest Gump (1994)',
'Inception (2010)',
'The Lord of the Rings: The Two Towers (2002)',
'Star Wars: Episode V: The Empire Strikes Back (1980)',
'The Matrix (1999)',
'GoodFellas (1990)',
'One Flew Over The Cuckoo\'s Nest (1975)',
'The Seven Samurai (1954)',
'Se7en (1995)',
'Life is Beautiful (1997)',
'City of God (2002)',
'The Silence of the Lambs (1991)',
'It\'s A Wonderful Life (1946)',
'Star Wars (1977)',
'Saving Private Ryan (1998)',
'Spirited Away (2001)',
'The Green Mile (1999)',
'Interstellar (2014)',
'Parasite (2019)',
'Leon, aka The Professional (1994)',
'The Usual Suspects (1995)',
'Harakiri (1962)',
'The Lion King (1994)',
'Back to the Future (1985)',
'The Pianist (2002)',
'Terminator 2: Judgment Day (1991)',
'American History X (1998)',
'Modern Times (1936)',
'Psycho (1960)',
'Gladiator (2000)',
'City Lights (1931)',
'The Departed (2006)',
'The Intouchables (2011)',
'Whiplash (2014)',
'The Prestige (2006)',
'Grave of the Fireflies (1988)',
'Hamilton (2020)',
'Once Upon a Time in the West (1969)',
'Casablanca (1942)',
'Cinema Paradiso (1988)',
'Rear Window (1954)',
'Alien (1979)',
'Apocalypse Now (1979)',
'Memento (2000)',
'The Great Dictator (1940)',
'Raiders of the Lost Ark (1981)',
'Django Unchained (2012)',
'The Lives of Others (2006)',
'Joker (2019)',
'Paths of Glory (1957)',
'WALL-E (2008)',
'The Shining (1980)',
'Avengers: Infinity War (2018)',
'Sunset Boulevard (1950)',
'Witness For the Prosecution (1957)',
'Spider-Man: Into the Spider-Verse (2018)',
'Oldboy (2003)',
'Princess Mononoke (1997)',
'Dr. Strangelove or: How I Learned To Stop Worrying and Love the Bomb (1964)',
'The Dark Knight Rises (2012)',
'Once Upon a Time in America (1984)',
'Aliens (1986)',
'Your Name. (2016)',
'Avengers: Endgame (2019)',
'Coco (2017)',
'American Beauty (1999)',
'Braveheart (1995)',
'Das Boot (1981)',
'3 Idiots (2009)',
'Toy Story (1995)',
'High and Low (1963)',
'Capernaum (2018)',
'Amadeus (1984)',
'Inglourious Basterds (2009)',
'Star Wars: Episode VI - Return of the Jedi (1983)',
'Like Stars on Earth (2007)',
'Good Will Hunting (1997)',
'Reservoir Dogs (1992)',
'2001: A Space Odyssey (1968)',
'Requiem for a Dream (2000)',
'Vertigo (1958)',
'M (1931)',
'Eternal Sunshine of the Spotless Mind (2004)',
'The Hunt (2012)',
'Dangal (2016)',
'Citizen Kane (1941)',
'1917 (2019)',
'Full Metal Jacket (1987)',
'The Bicycle Thief (1948)',
]
def main():
input('\nHello, press enter to play hangman!')
print('\nEnter -e or --exit to end game')
print('Enter -r or --retry to restart game with another movie.\n\n')
# select a random movie
movie, year = select_movie(films)
# print movie name and year - DEMO
# print(f'(Demo purpose - Movie name : {movie})\n')
# frame question with blanks
ques = question(movie)
# create list of moviename
movie_list = [letter for letter in movie]
# run game and get result
res = game(ques, movie_list, year)
if res == 'exit':
print('Game Ended.')
return
if res == True or res == False:
print(get_result(res))
def select_movie(films):
movie = random.choices(films)
if search := re.search(r'^([A-Za-z0-9_.-:,\' ]*) \((\d{4})\)$', movie[0]):
return search.groups()
def question(movie_name):
q = []
for letter in movie_name:
if letter.isalpha() or letter.isnumeric():
q.append('_')
else:
q.append(letter)
return q
def game(question, movie, year):
# create moviename in str
moviename = ''.join(map(str, movie)).strip().lower()
# copy moviename list
moviecp = movie.copy()
# create a list of all elements of movie in lowercase
lower_movie = [x.lower() for x in movie]
# initiate counter
count = 1
hint = False
while count < 11 and '_' in question:
print(*question, '\n')
if count > 5 and hint == False:
print('To get hint, enter \'--hint\'\n')
answer = input(f'Guess a character or the movie name ({11-count} chances left): ').lower().strip()
if answer == '--hint' and count > 5 and hint == False:
print(f'The movie was released in {year}\n')
hint = True
elif answer == '--exit' or answer == '-e' or answer == '--quit':
return 'exit'
elif answer == '-r' or answer == '--retry':
print('\n')
return main()
elif answer in lower_movie:
while answer in lower_movie:
index = lower_movie.index(answer)
question[index] = moviecp[index]
lower_movie[index] = 'NULL'
elif answer == moviename:
question=moviecp.copy()
break
else:
# if wrong guess increase counter
count+=1
if count < 11:
print(*question,'\n')
return True
return False
def get_result(result):
if result:
return 'Correct!'
else:
return 'Incorrect, try again!'
if __name__ == "__main__":
main()