From 6c68bbba2d07bf717c9176af0c41c64cd1897d36 Mon Sep 17 00:00:00 2001 From: Theouche Date: Tue, 10 Sep 2024 17:23:16 +0200 Subject: [PATCH] merge avec chaku --- logs/django.log | 1 + .../migrations/0003_alter_tournoi_date.py | 18 ++++++++++++++++++ pong/game/models.py | 2 +- pong/game/tournament.py | 12 ++++++++++++ pong/game/utils.py | 7 +++++++ pong/static/game.js | 19 ++++++++++++------- 6 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 pong/game/migrations/0003_alter_tournoi_date.py diff --git a/logs/django.log b/logs/django.log index 39a3693..444904d 100644 --- a/logs/django.log +++ b/logs/django.log @@ -6,3 +6,4 @@ {"message": "Not Found: /favicon.ico", "taskName": null, "status_code": 404, "request": ""} {"message": "Not Found: /favicon.ico", "taskName": null, "status_code": 404, "request": ""} {"message": "Not Found: /favicon.ico", "taskName": null, "status_code": 404, "request": ""} +{"message": "Not Found: /favicon.ico", "taskName": null, "status_code": 404, "request": ""} diff --git a/pong/game/migrations/0003_alter_tournoi_date.py b/pong/game/migrations/0003_alter_tournoi_date.py new file mode 100644 index 0000000..6bfda6c --- /dev/null +++ b/pong/game/migrations/0003_alter_tournoi_date.py @@ -0,0 +1,18 @@ +# Generated by Django 5.1.1 on 2024-09-10 14:17 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('game', '0002_alter_match_winner'), + ] + + operations = [ + migrations.AlterField( + model_name='tournoi', + name='date', + field=models.DateField(auto_now_add=True), + ), + ] diff --git a/pong/game/models.py b/pong/game/models.py index d72178f..4f63102 100644 --- a/pong/game/models.py +++ b/pong/game/models.py @@ -25,7 +25,7 @@ class Player(models.Model): class Tournoi(models.Model): name = models.CharField(max_length=200) nbr_player = models.PositiveSmallIntegerField() - date = models.DateField() + date = models.DateField(auto_now_add=True) winner = models.ForeignKey('Player', on_delete=models.SET_NULL, null=True) def __str__(self): diff --git a/pong/game/tournament.py b/pong/game/tournament.py index 4c45336..7a581e2 100644 --- a/pong/game/tournament.py +++ b/pong/game/tournament.py @@ -6,6 +6,16 @@ from django.template.loader import render_to_string import random from .matchmaking import match_maker from .game import Game +from .models import Tournoi +from .utils import create_tournament +from asgiref.sync import sync_to_async + + +TOURNAMENT_NAMES = [ + "Champions Clash", "Ultimate Showdown", "Battle Royale", + "Victory Cup", "Legends Tournament", "Elite Series", "Clash of 42", + "Shibuya incident", "Cunning Game", "Elite of the Stars" +] class TournamentMatch(Game): def __init__(self, game_id, player1, player2, tournament): @@ -36,6 +46,7 @@ class TournamentMatchMaker: self.rounds = [] self.current_round = 0 self.games = 0 + self.name = random.choice(TOURNAMENT_NAMES) self.tournament_state = "waiting" # Can be "waiting", "in_progress", or "ended" async def add_player(self, player): @@ -76,6 +87,7 @@ class TournamentMatchMaker: self.tournament_state = "in_progress" random.shuffle(self.waiting_players) self.current_round = 0 + #await sync_to_async(create_tournament)(self.name, len(self.waiting_players)) await self.advance_tournament() return True diff --git a/pong/game/utils.py b/pong/game/utils.py index d30ae3f..c911138 100644 --- a/pong/game/utils.py +++ b/pong/game/utils.py @@ -172,3 +172,10 @@ def get_player_p_win(player_name): player = get_object_or_404(Player, name=player_name) return player.p_win +def create_tournament(name, nbr_player): + print("here !!!") + tournoi=Tournoi(name=name, nbr_player=nbr_player, winner=None) + tournoi.save() + + + diff --git a/pong/static/game.js b/pong/static/game.js index 1b5a53c..8dcc898 100644 --- a/pong/static/game.js +++ b/pong/static/game.js @@ -349,6 +349,9 @@ document.addEventListener('DOMContentLoaded', () => { } function startTournament() { + saveData = { + type: 'tournoi' + } tournamentContainer.style.display = 'flex'; logo.style.display = 'none'; pongElements.style.display = 'none'; @@ -440,7 +443,7 @@ document.addEventListener('DOMContentLoaded', () => { function updateGameState(newState) { gameState = newState; renderGame(); - //checkForWinner(); + checkForWinner(); } function renderGame() { @@ -500,12 +503,14 @@ document.addEventListener('DOMContentLoaded', () => { function checkForWinner() { if (gameState.player1_score === 3 || gameState.player2_score === 3) { - gameControls.style.display = 'flex'; - homeButton.style.display = 'block'; - replayButton.style.display = 'none'; - console.log(saveData.type); - if (saveData.type === 'local'){ - replayButton.style.display = 'block'; + if (saveData.type != "tournoi"){ + gameControls.style.display = 'flex'; + homeButton.style.display = 'block'; + replayButton.style.display = 'none'; + console.log(saveData.type); + if (saveData.type === 'local'){ + replayButton.style.display = 'block'; + } } } }