pixi integration is improving
This commit is contained in:
parent
c194164e3c
commit
965b7a5ad7
@ -27,6 +27,7 @@
|
||||
let t = JSON.stringify(msg);
|
||||
window.game_socket.send(t);
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<div style="font-family:Wizzta; font-size:100px"></div>
|
||||
@ -37,12 +38,12 @@
|
||||
<script src="/js-cardgame/js/player.js"></script>
|
||||
<script src="/js-cardgame/js/game.js"></script>
|
||||
|
||||
<script>
|
||||
|
||||
let game = null;
|
||||
<script>
|
||||
//let game = null;
|
||||
//window.game = null;
|
||||
|
||||
//window.onload = function()
|
||||
function setupGame(names)
|
||||
function setupGame(names, hand)
|
||||
{
|
||||
|
||||
PIXI.AbstractRenderer.autoDensity = true;
|
||||
@ -91,7 +92,8 @@ function setupGame(names)
|
||||
game = new Game(app.stage, resources);
|
||||
//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.give_round(hand)
|
||||
//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");
|
||||
|
@ -22,6 +22,7 @@
|
||||
<script src="//oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
|
||||
<![endif]-->
|
||||
<script>
|
||||
window.the_game = null
|
||||
// let socket = new WebSocket("wss://cowiz.struppi.name/ws");
|
||||
if (window.location.hostname == '127.0.0.1') {
|
||||
ws_schema = 'ws://';
|
||||
@ -36,9 +37,13 @@
|
||||
//alert("[open] Connection established");
|
||||
//alert("Sending to server");
|
||||
//socket.send("My name is John");
|
||||
let player = "{{player}}"
|
||||
var msg = {
|
||||
//type: "message",
|
||||
//fct: "requestInit",
|
||||
type: "message",
|
||||
fct: "requestInit",
|
||||
fct: "getHand",
|
||||
player: player,
|
||||
};
|
||||
let t = JSON.stringify(msg);
|
||||
window.game_socket.send(t);
|
||||
@ -50,10 +55,19 @@
|
||||
if (fct == "reload") {
|
||||
location.reload(true);
|
||||
}
|
||||
else if (fct == "getHand") {
|
||||
window.hand = msg.cards;
|
||||
var msg_out = {
|
||||
type: "message",
|
||||
fct: "requestInit",
|
||||
};
|
||||
let t = JSON.stringify(msg_out);
|
||||
window.game_socket.send(t);
|
||||
}
|
||||
else if (fct == "startGame") {
|
||||
let names = msg.names
|
||||
setupGame(names)
|
||||
alert('game is set up')
|
||||
setupGame(names, window.hand)
|
||||
//alert('game is set up')
|
||||
}
|
||||
else {
|
||||
alert('unknown command: '+event.data);
|
||||
|
@ -80,10 +80,18 @@ async def initGame(ws):
|
||||
await ws.send_json(msg)
|
||||
|
||||
|
||||
@api.route('/ws', websocket=True)
|
||||
async def websocket(ws):
|
||||
async def getHand(player, ws):
|
||||
p = int(player)
|
||||
c = the_game.players[p].cards
|
||||
s = [x.json_serialise() for x in c]
|
||||
msg = {"type": "message", "fct": "getHand", "cards": s}
|
||||
await ws.send_json(msg)
|
||||
|
||||
|
||||
async def ws_handler(ws):
|
||||
await ws.accept()
|
||||
the_game.websockets.append(ws)
|
||||
while True:
|
||||
try:
|
||||
x = await ws.receive_json()
|
||||
fct = x['fct']
|
||||
@ -96,12 +104,20 @@ async def websocket(ws):
|
||||
color = x['color']
|
||||
await set_trump_color(player, color)
|
||||
elif fct == "requestInit":
|
||||
print("before init")
|
||||
await initGame(ws);
|
||||
print("after init")
|
||||
elif fct == "getHand":
|
||||
player = x['player']
|
||||
await getHand(player, ws)
|
||||
else:
|
||||
print("confused :(")
|
||||
|
||||
except WebSocketDisconnect:
|
||||
the_game.websockets.remove(ws)
|
||||
break;
|
||||
|
||||
|
||||
@api.route('/ws', websocket=True)
|
||||
async def websocket(ws):
|
||||
task = asyncio.create_task(ws_handler(ws))
|
||||
the_game.ws_tasks.append(task)
|
||||
await task;
|
||||
|
||||
|
21
wiz_game.py
21
wiz_game.py
@ -9,9 +9,10 @@ def chunks(lst, n):
|
||||
|
||||
|
||||
class Card:
|
||||
def __init__(self, color, value):
|
||||
def __init__(self, color, value, idx=None):
|
||||
self.color = color
|
||||
self.value = value
|
||||
self.idx = idx
|
||||
|
||||
def __str__(self):
|
||||
sc = self.color if self.color else ' '
|
||||
@ -21,6 +22,13 @@ class Card:
|
||||
def __repr__(self):
|
||||
return str(self)
|
||||
|
||||
def json_serialise(self):
|
||||
if self.color and self.color != '-':
|
||||
s = "{}{:02d}".format(self.color, self.value)
|
||||
else:
|
||||
s = "{}{}".format(self.value, self.idx)
|
||||
return s
|
||||
|
||||
|
||||
def get_higher_card(card1: Card, card2: Card, trump_color: str):
|
||||
"""
|
||||
@ -92,6 +100,7 @@ class WizGame:
|
||||
self.players_ordered = self.players
|
||||
self.last_trick = None
|
||||
self.websockets = []
|
||||
self.ws_tasks = []
|
||||
|
||||
def start_game(self):
|
||||
self.create_deck()
|
||||
@ -109,10 +118,10 @@ class WizGame:
|
||||
for color in ["b", "r", "g", "y"]:
|
||||
for val in range(1, 14):
|
||||
self.card_deck.append(Card(color, val))
|
||||
for _ in range(1, 5):
|
||||
self.card_deck.append(Card('-', 'Z'))
|
||||
for _ in range(1, 5):
|
||||
self.card_deck.append(Card('-', 'N'))
|
||||
for idx in range(1, 5):
|
||||
self.card_deck.append(Card('-', 'Z', idx))
|
||||
for idx in range(1, 5):
|
||||
self.card_deck.append(Card('-', 'N', idx))
|
||||
|
||||
def get_trump_color(self):
|
||||
card = self.trump_card
|
||||
@ -220,6 +229,6 @@ class WizGame:
|
||||
pass
|
||||
|
||||
|
||||
p = ["egg", "spam", "ham", "pups", "kekse"]
|
||||
p = ["spam", "egg", "ham", "tomato"]
|
||||
the_game = WizGame(p)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user