mirror of
https://github.com/AudebertAdrien/ft_transcendence.git
synced 2025-12-16 05:57:48 +01:00
merge avec chaku
This commit is contained in:
parent
4165b6985e
commit
6c68bbba2d
@ -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'>"}
|
||||
|
||||
18
pong/game/migrations/0003_alter_tournoi_date.py
Normal file
18
pong/game/migrations/0003_alter_tournoi_date.py
Normal 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),
|
||||
),
|
||||
]
|
||||
@ -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):
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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()
|
||||
|
||||
|
||||
|
||||
|
||||
@ -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';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user