2023-12-12 06:06:13 -05:00
|
|
|
from django.db import models
|
|
|
|
|
2023-12-28 06:02:39 -05:00
|
|
|
from .objects.GameRoomManager import GameRoomManager
|
|
|
|
|
|
|
|
from channels.generic.websocket import AsyncWebsocketConsumer
|
|
|
|
|
2023-12-12 06:06:13 -05:00
|
|
|
# Create your models here.
|
|
|
|
class GameModel(models.Model):
|
2023-12-20 13:11:56 -05:00
|
|
|
|
2023-12-26 15:35:08 -05:00
|
|
|
finished = models.BooleanField(default = False)
|
|
|
|
started = models.BooleanField(default = False)
|
|
|
|
winner_id = models.IntegerField(default = -1)
|
2023-12-12 06:06:13 -05:00
|
|
|
|
2023-12-26 15:32:20 -05:00
|
|
|
def create(self, players_id: [int]):
|
2023-12-12 06:06:13 -05:00
|
|
|
self.save()
|
2023-12-26 15:32:20 -05:00
|
|
|
for player_id in players_id:
|
|
|
|
GameMembersModel(game_id = self.pk, player_id = player_id).save()
|
2023-12-12 06:06:13 -05:00
|
|
|
return self.pk
|
2023-12-20 13:11:56 -05:00
|
|
|
|
2023-12-26 15:32:20 -05:00
|
|
|
def get_players_id(self):
|
2023-12-26 15:35:08 -05:00
|
|
|
return [game_member.member_id for game_member in GameMembersModel.objects.filter(game_id = self.pk)]
|
2023-12-12 06:06:13 -05:00
|
|
|
|
|
|
|
class GameMembersModel(models.Model):
|
|
|
|
game_id = models.IntegerField()
|
2023-12-28 06:02:39 -05:00
|
|
|
player_id = models.IntegerField()
|
|
|
|
|
|
|
|
game_room_manager: GameRoomManager = GameRoomManager()
|