aboutsummaryrefslogtreecommitdiff
path: root/api/game/socket.py
diff options
context:
space:
mode:
authorlonkaars <l.leblansch@gmail.com>2021-02-21 10:18:21 +0100
committerlonkaars <l.leblansch@gmail.com>2021-02-21 10:18:21 +0100
commitff83a204a27a5c37a5061857f2bc67a3d7f05d46 (patch)
treee8abcabe0e67837b5aae1bf33d2a1bc97948dfaf /api/game/socket.py
parent96f56b2154195191132fb43c5b27f0a7c2ce1bb6 (diff)
working game on two screens
Diffstat (limited to 'api/game/socket.py')
-rw-r--r--api/game/socket.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/api/game/socket.py b/api/game/socket.py
index 76629f0..3828c35 100644
--- a/api/game/socket.py
+++ b/api/game/socket.py
@@ -10,15 +10,17 @@ from socket_io import io
games = {}
class game:
- def __init__(self, game_id, io):
+ def __init__(self, game_id, io, player_1_id, player_2_id):
self.game_id = game_id
self.board = bord(7, 6)
self.io = io
+ self.player_1_id = player_1_id
+ self.player_2_id = player_2_id
def move(self, user_id, column):
- # player_1 = cursor.execute("select player_1_id from games where game_id = ?", [self.game_id]).fetchone()[0]
- # player_1_move = player_1 == user_id
- # if not self.board.player_1 == player_1_move: return
+ if user_id != self.player_1_id and user_id != self.player_2_id: return
+ move = self.player_1_id if self.board.player_1 else self.player_2_id
+ if user_id != move: return
self.board.drop_fisje(column)
self.io.emit("fieldUpdate", { "field": self.board.board })
self.io.emit("turnUpdate", { "player1": self.board.player_1 })
@@ -30,9 +32,10 @@ class game:
@io.on("newMove")
def new_move(data):
- print("socket.py")
- print(games)
- print(data)
+ if not data["game_id"] or \
+ not data["move"] or \
+ not data["token"]: return
+ if not data["game_id"] in games: return
game = games[data["game_id"]]
if(len(game.board.win_positions) > 0 or game.board.board_full): return
user_id = token_login(data["token"])[0]