mirror of
https://github.com/AudebertAdrien/ft_transcendence.git
synced 2025-12-16 14:07:49 +01:00
handle tournament end game's
This commit is contained in:
parent
8ad33f8acb
commit
c6cb11d2f8
@ -4,8 +4,9 @@ import json
|
||||
import asyncio
|
||||
import random
|
||||
from datetime import datetime
|
||||
from .utils import handle_game_data
|
||||
from .utils import handle_game_data, getlen
|
||||
from asgiref.sync import sync_to_async
|
||||
from .models import Tournoi
|
||||
|
||||
class Game:
|
||||
def __init__(self, game_id, player1, player2, localgame):
|
||||
@ -242,6 +243,12 @@ class Game:
|
||||
if not self.botgame:
|
||||
if not self.localgame:
|
||||
await self.player2.send(end_message)
|
||||
if hasattr(self, 'tournament'):
|
||||
len_tournament = await sync_to_async(getlen)()
|
||||
await sync_to_async(handle_game_data)(self.game_state['player1_name'], self.game_state['player2_name'],
|
||||
self.game_state['player1_score'], self.game_state['player2_score'],
|
||||
self.bt1, self.bt2, duration, True, self.tournament.name + " #" + str(len_tournament + 1))
|
||||
else:
|
||||
await sync_to_async(handle_game_data)(self.game_state['player1_name'], self.game_state['player2_name'],
|
||||
self.game_state['player1_score'], self.game_state['player2_score'],
|
||||
self.bt1, self.bt2, duration, False, None)
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
jik<!-- pong/tournament_waiting_room.html -->
|
||||
<!-- pong/tournament_waiting_room.html -->
|
||||
<div class="tournament-waiting-room">
|
||||
<h2>Tournament Waiting Room</h2>
|
||||
|
||||
|
||||
@ -7,6 +7,12 @@ import random
|
||||
from .matchmaking import match_maker
|
||||
from .game import Game
|
||||
|
||||
TOURNAMENT_NAMES = [
|
||||
"Champion's Clash", "Ultimate Showdown", "Battle Royale",
|
||||
"Victory's Cup", "Legends Tournament", "Elite Series", "Clash of 42",
|
||||
"Shibuya Incident", "Cunning Game", "Elite of the Stars", "Chaku's Disciples"
|
||||
]
|
||||
|
||||
class TournamentMatch(Game):
|
||||
def __init__(self, game_id, player1, player2, tournament):
|
||||
# Initialize the parent Game class with the provided parameters
|
||||
@ -32,6 +38,7 @@ class TournamentMatchMaker:
|
||||
self.current_round = 0
|
||||
self.games = 0
|
||||
self.tournament_state = "waiting" #Can be "waiting", "in_progress", or "ended"
|
||||
self.name = random.choice(TOURNAMENT_NAMES)
|
||||
|
||||
async def add_player(self, player):
|
||||
if self.tournament_state == "waiting" and player not in self.waiting_players:
|
||||
@ -70,6 +77,7 @@ class TournamentMatchMaker:
|
||||
|
||||
# Tournament start method
|
||||
async def start_tournament(self):
|
||||
|
||||
if len(self.waiting_players) < 2:
|
||||
return False
|
||||
if len(self.waiting_players) % 2 == 0:
|
||||
|
||||
@ -172,3 +172,5 @@ def get_player_p_win(player_name):
|
||||
player = get_object_or_404(Player, name=player_name)
|
||||
return player.p_win
|
||||
|
||||
def getlen():
|
||||
return Tournoi.objects.count()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user