merge avec chaku

This commit is contained in:
Theouche 2024-09-10 17:23:16 +02:00
parent 4165b6985e
commit 6c68bbba2d
6 changed files with 51 additions and 8 deletions

View File

@ -6,3 +6,4 @@
{"message": "Not Found: /favicon.ico", "taskName": null, "status_code": 404, "request": "<ASGIRequest: GET '/favicon.ico'>"} {"message": "Not Found: /favicon.ico", "taskName": null, "status_code": 404, "request": "<ASGIRequest: GET '/favicon.ico'>"}
{"message": "Not Found: /favicon.ico", "taskName": null, "status_code": 404, "request": "<ASGIRequest: GET '/favicon.ico'>"} {"message": "Not Found: /favicon.ico", "taskName": null, "status_code": 404, "request": "<ASGIRequest: GET '/favicon.ico'>"}
{"message": "Not Found: /favicon.ico", "taskName": null, "status_code": 404, "request": "<ASGIRequest: GET '/favicon.ico'>"} {"message": "Not Found: /favicon.ico", "taskName": null, "status_code": 404, "request": "<ASGIRequest: GET '/favicon.ico'>"}
{"message": "Not Found: /favicon.ico", "taskName": null, "status_code": 404, "request": "<ASGIRequest: GET '/favicon.ico'>"}

View File

@ -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),
),
]

View File

@ -25,7 +25,7 @@ class Player(models.Model):
class Tournoi(models.Model): class Tournoi(models.Model):
name = models.CharField(max_length=200) name = models.CharField(max_length=200)
nbr_player = models.PositiveSmallIntegerField() 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) winner = models.ForeignKey('Player', on_delete=models.SET_NULL, null=True)
def __str__(self): def __str__(self):

View File

@ -6,6 +6,16 @@ from django.template.loader import render_to_string
import random import random
from .matchmaking import match_maker from .matchmaking import match_maker
from .game import Game 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): class TournamentMatch(Game):
def __init__(self, game_id, player1, player2, tournament): def __init__(self, game_id, player1, player2, tournament):
@ -36,6 +46,7 @@ class TournamentMatchMaker:
self.rounds = [] self.rounds = []
self.current_round = 0 self.current_round = 0
self.games = 0 self.games = 0
self.name = random.choice(TOURNAMENT_NAMES)
self.tournament_state = "waiting" # Can be "waiting", "in_progress", or "ended" self.tournament_state = "waiting" # Can be "waiting", "in_progress", or "ended"
async def add_player(self, player): async def add_player(self, player):
@ -76,6 +87,7 @@ class TournamentMatchMaker:
self.tournament_state = "in_progress" self.tournament_state = "in_progress"
random.shuffle(self.waiting_players) random.shuffle(self.waiting_players)
self.current_round = 0 self.current_round = 0
#await sync_to_async(create_tournament)(self.name, len(self.waiting_players))
await self.advance_tournament() await self.advance_tournament()
return True return True

View File

@ -172,3 +172,10 @@ def get_player_p_win(player_name):
player = get_object_or_404(Player, name=player_name) player = get_object_or_404(Player, name=player_name)
return player.p_win return player.p_win
def create_tournament(name, nbr_player):
print("here !!!")
tournoi=Tournoi(name=name, nbr_player=nbr_player, winner=None)
tournoi.save()

View File

@ -349,6 +349,9 @@ document.addEventListener('DOMContentLoaded', () => {
} }
function startTournament() { function startTournament() {
saveData = {
type: 'tournoi'
}
tournamentContainer.style.display = 'flex'; tournamentContainer.style.display = 'flex';
logo.style.display = 'none'; logo.style.display = 'none';
pongElements.style.display = 'none'; pongElements.style.display = 'none';
@ -440,7 +443,7 @@ document.addEventListener('DOMContentLoaded', () => {
function updateGameState(newState) { function updateGameState(newState) {
gameState = newState; gameState = newState;
renderGame(); renderGame();
//checkForWinner(); checkForWinner();
} }
function renderGame() { function renderGame() {
@ -500,12 +503,14 @@ document.addEventListener('DOMContentLoaded', () => {
function checkForWinner() { function checkForWinner() {
if (gameState.player1_score === 3 || gameState.player2_score === 3) { if (gameState.player1_score === 3 || gameState.player2_score === 3) {
gameControls.style.display = 'flex'; if (saveData.type != "tournoi"){
homeButton.style.display = 'block'; gameControls.style.display = 'flex';
replayButton.style.display = 'none'; homeButton.style.display = 'block';
console.log(saveData.type); replayButton.style.display = 'none';
if (saveData.type === 'local'){ console.log(saveData.type);
replayButton.style.display = 'block'; if (saveData.type === 'local'){
replayButton.style.display = 'block';
}
} }
} }
} }