-
Notifications
You must be signed in to change notification settings - Fork 0
/
games.py
131 lines (92 loc) · 3 KB
/
games.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
import players
#===============================================================================
def play501(people):
print "\nPlaying 501"
num_people = len(people)
score = [501 for i in range(num_people)]
while min(score) != 0:
for i in range(num_people):
displayScore(people,score)
total = input( "Player {0}: ".format(people[i]) )
while total < 0 or total > 180:
total = input( "Invalid entry. Player {0}: ".format(people[i]) )
if total <= score[i]:
score[i] = score[i] - total
else:
print " Bust."
if score[i] == 0:
print "{0} wins!".format(people[i])
break
#===============================================================================
def displayScore(names,score):
print "\nScore:"
for i in range(len(score)):
print " {0}: {1}".format(names[i],score[i])
print
#===============================================================================
def setupGame():
people = []
num_people = 0
game = '501'
sets = 1
legs = 1
while True:
print """
Game Menu
Current Game: {0}
Match: race to {1} sets
Set: race to {2} legs
Players:""".format(game,sets,legs)
if num_people==0:
print " None"
for p in people:
print " {0}".format(p)
print """
1 -- Play Game
2 -- Change Game
3 -- Change Sets/Legs
4 -- Manage Game Players
0 -- Main Menu
"""
option = input("Input option: ")
if option==0:
break
elif option==1:
if num_people==0:
print "Error! At least one player is required."
continue
play501(people)
break
elif option==2:
print "501 is the only available game."
elif option==3:
sets = input("Match: Race to X sets: ")
legs = input("Set: Race to X legs: ")
elif option==4:
people = manageGamePlayers(people)
num_people = len(people)
else:
break
def manageGamePlayers(people):
while True:
print "\nCurrent players:"
for p in people:
print " {0}".format(p)
if len(people)==0:
print " None"
print """
1 -- Add Player
2 -- Remove Player
0 -- Back
"""
option = input("Input option: ")
if option==0:
break
elif option==1:
name = raw_input("Input name: ")
exists = players.playerExists(name)
if exists:
people.append(name)
else:
print "Error! Player {0} not in database.".format(name)
return people