implement undo function

This commit is contained in:
2020-05-21 18:49:52 +02:00
parent c6def1169f
commit 688641d749
3 changed files with 37 additions and 0 deletions

View File

@ -51,3 +51,34 @@ async def start_next_trick(req, resp):
pass
api.redirect(resp, '/control/', status_code=303)
@api.route("/control/undo_last/")
async def undo_last(req, resp):
hand_finished = the_game.is_hand_finished()
if the_game.played_cards:
if not hand_finished:
p, c = the_game.played_cards.pop()
the_game.active_player -= 1
p.add_card(c)
for ws in the_game.websockets:
try:
await ws.send_text("reload")
except Exception as e:
pass
else:
if the_game.num_tricks_played > 0:
the_game.num_tricks_played -= 1;
the_game.played_cards = the_game.last_trick;
the_game.active_player = len(the_game.players) - 1
player, _ = the_game.get_trick_winner()
player.tricks_taken -= 1
the_game.players_ordered = [p for p, _ in the_game.played_cards]
p, c = the_game.played_cards.pop()
p.add_card(c)
for ws in the_game.websockets:
try:
await ws.send_text("reload")
except Exception as e:
pass
api.redirect(resp, '/control/', status_code=303)