core: game: split backed django
This commit is contained in:
@ -1,28 +1,33 @@
|
||||
from ..models import GameModel
|
||||
|
||||
from .Game import Game
|
||||
from .pong.PongGame import PongGame
|
||||
from .tictactoe.TicTacToeGame import TicTacToeGame
|
||||
|
||||
class GameManager():
|
||||
|
||||
def __init__(self) -> None:
|
||||
self._game_list: list[Game] = []
|
||||
self._game_list: list[PongGame | TicTacToeGame] = []
|
||||
|
||||
def remove(self, game: Game):
|
||||
def remove(self, game: PongGame | TicTacToeGame) -> None:
|
||||
if (game not in self._game_list):
|
||||
return
|
||||
self._game_list.remove(game)
|
||||
|
||||
def get(self, game_id: int) -> Game:
|
||||
def get(self, game_id: int, game_type: str) -> TicTacToeGame | PongGame:
|
||||
|
||||
if (not GameModel.objects.filter(pk = game_id, finished = False).exists()):
|
||||
if (not GameModel.objects.filter(pk=game_id, finished=False, game_type=game_type).exists()):
|
||||
return None
|
||||
|
||||
for game in self._game_list:
|
||||
game: Game
|
||||
game: PongGame | TicTacToeGame
|
||||
if (game.game_id == game_id):
|
||||
return game
|
||||
|
||||
game: Game = Game(game_id, self)
|
||||
|
||||
game: PongGame | TicTacToeGame
|
||||
if (game_type == "pong"):
|
||||
game = PongGame(game_id, self)
|
||||
elif (game_type == "tictactoe"):
|
||||
game = PongGame(game_id, self)
|
||||
|
||||
self._game_list.append(game)
|
||||
|
||||
|
Reference in New Issue
Block a user