request game init from server
This commit is contained in:
parent
abccd2e51a
commit
bcfc488c2e
@ -4,13 +4,28 @@
|
||||
|
||||
<script>
|
||||
function playCard(card) {
|
||||
let player = {{player}}
|
||||
window.game_socket.send("playcard "+player+":"+card)
|
||||
let player = "{{player}}";
|
||||
let c = card.toString();
|
||||
var msg = {
|
||||
type: "message",
|
||||
fct: "playcard",
|
||||
player: player,
|
||||
card: c
|
||||
};
|
||||
let t = JSON.stringify(msg);
|
||||
window.game_socket.send(t);
|
||||
}
|
||||
|
||||
function setTrumpColor(color) {
|
||||
let player = {{player}}
|
||||
window.game_socket.send("setTrumpColor "+player+":"+color)
|
||||
let player = "{{player}}"
|
||||
var msg = {
|
||||
type: "message",
|
||||
fct: "setTrumpColor",
|
||||
player: player,
|
||||
color: color
|
||||
};
|
||||
let t = JSON.stringify(msg);
|
||||
window.game_socket.send(t);
|
||||
}
|
||||
</script>
|
||||
|
||||
@ -26,7 +41,8 @@
|
||||
|
||||
let game = null;
|
||||
|
||||
window.onload = function()
|
||||
//window.onload = function()
|
||||
function setupGame(names)
|
||||
{
|
||||
|
||||
PIXI.AbstractRenderer.autoDensity = true;
|
||||
@ -73,15 +89,16 @@ window.onload = function()
|
||||
loader.load(function(loader, resources)
|
||||
{
|
||||
game = new Game(app.stage, resources);
|
||||
game.init(['Hubert', 'Struppi', 'Patrice', 'Steffi', "Max", "Renate"]);
|
||||
//game.init(['Hubert', 'Struppi', 'Patrice', 'Steffi', "Max", "Renate"]);
|
||||
game.init(names)
|
||||
game.give_round(["z3", "b04", "r08", "g12", "y13", "r02", "b05", "b02", "b03", "g03", "g05"]);
|
||||
game.play_card(0, 0, "z3");
|
||||
game.play_card(1, 0, "y13");
|
||||
game.play_card(2, 0, "b02");
|
||||
game.play_card(3, 0, "r02");
|
||||
game.play_card(4, 0, "y05");
|
||||
game.play_card(5, 0, "g05");
|
||||
game.give_trick_to(0);
|
||||
//game.play_card(0, 0, "z3");
|
||||
//game.play_card(1, 0, "y13");
|
||||
//game.play_card(2, 0, "b02");
|
||||
//game.play_card(3, 0, "r02");
|
||||
//game.play_card(4, 0, "y05");
|
||||
//game.play_card(5, 0, "g05");
|
||||
//game.give_trick_to(0);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -30,16 +30,23 @@
|
||||
//alert("[open] Connection established");
|
||||
//alert("Sending to server");
|
||||
//socket.send("My name is John");
|
||||
var msg = {
|
||||
type: "message",
|
||||
fct: "requestInit",
|
||||
};
|
||||
let t = JSON.stringify(msg);
|
||||
window.game_socket.send(t);
|
||||
};
|
||||
|
||||
socket.onmessage = function(event) {
|
||||
let x = JSON.parse(event.data);
|
||||
let fct = x.fct;
|
||||
let msg = JSON.parse(event.data);
|
||||
let fct = msg.fct;
|
||||
if (fct == "reload") {
|
||||
location.reload(true);
|
||||
}
|
||||
else if (fct == "startGame") {
|
||||
let names = "..."
|
||||
let names = msg.names
|
||||
setupGame(names)
|
||||
}
|
||||
else {
|
||||
alert('unknown command: '+event.data);
|
||||
|
@ -56,6 +56,7 @@ async def play(req, resp, player: str, card: str):
|
||||
url = '/player/'+player
|
||||
api.redirect(resp, url, status_code=303)
|
||||
|
||||
|
||||
@api.route("/player/{player}/set_trump/{trump}")
|
||||
async def set_trump_color_rest(req, resp, player, trump):
|
||||
p = int(player)
|
||||
@ -64,12 +65,21 @@ async def set_trump_color_rest(req, resp, player, trump):
|
||||
await the_game.send_page_reload()
|
||||
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:
|
||||
the_game.set_trump_color(color)
|
||||
await the_game.send_page_reload()
|
||||
|
||||
|
||||
async def initGame(ws):
|
||||
p = the_game.players
|
||||
n = [x.name for x in p]
|
||||
msg = {"type": "message", "fct": "startGame", "names": n}
|
||||
await ws.send_json(msg)
|
||||
|
||||
|
||||
@api.route('/ws', websocket=True)
|
||||
async def websocket(ws):
|
||||
await ws.accept()
|
||||
@ -85,6 +95,8 @@ async def websocket(ws):
|
||||
player = x['player']
|
||||
color = x['color']
|
||||
await set_trump_color(player, color)
|
||||
elif fct == "requestInit":
|
||||
await initGame(ws);
|
||||
else:
|
||||
print("confused :(")
|
||||
|
||||
|
@ -220,6 +220,6 @@ class WizGame:
|
||||
pass
|
||||
|
||||
|
||||
p = ["A", "B", "C", "D", "E"]
|
||||
p = ["egg", "spam", "ham", "pups", "kekse"]
|
||||
the_game = WizGame(p)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user