aboutsummaryrefslogtreecommitdiff
path: root/api/game/socket.py
diff options
context:
space:
mode:
Diffstat (limited to 'api/game/socket.py')
-rw-r--r--api/game/socket.py39
1 files changed, 21 insertions, 18 deletions
diff --git a/api/game/socket.py b/api/game/socket.py
index c4e5ac7..d6dff1b 100644
--- a/api/game/socket.py
+++ b/api/game/socket.py
@@ -1,30 +1,33 @@
from flask import Blueprint, request, make_response
-from flask_socketio import SocketIO, emit, disconnect, Namespace, emit
+from flask_socketio import SocketIO, emit, disconnect, emit
+from game.voerbak_connector import bord
+from db import cursor
import time
import json
-class GameSocketNamespace(Namespace):
- def connect(self):
- print("new connection")
- emit("gert", {"gert": "banaan"})
+namespace = "/game/socket"
- def on_connect(self):
- print("new connection")
- emit("gert", {"gert": "banaan"})
+class game:
+ def __init__(self, game_id):
+ self.game_id = game_id
+ self.board = bord(7, 6)
- def on_disconnect(self):
- print("disconnect")
+ 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)
- def new_move(self, data):
- print("new_move")
+def run(app):
+ io = SocketIO(app)
+
+ @io.on("new_move", namespace)
+ def new_move(data):
print(data)
- def resign(self, data):
- print("resign")
+ @io.on("resign", namespace)
+ def resign(data):
print(data)
-def run(app):
- socketio = SocketIO(app)
- socketio.on_namespace(GameSocketNamespace("/game/socket"))
- socketio.run(app, host="127.0.0.1", port=5000, debug=True)
+ io.run(app, host="127.0.0.1", port=5000, debug=True)