From f11af8336a70548c1e2cf80726338ed0fc5c52a8 Mon Sep 17 00:00:00 2001 From: starnakin Date: Thu, 28 Dec 2023 12:01:52 +0100 Subject: [PATCH] game: init: class --- games/objects/GameMember.py | 17 +++++++++++++++++ games/objects/GameRoom.py | 9 +++++++++ games/objects/GameRoomManager.py | 18 ++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 games/objects/GameMember.py create mode 100644 games/objects/GameRoom.py create mode 100644 games/objects/GameRoomManager.py diff --git a/games/objects/GameMember.py b/games/objects/GameMember.py new file mode 100644 index 0000000..a2cdcb9 --- /dev/null +++ b/games/objects/GameMember.py @@ -0,0 +1,17 @@ +from channels.generic.websocket import AsyncWebsocketConsumer + +from transcendence.abstract.AbstractRoomMember import AbstractRoomMember + +class GameMember(AbstractRoomMember): + + def __init__(self, user_id: int, socket: AsyncWebsocketConsumer): + super().__init__(user_id, socket) + self.is_a_player = False + + def receive(self, data: dict): + if (not self.is_a_player): + self.send("You are not a player.") + return + + def send_ball(self, ball): + pass \ No newline at end of file diff --git a/games/objects/GameRoom.py b/games/objects/GameRoom.py new file mode 100644 index 0000000..1ee12f8 --- /dev/null +++ b/games/objects/GameRoom.py @@ -0,0 +1,9 @@ +from transcendence.abstract.AbstractRoom import AbstractRoom + +from .GameRoomManager import GameRoomManager + +class GameRoom(AbstractRoom): + + def __init__(self, game_room_manager: GameRoomManager, game_id: int): + super().__init__(game_room_manager) + self.game_id = game_id \ No newline at end of file diff --git a/games/objects/GameRoomManager.py b/games/objects/GameRoomManager.py new file mode 100644 index 0000000..e304541 --- /dev/null +++ b/games/objects/GameRoomManager.py @@ -0,0 +1,18 @@ +from transcendence.abstract.AbstractRoomManager import AbstractRoomManager + +from ..models import GameModel + +class GameRoomManager(AbstractRoomManager): + + def get(self, game_id: int): + + for room in self._room_list: + if (room.game_id == game_id): + return room + + if (GameModel.objects.filter(pk = tournament_id).exists()): + room = TournamentRoom(self, game_id) + self.append(room) + return room + + return None \ No newline at end of file