-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplay.py
executable file
·159 lines (123 loc) · 4.66 KB
/
play.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/env python3
import threading
import json
import time
import pprint
from lib.game import Game
from lib.scale import Scale
from lib.config import TEST_MODE
from lib.term_controls import clear_screen
from lib.sounds import Sounds
def player_names(n):
""" prompt the users for a list of player names """
player_names = []
for p in range(n):
name = input(f"Who is player {p + 1}? ")
player_names.append(name)
return player_names
def main():
print ("Welcome to SpeedJenga!")
#init sounds
sound = Sounds()
#setup players
if TEST_MODE:
players = ["Tuna","Trout","QV","Clover"]
else:
number_of_players = int(input('How many players? '))
players = player_names(number_of_players)
while True:
game = Game(players)
scale = Scale()
countdown = False
paused = False
clear_screen()
input("Press enter to start the game")
clear_screen()
while True:
game.current_player().start_turn()
sound.start_turn()
print (game.scoreboard())
while (scale.on() or scale.paused()) and not game.current_player().out_of_time():
print (game.current_player().status(), end="\r")
if game.current_player().current_time() <= 10 and not countdown:
sound.warning()
countdown = True
#pause block logic
if scale.paused() and not game.current_player().out_of_pause_blocks():
paused = True
sound.stop_all()
game.current_player().pause_turn()
sound.pause_turn()
clear_screen()
print (game.scoreboard())
print (game.current_player().status())
while scale.paused():
pass
break
sound.stop_all()
game.current_player().end_turn()
countdown = False
clear_screen()
#check if game is over
if game.one_player_remains() or scale.collapsed():
if scale.collapsed():
game.current_player().out_of_game = True
game.current_player().knock_over_tower = True
break
#check if player is out of the game
if game.current_player().out_of_time() or scale.disqualified() and not paused:
game.current_player().out_of_game = True
sound.out_of_game()
else:
sound.end_turn()
#check if end of round
if game.round_complete():
game.end_round()
#display game info
print (game.scoreboard())
print (game.current_player().status())
print (f"next player: {game.next_player_name()} ({game.next_player_current_time()})")
#prompt user for next turn
if scale.on() and not paused:
input("Press enter to start next turn")
else:
if paused:
print('Please remove pause block')
while scale.on():
pass
print ("waiting for tower to be restored...")
while scale.off() or scale.disqualified():
pass
#print (scale.status(), end="\r")
s = game.stability_seconds()
print (f"tower must stay stable for {s} second(s)...")
time.sleep(s)
if scale.collapsed():
game.current_player().destroyer = True
game.current_player().out_of_game = True
break
else:
print ("success!")
game.moves += 1
paused = False
game.move_to_next_player()
clear_screen()
scale.stop()
game.end_game()
clear_screen()
print ("GAME OVER\n")
print (game.scoreboard())
#pprint.pprint(game.data,indent=4)
game.graph()
while True:
answer = input("Would you like to play again? y/n: ")
if answer in ['n','N','no','No','y','Y','yes','Yes']:
break
else:
print ("{} is not an option: Please try again.".format(answer))
if answer in ['n','N','no','No']:
break
print("Thanks for playing!")
#print json.dumps(game.data, indent=4)
if __name__ == "__main__":
main()