diff options
author | lonkaars <l.leblansch@gmail.com> | 2021-02-19 20:32:24 +0100 |
---|---|---|
committer | lonkaars <l.leblansch@gmail.com> | 2021-02-19 20:32:24 +0100 |
commit | 0ddd056990d33f335cefc7f0a633e837ce7e116a (patch) | |
tree | b15df5c9ce1d2eb251a0e21cf701ee08cb5a4c2c /api/game/socket.py | |
parent | 1787205f04c9008a753618839bc8da72708f5cab (diff) |
working connect 4 game on website
Diffstat (limited to 'api/game/socket.py')
-rw-r--r-- | api/game/socket.py | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/api/game/socket.py b/api/game/socket.py index 55bff0f..33fbf1b 100644 --- a/api/game/socket.py +++ b/api/game/socket.py @@ -6,28 +6,31 @@ import time import json class game: - def __init__(self, game_id): + def __init__(self, game_id, io): self.game_id = game_id self.board = bord(7, 6) + self.io = io 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 self.board.drop_fisje(column) + self.io.emit("fieldUpdate", { "field": self.board.board }) def run(app): io = SocketIO(app, cors_allowed_origins="*") + games = [game("test_game", io)] namespace = "/game/socket/" @io.on("connect", namespace) def connect(): - print("new connection", namespace) + print("connect") - @io.on("new_move") - def connect(data): - print("new_move") - print(data) + @io.on("newMove") + def new_move(data): + # json_data = json.loads(data) + games[0].move(data["token"], data["move"]) io.run(app, host="127.0.0.1", port=5000, debug=True) |