mirror of
https://github.com/AudebertAdrien/ft_transcendence.git
synced 2025-12-16 05:57:48 +01:00
merging with theouche ok
This commit is contained in:
commit
f68c4a65b6
2
.gitignore
vendored
2
.gitignore
vendored
@ -5,4 +5,4 @@ logs/
|
||||
makefile
|
||||
docker-compose.old.yml
|
||||
docker-compose.yml
|
||||
pong/settings.py
|
||||
pong/settings.py
|
||||
|
||||
10
logs/django.log
Normal file
10
logs/django.log
Normal file
@ -0,0 +1,10 @@
|
||||
{"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'>"}
|
||||
{"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'>"}
|
||||
@ -244,12 +244,9 @@ class Game:
|
||||
if not self.localgame:
|
||||
await self.player2.send(end_message)
|
||||
if hasattr(self, 'tournament'):
|
||||
len_tournament = await sync_to_async(getlen)()
|
||||
name_tournament = self.tournament.name + " #" + str(len_tournament + 1)
|
||||
print(f"- Saving match game #{self.game_id} of tournament: {name_tournament}")
|
||||
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, name_tournament)
|
||||
self.bt1, self.bt2, duration, True, self.tournament.tournoi_reg)
|
||||
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'],
|
||||
|
||||
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, update_tournament, getlen
|
||||
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"
|
||||
]
|
||||
|
||||
TOURNAMENT_NAMES = [
|
||||
"Champion's Clash", "Ultimate Showdown", "Battle Royale",
|
||||
@ -39,6 +49,8 @@ class TournamentMatchMaker:
|
||||
self.games = 0
|
||||
self.tournament_state = "waiting" #Can be "waiting", "in_progress", or "ended"
|
||||
self.name = random.choice(TOURNAMENT_NAMES)
|
||||
self.final_name = ""
|
||||
self.tournoi_reg = None
|
||||
|
||||
async def add_player(self, player):
|
||||
if self.tournament_state == "waiting" and player not in self.waiting_players:
|
||||
@ -85,6 +97,9 @@ class TournamentMatchMaker:
|
||||
self.tournament_state = "in_progress"
|
||||
random.shuffle(self.waiting_players)
|
||||
self.current_round = 0
|
||||
len_tournament = await sync_to_async(getlen)()
|
||||
self.final_name = self.name + " #" + str(len_tournament + 1)
|
||||
self.tournoi_reg = await sync_to_async(create_tournament)(self.final_name, len(self.waiting_players))
|
||||
await self.advance_tournament()
|
||||
return True
|
||||
|
||||
@ -191,6 +206,8 @@ class TournamentMatchMaker:
|
||||
'type': 'tournament_end',
|
||||
'winner': winner_username
|
||||
})
|
||||
|
||||
await sync_to_async(update_tournament)(self.final_name, winner_username)
|
||||
# Reset tournament state
|
||||
self.waiting_players = []
|
||||
self.matches = []
|
||||
|
||||
@ -172,5 +172,25 @@ 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("tournoi created!!!")
|
||||
tournoi=Tournoi(name=name, nbr_player=nbr_player, winner=None)
|
||||
tournoi.save()
|
||||
print(f"tournoi name : {tournoi.name} *******!*!*!*!**!*!**!*!*!*!*!*!*!*!*!*")
|
||||
return tournoi
|
||||
|
||||
def update_tournament(name_tournoi, winner_name):
|
||||
tournoi = get_object_or_404(Tournoi, name=name_tournoi)
|
||||
winner_p = get_object_or_404(Player, name=winner_name)
|
||||
print(f"in update tourna - tournoi name : {tournoi.name} *******!*!*!*!**!*!**!*!*!*!*!*!*!*!*!*")
|
||||
print(f"in update tourna - winner is : {winner_p.name} *******!*!*!*!**!*!**!*!*!*!*!*!*!*!*!*")
|
||||
|
||||
tournoi.winner = winner_p
|
||||
print(f"in update tourna - TOURNOI winner is : {tournoi.winner.name} *******!*!*!*!**!*!**!*!*!*!*!*!*!*!*!*")
|
||||
tournoi.save()
|
||||
|
||||
|
||||
|
||||
|
||||
def getlen():
|
||||
return Tournoi.objects.count()
|
||||
|
||||
@ -103,10 +103,10 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
console.log('Displaying matches:');
|
||||
const matchListBody = document.querySelector('#match-list tbody');
|
||||
matchListBody.innerHTML = '';
|
||||
const row = document.createElement('tr');
|
||||
|
||||
if (matches.length != 0) {
|
||||
matches.forEach(match => {
|
||||
const row = document.createElement('tr');
|
||||
row.innerHTML = `
|
||||
<td>${match.id}</td>
|
||||
<td>${match.player1__name}</td>
|
||||
@ -135,10 +135,10 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
console.log('Displaying players:');
|
||||
const playersListBody = document.querySelector('#player-list tbody');
|
||||
playersListBody.innerHTML = '';
|
||||
const row = document.createElement('tr');
|
||||
|
||||
if (players.length != 0) {
|
||||
players.forEach(player => {
|
||||
const row = document.createElement('tr');
|
||||
row.innerHTML = `
|
||||
<td>${player.id}</td>
|
||||
<td>${player.name}</td>
|
||||
@ -168,16 +168,16 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
console.log('Displaying tournois:');
|
||||
const tournoisListBody = document.querySelector('#tournoi-list tbody');
|
||||
tournoisListBody.innerHTML = '';
|
||||
const row = document.createElement('tr');
|
||||
|
||||
if (tournois.length != 0) {
|
||||
tournois.forEach(tournoi => {
|
||||
const row = document.createElement('tr');
|
||||
row.innerHTML = `
|
||||
<td>${tournoi.id}</td>
|
||||
<td>${tournoi.name}</td>
|
||||
<td>${tournoi.nbr_player}</td>
|
||||
<td>${tournoi.date}</td>
|
||||
<td>${tournoi.winner.name}</td>
|
||||
<td>${tournoi.winner ? tournoi.winner.name : 'None'}</td>
|
||||
`;
|
||||
tournoisListBody.appendChild(row);
|
||||
});
|
||||
|
||||
@ -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