-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathJumper.py
96 lines (83 loc) · 2.76 KB
/
Jumper.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
from ast import keyword
import random
from words import Word
#from letters import Letters
class Game():
def create_parachute(self, incorrect):
if incorrect == 0:
print(f' ㅡ')
if incorrect < 2:
print(f'/ \ ')
if incorrect < 3:
print('ㅡ ㅡ')
if incorrect < 4:
print(f'\ /')
if incorrect < 5:
print(' \ /')
def create_man(self):
print(' O')
print('/ | \ ')
print(' / \ ')
def get_input(self, guesses):
self.guess = input('Guess a letter from a-z: ')
if len(self.guess) == 1:
if self.guess.isalpha() == True:
if self.guess not in guesses:
return self.guess
else:
print('You have already guessed that')
return self.guess
else:
print('Your guess is not a letter')
return self.guess
else:
print('Your guess is too long')
return self.guess
def create_lines(self, key):
output = []
for i in range(len(key)):
print('_', end='')
output.append('_')
print('')
return output
def get_lines(self, output, key, guesses):
for i in range(len(key)):
for j in range(len(guesses)):
if key[i] == guesses[j]:
output.pop(i)
output.insert(i, key[i])
for i in range(len(key)):
print(output[i], end='')
print('')
return output
def main(self):
obj = Word()
key_word = obj.key_word
key = key_word
incorrect = 0
win = False
guesses = []
word = []
for i in range(len(key_word)):
word.append('_')
number = 0
while win == False:
self.create_parachute(incorrect)
self.create_man()
if number < 1:
output = self.create_lines(key)
else:
total = self.get_lines(output, key, guesses)
if '_' not in total:
win = True
print('Congradulations!!! You have won!!!')
if win == False:
input = self.get_input(guesses)
guesses.append(input)
if guesses[number] not in key:
incorrect += 1
print('You have guessed incorrectly')
if incorrect == 5:
win = True
print('You have lost the game')
number += 1