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