27 lines
815 B
Python
27 lines
815 B
Python
from django.db import models
|
|
|
|
from .objects.GameRoomManager import GameRoomManager
|
|
|
|
from channels.generic.websocket import AsyncWebsocketConsumer
|
|
|
|
# Create your models here.
|
|
class GameModel(models.Model):
|
|
|
|
finished = models.BooleanField(default = False)
|
|
started = models.BooleanField(default = False)
|
|
winner_id = models.IntegerField(default = -1)
|
|
|
|
def create(self, players_id: [int]):
|
|
self.save()
|
|
for player_id in players_id:
|
|
GameMembersModel(game_id = self.pk, player_id = player_id).save()
|
|
return self.pk
|
|
|
|
def get_players_id(self):
|
|
return [game_member.member_id for game_member in GameMembersModel.objects.filter(game_id = self.pk)]
|
|
|
|
class GameMembersModel(models.Model):
|
|
game_id = models.IntegerField()
|
|
player_id = models.IntegerField()
|
|
|
|
game_room_manager: GameRoomManager = GameRoomManager() |