other players see played cards now
This commit is contained in:
parent
b574014c95
commit
f23319b7b8
@ -1 +1 @@
|
|||||||
Subproject commit 0115621a3d1081239fbea7a7746d7093dc67524f
|
Subproject commit 4d88b9198cb335414600aab691bbe1ae5edb590c
|
@ -101,6 +101,7 @@ function setupGame(names, hand)
|
|||||||
//game.play_card(4, 0, "y05");
|
//game.play_card(4, 0, "y05");
|
||||||
//game.play_card(5, 0, "g05");
|
//game.play_card(5, 0, "g05");
|
||||||
//game.give_trick_to(0);
|
//game.give_trick_to(0);
|
||||||
|
window.the_game = game;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -71,6 +71,13 @@
|
|||||||
setupGame(names, window.hand)
|
setupGame(names, window.hand)
|
||||||
//alert('game is set up')
|
//alert('game is set up')
|
||||||
}
|
}
|
||||||
|
else if (fct == "cardPlayed") {
|
||||||
|
let player_id = msg.player;
|
||||||
|
let card_idx = msg.card_idx;
|
||||||
|
let card = msg.card;
|
||||||
|
let num_players = msg.num_players;
|
||||||
|
cardPlayed(player_id, card_idx, card, num_players)
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
alert('unknown command: '+event.data);
|
alert('unknown command: '+event.data);
|
||||||
}
|
}
|
||||||
@ -103,6 +110,12 @@
|
|||||||
window.game_socket.send(t);
|
window.game_socket.send(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function cardPlayed(player, card_idx, card, num_players) {
|
||||||
|
let myself = "{{player}}";
|
||||||
|
let player_idx = ((player + num_players) - myself) % num_players;
|
||||||
|
window.the_game.play_card(player_idx, card_idx, card)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -48,6 +48,31 @@ async def play_card(player, card):
|
|||||||
await the_game.send_page_reload()
|
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}")
|
@api.route("/player/{player}/play/{card}")
|
||||||
async def play(req, resp, player: str, card: str):
|
async def play(req, resp, player: str, card: str):
|
||||||
p = int(player)
|
p = int(player)
|
||||||
@ -99,7 +124,7 @@ async def ws_handler(ws):
|
|||||||
if fct == 'playcard':
|
if fct == 'playcard':
|
||||||
p = int(x['player'])
|
p = int(x['player'])
|
||||||
c = int(x['card'])
|
c = int(x['card'])
|
||||||
await play_card(p, c)
|
await play_card_js(p, c)
|
||||||
elif fct == 'setTrumpColor':
|
elif fct == 'setTrumpColor':
|
||||||
player = x['player']
|
player = x['player']
|
||||||
color = x['color']
|
color = x['color']
|
||||||
|
@ -203,6 +203,7 @@ class WizGame:
|
|||||||
self.active_player += 1
|
self.active_player += 1
|
||||||
if self.is_trick_finished():
|
if self.is_trick_finished():
|
||||||
self.num_tricks_played += 1
|
self.num_tricks_played += 1
|
||||||
|
return c # return card to calling function
|
||||||
|
|
||||||
def set_trump_color(self, trump_color):
|
def set_trump_color(self, trump_color):
|
||||||
if self.trump_card.value != 'Z':
|
if self.trump_card.value != 'Z':
|
||||||
|
Loading…
Reference in New Issue
Block a user