game: add: online

This commit is contained in:
2024-04-08 20:18:25 +02:00
parent bceb26790d
commit 9f5ca1430d
5 changed files with 202 additions and 117 deletions

View File

@ -33,11 +33,23 @@ class TicTacToeWebSocket(WebsocketConsumer):
self.game_id = int(self.scope['url_route']['kwargs']['game_id'])
self.game: PongGame = game_manager.get(self.game_id, "pong")
self.game: TicTacToeGame = game_manager.get(self.game_id, "tictactoe")
self.member = self.game.join(self.user.pk, self)
self.member.send("x" if self.game._everbody_is_here() else "o")
if (self.game._everbody_is_here()):
self.game.broadcast("game_start")
def receive(self, text_data=None, bytes_data=None):
print(text_data)
self.game.broadcast("", json.loads(text_data), [self.member])
pass
def disconnect(self, event):
self.member.socket = None
class PongWebSocket(WebsocketConsumer):
def __init__(self, *args, **kwargs):