This commit is contained in:
starnakin 2023-12-26 21:35:08 +01:00
parent 98ec43e7b9
commit 35a2f273f9
2 changed files with 11 additions and 11 deletions

View File

@ -3,9 +3,9 @@ from django.db import models
# Create your models here. # Create your models here.
class GameModel(models.Model): class GameModel(models.Model):
finished = models.BooleanField(default=False) finished = models.BooleanField(default = False)
started = models.BooleanField(default=False) started = models.BooleanField(default = False)
winner_id = models.IntegerField(default=-1) winner_id = models.IntegerField(default = -1)
def create(self, players_id: [int]): def create(self, players_id: [int]):
self.save() self.save()
@ -14,7 +14,7 @@ class GameModel(models.Model):
return self.pk return self.pk
def get_players_id(self): def get_players_id(self):
return [game_member.member_id for game_member in GameMembersModel.objects.filter(self.pk)] return [game_member.member_id for game_member in GameMembersModel.objects.filter(game_id = self.pk)]
class GameMembersModel(models.Model): class GameMembersModel(models.Model):
game_id = models.IntegerField() game_id = models.IntegerField()

View File

@ -13,12 +13,12 @@ from transcendence.abstract.AbstractRoomManager import AbstractRoomManager
# Create your models here.tu # Create your models here.tu
class TournamentModel(models.Model): class TournamentModel(models.Model):
name = models.CharField(max_length=100) name = models.CharField(max_length = 100)
nb_players = models.IntegerField() nb_players = models.IntegerField()
nb_players_by_game = models.IntegerField() nb_players_by_game = models.IntegerField()
level = models.IntegerField() level = models.IntegerField()
started = models.BooleanField(default=False) started = models.BooleanField(default = False)
finished = models.BooleanField(default=False) finished = models.BooleanField(default = False)
def create_game(self, level, players_id): def create_game(self, level, players_id):
game_id = GameModel().create(players_id = players_id) game_id = GameModel().create(players_id = players_id)
@ -36,11 +36,11 @@ class TournamentModel(models.Model):
return [model.participant_id for model in TournamentParticipantsModel.objects.filter(tournament_id=self.pk)] return [model.participant_id for model in TournamentParticipantsModel.objects.filter(tournament_id=self.pk)]
def is_a_participant(self, participant_id: int): def is_a_participant(self, participant_id: int):
return TournamentParticipantsModel.objects.filter(participant_id=participant_id, tournament_id=self.pk).exists() return TournamentParticipantsModel.objects.filter(participant_id = participant_id, tournament_id = self.pk).exists()
def add_participants(self, participants_id: [int]): def add_participants(self, participants_id: [int]):
for participant_id in participants_id: for participant_id in participants_id:
TournamentParticipantsModel(tournament_id=self.pk, participant_id=participant_id).save() TournamentParticipantsModel(tournament_id = self.pk, participant_id = participant_id).save()
def start(self, participants_id: [int]): def start(self, participants_id: [int]):
self.started = True self.started = True
@ -93,7 +93,7 @@ class TournamentRoom(AbstractRoom):
def __init__(self, room_manager, tournament_id: int): def __init__(self, room_manager, tournament_id: int):
super().__init__(room_manager) super().__init__(room_manager)
self.tournament_id = tournament_id self.tournament_id = tournament_id
self.tournament = TournamentModel.objects.get(pk=tournament_id) self.tournament = TournamentModel.objects.get(pk = tournament_id)
def start(self): def start(self):
self.broadcast("tournament_start") self.broadcast("tournament_start")
@ -144,7 +144,7 @@ class TournamentRoomManager(AbstractRoomManager):
if (room.tournament_id == tournament_id): if (room.tournament_id == tournament_id):
return room return room
if (TournamentModel.objects.filter(pk = tournament_id, finished=False).exists()): if (TournamentModel.objects.filter(pk = tournament_id).exists()):
room = TournamentRoom(self, tournament_id) room = TournamentRoom(self, tournament_id)
self.append(room) self.append(room)
return room return room