-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.py
78 lines (45 loc) · 1.91 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
import requests
import json, sys, readchar
import random
banner = """
(_____) ____ ____ ____ (__ _ __)(_) ____ (_) _ (_) _ (_)
(_) ___ _ _ (____)(____)(____) (_) (_)__ (____) (_) (_) (_) ___ (_)__ __(_)
(_) (___)(_) (_)(_)_(_)(_)__ (_)__ (_) (____) (_)_(_) (_) (_) (_) (___) (____)(____)
(_)___(_)(_)_(_)(__)__ _(__) _(__) (_) (_) (_)(__)__ (_)_(_)_(_)(_)_(_)(_) (_)_(_)
(_____) (___) (____)(____)(____) (_) (_) (_) (____) (__) (__) (___) (_) (____)
"""
# Getting The Word
lines = open('./words.txt').read().splitlines()
word =random.choice(lines)
word = word.lower()
guessed_letters = []
print(banner)
def censored_word():
return ''.join(c if c in guessed_letters else '_' for c in word)
print(censored_word())
def is_game_over():
unique_letters_in_answer = ''.join(set(word))
# Winning
if (len(unique_letters_in_answer) == len(guessed_letters)):
print("Congrats, You won!")
return True
# Losing
if (attempts == 0):
print("You lost, womp womp :(, the word was " + word)
return True
return False
attempts = 10
while(not is_game_over()):
letter = repr(readchar.readchar())[1]
#Kill Switch
if (letter == '\\'):
exit(0)
print(letter)
if (letter in word and not (letter in guessed_letters)):
print("Correct!")
guessed_letters.append(letter)
else:
attempts-=1
print("No no :(, attempts left " + str(attempts))
guessed_word = censored_word()
print(guessed_word)