set Trump Color also uses websockets now
This commit is contained in:
parent
a1710cba4a
commit
4037822446
@ -7,6 +7,11 @@
|
|||||||
let player = {{player}}
|
let player = {{player}}
|
||||||
window.game_socket.send("playcard "+player+":"+card)
|
window.game_socket.send("playcard "+player+":"+card)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setTrumpColor(color) {
|
||||||
|
let player = {{player}}
|
||||||
|
window.game_socket.send("setTrumpColor "+player+":"+color)
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="content">
|
<div class="content">
|
||||||
@ -59,10 +64,16 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% if choose_trump_color and (player == choose_trump_player) %}
|
{% if choose_trump_color and (player == choose_trump_player) %}
|
||||||
<strong>Choose Trump Color:</strong>
|
<strong>Choose Trump Color:</strong>
|
||||||
|
<!--
|
||||||
<a href="/player/{{player}}/set_trump/r">Red></a>
|
<a href="/player/{{player}}/set_trump/r">Red></a>
|
||||||
<a href="/player/{{player}}/set_trump/g">Green></a>
|
<a href="/player/{{player}}/set_trump/g">Green></a>
|
||||||
<a href="/player/{{player}}/set_trump/b">Blue></a>
|
<a href="/player/{{player}}/set_trump/b">Blue></a>
|
||||||
<a href="/player/{{player}}/set_trump/y">Yellow ></a>
|
<a href="/player/{{player}}/set_trump/y">Yellow ></a>
|
||||||
|
-->
|
||||||
|
<button onclick="setTrumpColor('r')">Red</button>
|
||||||
|
<button onclick="setTrumpColor('g')">Green</button>
|
||||||
|
<button onclick="setTrumpColor('b')">Blue</button>
|
||||||
|
<button onclick="setTrumpColor('y')">Yellow</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<!--
|
<!--
|
||||||
<li>
|
<li>
|
||||||
|
@ -52,7 +52,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
socket.onerror = function(error) {
|
socket.onerror = function(error) {
|
||||||
alert(`[error] ${error.message}`);
|
alert("[error]: "+error.message);
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
@ -56,13 +56,20 @@ async def play(req, resp, player: str, card: str):
|
|||||||
api.redirect(resp, url, status_code=303)
|
api.redirect(resp, url, status_code=303)
|
||||||
|
|
||||||
@api.route("/player/{player}/set_trump/{trump}")
|
@api.route("/player/{player}/set_trump/{trump}")
|
||||||
async def set_trump_color(req, resp, player, trump):
|
async def set_trump_color_rest(req, resp, player, trump):
|
||||||
p = int(player)
|
p = int(player)
|
||||||
the_game.set_trump_color(trump)
|
the_game.set_trump_color(trump)
|
||||||
url = '/player/'+player
|
url = '/player/'+player
|
||||||
await the_game.send_page_reload()
|
await the_game.send_page_reload()
|
||||||
api.redirect(resp, url, status_code=303)
|
api.redirect(resp, url, status_code=303)
|
||||||
|
|
||||||
|
async def set_trump_color(player, color):
|
||||||
|
p = int(player)
|
||||||
|
if p != the_game.players_ordered[-1].id:
|
||||||
|
print("error error error: not allowed")
|
||||||
|
else:
|
||||||
|
the_game.set_trump_color(color)
|
||||||
|
await the_game.send_page_reload()
|
||||||
|
|
||||||
@api.route('/ws', websocket=True)
|
@api.route('/ws', websocket=True)
|
||||||
async def websocket(ws):
|
async def websocket(ws):
|
||||||
@ -74,6 +81,11 @@ async def websocket(ws):
|
|||||||
if fct == "playcard":
|
if fct == "playcard":
|
||||||
p, c = map(int, args.split(':'))
|
p, c = map(int, args.split(':'))
|
||||||
await play_card(p, c)
|
await play_card(p, c)
|
||||||
|
elif fct == "setTrumpColor":
|
||||||
|
player, color = args.split(':')
|
||||||
|
print("trump color choesen by {} is: {}".format(player, color))
|
||||||
|
await set_trump_color(player, color)
|
||||||
|
|
||||||
except WebSocketDisconnect:
|
except WebSocketDisconnect:
|
||||||
the_game.websockets.remove(ws)
|
the_game.websockets.remove(ws)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user