-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
122 lines (92 loc) · 3.22 KB
/
Copy pathmain.py
File metadata and controls
122 lines (92 loc) · 3.22 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
def doRound(player,round,multiple):
"""
This is a function to check round answer against player answer
Args:
player: current round player
round: the round the game is currently on
multiple: the multiple the bus value is checked upon
returns:
int: 1 - correct | 0 - incorrect | -1 - invalid
"""
try:
ans = input(f"Player {player} answer:").lower()
if(ans != 'bus'):
try:
int(ans)
except ValueError as e:
raise(ValueError)
#set round answer
round_ans = "bus" if (round % multiple == 0) else str(round)
if(ans == round_ans):
return 1
else:
# print("Round Ans:",round_ans)
return 0
except ValueError as e:
print("Error:","Please Enter round asnwer correctly\n('bus' or value as integer)")
return -1
def getGameData():
"""
This is a function to get game data from the player
Args:
none
Returns:
values:both values as a list or -1 if error
"""
try:
totalPlayers = int(input("How many players:"))
multiple = int(input("Bus on which multiple:"))
print()
if(totalPlayers<2):
print("At least 2 players are needed")
elif(multiple<2):
print("At least a multiplier of 2 is required")
else:
return [totalPlayers,multiple]
except ValueError as e:
print("Error:","Please correctly enter values for the game data")
return -1
def main():
print("=========")
print("Bus Game")
print("=========")
print()
# number of player, the multiple
gameData = getGameData()
if(gameData!=-1):
# round counter
i = 1
#get of list of players
players = list(range(1, gameData[0]+1))
#main loop
while(len(players)>0):
#find the player who won
if(len(players)==1):
print("================")
print(f"Player {players[0]} Wins!")
break
player_index = (i%(gameData[0]))-1
round_ans = doRound(players[player_index],i,gameData[1])
if(round_ans == 1):
print("Correct!")
print()
elif(round_ans == 0):
print(f"Incorrect! Player {players[player_index]} lost!")
# remove failed player from game
del players[player_index]
# display remaining players (skips if 1 player becoz the game will end next round)
if(len(players)>1):
print("\nRemaining players")
for ply in players:
print(f"> Player {ply}")
print()
# starts the round off where the last person failed, remove if unnecessary
continue
else:
# starts the round off where the last person failed, remove if unnecessary
continue
# set next round
i += 1
print("Game Over!")
if __name__ == "__main__":
main()