mirror of
https://github.com/AudebertAdrien/ft_transcendence.git
synced 2025-12-16 14:07:49 +01:00
It worked git add .git add .!
This commit is contained in:
parent
9fe4e51c53
commit
8ed7cf6419
@ -89,6 +89,7 @@ class Game:
|
|||||||
#await self.bot_player.update_bot_position()
|
#await self.bot_player.update_bot_position()
|
||||||
await self.update_bot_position()
|
await self.update_bot_position()
|
||||||
#print('is it ok ?? ')
|
#print('is it ok ?? ')
|
||||||
|
await self.handle_pad_movement()
|
||||||
self.update_game_state()
|
self.update_game_state()
|
||||||
await self.send_game_state()
|
await self.send_game_state()
|
||||||
await asyncio.sleep(1/60) # Around 60 FPS
|
await asyncio.sleep(1/60) # Around 60 FPS
|
||||||
@ -165,6 +166,7 @@ class Game:
|
|||||||
if self.ended:
|
if self.ended:
|
||||||
return
|
return
|
||||||
if player == self.player1:
|
if player == self.player1:
|
||||||
|
print(f"Key press: {key}")
|
||||||
if key == 'arrowup':
|
if key == 'arrowup':
|
||||||
self.p1_mov = -1
|
self.p1_mov = -1
|
||||||
#self.game_state['player1_position'] = max(self.game_state['player1_position'] - 25, 0)
|
#self.game_state['player1_position'] = max(self.game_state['player1_position'] - 25, 0)
|
||||||
|
|||||||
@ -40,7 +40,7 @@ class MatchMaker:
|
|||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
self.timer += 1
|
self.timer += 1
|
||||||
# Waiting for more than 30s -> BOT game
|
# Waiting for more than 30s -> BOT game
|
||||||
if self.timer >= 30 and self.waiting_players:
|
if self.timer >= 3 and self.waiting_players:
|
||||||
player1 = self.waiting_players.pop(0)
|
player1 = self.waiting_players.pop(0)
|
||||||
print(f"*** MATCH FOUND: {player1.user.username} vs BOT")
|
print(f"*** MATCH FOUND: {player1.user.username} vs BOT")
|
||||||
self.botgame = True
|
self.botgame = True
|
||||||
@ -98,3 +98,6 @@ class MatchMaker:
|
|||||||
|
|
||||||
# Instance of the class
|
# Instance of the class
|
||||||
match_maker = MatchMaker()
|
match_maker = MatchMaker()
|
||||||
|
|
||||||
|
# to get what you want use get_player_p_win(player_name) !! (voir utils.py)
|
||||||
|
#
|
||||||
@ -1,4 +1,4 @@
|
|||||||
# Generated by Django 5.0.7 on 2024-07-31 13:42
|
# Generated by Django 5.0.7 on 2024-07-31 15:16
|
||||||
|
|
||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
@ -24,7 +24,7 @@ class Migration(migrations.Migration):
|
|||||||
('m_score_adv_match', models.DecimalField(blank=True, decimal_places=2, max_digits=5, null=True)),
|
('m_score_adv_match', models.DecimalField(blank=True, decimal_places=2, max_digits=5, null=True)),
|
||||||
('best_score', models.PositiveSmallIntegerField(default=0)),
|
('best_score', models.PositiveSmallIntegerField(default=0)),
|
||||||
('m_nbr_ball_touch', models.DecimalField(blank=True, decimal_places=2, max_digits=5, null=True)),
|
('m_nbr_ball_touch', models.DecimalField(blank=True, decimal_places=2, max_digits=5, null=True)),
|
||||||
('total_duration', models.DurationField(blank=True, null=True)),
|
('total_duration', models.DecimalField(blank=True, decimal_places=2, max_digits=7, null=True)),
|
||||||
('m_duration', models.DecimalField(blank=True, decimal_places=2, max_digits=5, null=True)),
|
('m_duration', models.DecimalField(blank=True, decimal_places=2, max_digits=5, null=True)),
|
||||||
('num_participated_tournaments', models.PositiveSmallIntegerField(default=0)),
|
('num_participated_tournaments', models.PositiveSmallIntegerField(default=0)),
|
||||||
('num_won_tournaments', models.PositiveSmallIntegerField(default=0)),
|
('num_won_tournaments', models.PositiveSmallIntegerField(default=0)),
|
||||||
|
|||||||
@ -15,7 +15,7 @@ class Player(models.Model):
|
|||||||
m_score_adv_match = models.DecimalField(max_digits=5, decimal_places=2, null=True, blank=True)
|
m_score_adv_match = models.DecimalField(max_digits=5, decimal_places=2, null=True, blank=True)
|
||||||
best_score = models.PositiveSmallIntegerField(default=0)
|
best_score = models.PositiveSmallIntegerField(default=0)
|
||||||
m_nbr_ball_touch = models.DecimalField(max_digits=5, decimal_places=2, null=True, blank=True)
|
m_nbr_ball_touch = models.DecimalField(max_digits=5, decimal_places=2, null=True, blank=True)
|
||||||
total_duration = models.DurationField(null=True, blank=True)
|
total_duration = models.DecimalField(max_digits=7, decimal_places=2, null=True, blank=True)
|
||||||
m_duration = models.DecimalField(max_digits=5, decimal_places=2, null=True, blank=True)
|
m_duration = models.DecimalField(max_digits=5, decimal_places=2, null=True, blank=True)
|
||||||
num_participated_tournaments = models.PositiveSmallIntegerField(default=0)
|
num_participated_tournaments = models.PositiveSmallIntegerField(default=0)
|
||||||
num_won_tournaments = models.PositiveSmallIntegerField(default=0)
|
num_won_tournaments = models.PositiveSmallIntegerField(default=0)
|
||||||
|
|||||||
@ -9,20 +9,26 @@ async def endfortheouche(p1, p2, s_p1, s_p2, bt_p1, bt_2, dur, is_tournoi, name_
|
|||||||
# Check if player p1 exists, if not create
|
# Check if player p1 exists, if not create
|
||||||
if not await database_sync_to_async(Player.objects.filter(name=p1).exists)():
|
if not await database_sync_to_async(Player.objects.filter(name=p1).exists)():
|
||||||
player_1 = await create_player(p1)
|
player_1 = await create_player(p1)
|
||||||
|
print("############# PLAYER DONE")
|
||||||
else:
|
else:
|
||||||
player_1 = await database_sync_to_async(Player.objects.get)(name=p1)
|
player_1 = await database_sync_to_async(Player.objects.get)(name=p1)
|
||||||
|
|
||||||
# Check if player p2 exists, if not create
|
# Check if player p2 exists, if not create
|
||||||
if not await database_sync_to_async(Player.objects.filter(name=p2).exists)():
|
if not await database_sync_to_async(Player.objects.filter(name=p2).exists)():
|
||||||
player_2 = await create_player(p2)
|
player_2 = await create_player(p2)
|
||||||
|
print("############# PLAYER DONE")
|
||||||
else:
|
else:
|
||||||
player_2 = await database_sync_to_async(Player.objects.get)(name=p2)
|
player_2 = await database_sync_to_async(Player.objects.get)(name=p2)
|
||||||
|
|
||||||
# create Match
|
# create Match
|
||||||
|
print("############# BEFORE MATCH")
|
||||||
await create_match(player_1, player_2, s_p1, s_p2, bt_p1, bt_2, dur, is_tournoi, name_tournament)
|
await create_match(player_1, player_2, s_p1, s_p2, bt_p1, bt_2, dur, is_tournoi, name_tournament)
|
||||||
|
print("############# AFTER DONE")
|
||||||
|
|
||||||
# Update data p1 et p2
|
# Update data p1 et p2
|
||||||
|
|
||||||
await uptdate_player_statistics(p1)
|
await uptdate_player_statistics(p1)
|
||||||
|
print("############# END STAT P1")
|
||||||
await uptdate_player_statistics(p2)
|
await uptdate_player_statistics(p2)
|
||||||
|
|
||||||
@database_sync_to_async
|
@database_sync_to_async
|
||||||
@ -92,11 +98,14 @@ def create_match(player1, player2, score_player1, score_player2, nbr_ball_touch_
|
|||||||
|
|
||||||
@database_sync_to_async
|
@database_sync_to_async
|
||||||
def uptdate_player_statistics(player_name):
|
def uptdate_player_statistics(player_name):
|
||||||
|
print("############# BEG STAT P")
|
||||||
player = get_object_or_404(Player, name=player_name)
|
player = get_object_or_404(Player, name=player_name)
|
||||||
|
|
||||||
# Filtrer les matchs où le joueur est joueur 1 ou joueur 2
|
# Filtrer les matchs où le joueur est joueur 1 ou joueur 2
|
||||||
|
print("############# HERE")
|
||||||
matches_as_player1 = Match.objects.filter(player1=player)
|
matches_as_player1 = Match.objects.filter(player1=player)
|
||||||
matches_as_player2 = Match.objects.filter(player2=player)
|
matches_as_player2 = Match.objects.filter(player2=player)
|
||||||
|
print("############# ACTUALLY, IT'S GOOD")
|
||||||
|
|
||||||
# Calculer les statistiques
|
# Calculer les statistiques
|
||||||
total_match = matches_as_player1.count() + matches_as_player2.count()
|
total_match = matches_as_player1.count() + matches_as_player2.count()
|
||||||
@ -118,9 +127,9 @@ def uptdate_player_statistics(player_name):
|
|||||||
return
|
return
|
||||||
|
|
||||||
won_matches = Match.objects.filter(winner=player)
|
won_matches = Match.objects.filter(winner=player)
|
||||||
part_tourn_as_p1 = Tournoi.objects.filter(matches__is_tournoi=True, matches__matches_as_player1=player)
|
""" part_tourn_as_p1 = Tournoi.objects.filter(matches__is_tournoi=True, matches__matches_as_player1=player)
|
||||||
part_tourn_as_p2 = Tournoi.objects.filter(matches__is_tournoi=True, matches__matches_as_player2=player)
|
part_tourn_as_p2 = Tournoi.objects.filter(matches__is_tournoi=True, matches__matches_as_player2=player)
|
||||||
won_tourn = Tournoi.objects.filter(winner=player)
|
won_tourn = Tournoi.objects.filter(winner=player) """
|
||||||
|
|
||||||
total_score = matches_as_player1.aggregate(Sum('score_player1'))['score_player1__sum'] or 0
|
total_score = matches_as_player1.aggregate(Sum('score_player1'))['score_player1__sum'] or 0
|
||||||
total_score += matches_as_player2.aggregate(Sum('score_player2'))['score_player2__sum'] or 0
|
total_score += matches_as_player2.aggregate(Sum('score_player2'))['score_player2__sum'] or 0
|
||||||
@ -138,8 +147,8 @@ def uptdate_player_statistics(player_name):
|
|||||||
nbr_ball_touch += matches_as_player2.aggregate(Sum('nbr_ball_touch_p2'))['nbr_ball_touch_p2__sum'] or 0
|
nbr_ball_touch += matches_as_player2.aggregate(Sum('nbr_ball_touch_p2'))['nbr_ball_touch_p2__sum'] or 0
|
||||||
m_nbr_ball_touch = nbr_ball_touch / total_match
|
m_nbr_ball_touch = nbr_ball_touch / total_match
|
||||||
|
|
||||||
total_duration = matches_as_player1.aggregate(Sum('duration'))['duration__sum']
|
total_duration = matches_as_player1.aggregate(Sum('duration'))['duration__sum'] or 0
|
||||||
total_duration += matches_as_player2.aggregate(Sum('duration'))['duration__sum']
|
total_duration += matches_as_player2.aggregate(Sum('duration'))['duration__sum'] or 0
|
||||||
m_duration = total_duration / total_match
|
m_duration = total_duration / total_match
|
||||||
|
|
||||||
""" total_tourn_p = part_tourn_as_p1.count() + part_tourn_as_p2.count()
|
""" total_tourn_p = part_tourn_as_p1.count() + part_tourn_as_p2.count()
|
||||||
@ -164,6 +173,13 @@ def uptdate_player_statistics(player_name):
|
|||||||
player.num_won_tournaments = total_win_tourn """
|
player.num_won_tournaments = total_win_tourn """
|
||||||
|
|
||||||
player.save()
|
player.save()
|
||||||
|
print("CHAKU IS THE BEST")
|
||||||
|
|
||||||
|
def get_player_p_win(player_name):
|
||||||
|
# Rechercher le joueur par son nom
|
||||||
|
player = get_object_or_404(Player, name=player_name)
|
||||||
|
# Retourner la valeur de p_win
|
||||||
|
return player.p_win
|
||||||
|
|
||||||
|
|
||||||
""" def complete_match(match_id, score_player1, score_player2, nbr_ball_touch_p1, nbr_ball_touch_p2, duration):
|
""" def complete_match(match_id, score_player1, score_player2, nbr_ball_touch_p1, nbr_ball_touch_p2, duration):
|
||||||
|
|||||||
@ -205,14 +205,15 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleKeyDown(event) {
|
function handleKeyDown(event) {
|
||||||
console.log('Key press: ', event.key);
|
|
||||||
if (event.key === 'ArrowUp' || event.key === 'ArrowDown') {
|
if (event.key === 'ArrowUp' || event.key === 'ArrowDown') {
|
||||||
|
console.log('Key press: ', event.key);
|
||||||
sendKeyPress(event.key.toLowerCase());
|
sendKeyPress(event.key.toLowerCase());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendKeyPress(key) {
|
function sendKeyPress(key) {
|
||||||
if (socket.readyState === WebSocket.OPEN) {
|
if (socket.readyState === WebSocket.OPEN) {
|
||||||
|
console.log('Key sent: ', key);
|
||||||
socket.send(JSON.stringify({ type: 'key_press', key }));
|
socket.send(JSON.stringify({ type: 'key_press', key }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user