Skip to content

Commit 932bb94

Browse files
committed
Add max wait to let the anim progress without key
1 parent 1a4e12d commit 932bb94

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

squadro/animation/animated_game.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import argparse
2-
from time import sleep
2+
from time import sleep, time
33

44
import pygame
55

@@ -19,13 +19,14 @@ class GameAnimation:
1919
Visualize a game that was played between two computer agents
2020
"""
2121

22-
def __init__(self, game: Game, move_delay=.05):
22+
def __init__(self, game: Game, move_delay=.05, max_wait=None):
2323
"""
2424
:param game: Game
2525
:param move_delay: delay in seconds between moves
2626
"""
2727
self.game = game
2828
self.move_delay = move_delay
29+
self.max_wait = max_wait
2930

3031
def show(self):
3132
board = Board(self.game.n_pawns, title=f"Game Visualization: {self.game.title}")
@@ -60,15 +61,15 @@ def show(self):
6061

6162
sleep(self.move_delay)
6263

63-
@staticmethod
64-
def get_command():
64+
def get_command(self):
6565
"""
6666
Wait for a command that will dictate the next update in the animation.
6767
Available commands:
6868
- next: show the next move
6969
- previous: show the previous move
7070
- quit: quit the game
7171
"""
72+
t = time()
7273
try:
7374
while True:
7475
for event in pygame.event.get():
@@ -87,6 +88,9 @@ def get_command():
8788
return 'next'
8889
if keys[pygame.K_LEFT]:
8990
return 'previous'
91+
92+
if self.max_wait and time() - t > self.max_wait:
93+
return 'next'
9094
except SystemExit:
9195
return 'quit'
9296

0 commit comments

Comments
 (0)