other players see played cards now

This commit is contained in:
2021-01-20 22:38:12 +01:00
parent b574014c95
commit f23319b7b8
5 changed files with 42 additions and 2 deletions

View File

@ -48,6 +48,31 @@ async def play_card(player, card):
await the_game.send_page_reload()
async def play_card_js(player_id, card_idx):
global playing_lock
async with playing_lock:
try:
isActive = the_game.players_ordered[the_game.active_player].id == player_id
except IndexError:
isActive = False
if isActive:
card = the_game.play_card(player_id, card_idx)
if the_game.is_round_finished():
trick_winner, highest_card = the_game.get_trick_winner()
trick_winner.take_trick()
elif the_game.is_trick_finished():
trick_winner, highest_card = the_game.get_trick_winner()
trick_winner.take_trick()
the_game.next_trick()
s = card.json_serialise()
msg = {"type": "message", "fct": "cardPlayed", "card": s, "card_idx": card_idx,
"player": player_id, "num_players": len(the_game.players)}
for ws in the_game.websockets:
await ws.send_json(msg)
@api.route("/player/{player}/play/{card}")
async def play(req, resp, player: str, card: str):
p = int(player)
@ -99,7 +124,7 @@ async def ws_handler(ws):
if fct == 'playcard':
p = int(x['player'])
c = int(x['card'])
await play_card(p, c)
await play_card_js(p, c)
elif fct == 'setTrumpColor':
player = x['player']
color = x['color']