-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject 2.py
More file actions
108 lines (91 loc) · 1.85 KB
/
Project 2.py
File metadata and controls
108 lines (91 loc) · 1.85 KB
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
from random import choice
# Game data
lib = [
'potato',
'orange',
'dog',
'chair',
'horse',
'monkey',
'cake'
]
temp = ''
board = []
parts = 0
def makeBoard(word):
out = []
for letter in word:
obj = {'char': letter, 'show': False}
out.append(obj)
return out
def guess(letter):
global parts
fail = True
for i in board:
if i['char'] == letter:
i['show'] = True
fail = False
if fail:
parts += 1
def checkWin(board):
out = True
for i in board:
if i['show'] == False:
out = False
return out
def printMan(parts):
man = [' ', 'o', ' ', '\n', '/', '|', u'\u2216', '\n' '/', ' ', u'\u2216']
out = ''
r = 0
if parts == 1:
r = 3
elif parts == 2:
r = 5
elif parts == 3:
r = 6
elif parts == 4:
r = 7
elif parts == 5:
r = 8
elif parts == 6:
r = 10
else:
r = 0
for i in range(r):
out += man[i]
print(out)
def printBoard(board):
out = ''
for i in board:
c = '_'
if i['show']:
c = i['char']
c += ' '
out += c
print(out)
for i in range(len(lib)):
print(i + 1, lib[i])
while len(board) == 0:
print('\nPlayer 1 select a word:')
temp = int(input('> '))
if temp - 1 in range(len(lib)):
board = makeBoard(lib[temp - 1])
print(chr(27) + "[2J")
break
else:
print('Error: Not a valid selection.')
while True:
printMan(parts)
printBoard(board)
print('\nPlayer 2 select a letter:')
letter = input('> ')
print('\n')
guess(letter)
if checkWin(board):
printBoard(board)
print('\nPlayer 2 wins')
break
elif parts == 6:
printMan(parts)
print('\nPlayer 1 wins')
break