diff --git a/templates/home/gplayer.html b/templates/home/gplayer.html
index b63cca9..eb238f9 100644
--- a/templates/home/gplayer.html
+++ b/templates/home/gplayer.html
@@ -4,13 +4,28 @@
@@ -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);
});
};
diff --git a/templates/shared/_layout.html b/templates/shared/_layout.html
index a6371b8..91710b4 100644
--- a/templates/shared/_layout.html
+++ b/templates/shared/_layout.html
@@ -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);
diff --git a/views/player.py b/views/player.py
index 3f6616a..845347a 100644
--- a/views/player.py
+++ b/views/player.py
@@ -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 :(")
diff --git a/wiz_game.py b/wiz_game.py
index 2e1f1d0..3d940e2 100644
--- a/wiz_game.py
+++ b/wiz_game.py
@@ -220,6 +220,6 @@ class WizGame:
pass
-p = ["A", "B", "C", "D", "E"]
+p = ["egg", "spam", "ham", "pups", "kekse"]
the_game = WizGame(p)