mirror of
https://github.com/AudebertAdrien/ft_transcendence.git
synced 2026-11-09 18:17:07 +01:00
endfortheouche doesnt work yet
This commit is contained in:
@@ -100,12 +100,14 @@ class Game:
|
||||
self.game_state['player2_score'] += 1
|
||||
if self.game_state['player2_score'] > 2:
|
||||
print("Here !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
|
||||
await self.send_game_state()
|
||||
await self.end_game()
|
||||
self.reset_ball()
|
||||
elif self.game_state['ball_position']['x'] >= 790:
|
||||
self.game_state['player1_score'] += 1
|
||||
if self.game_state['player1_score'] > 2:
|
||||
print("Here !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
|
||||
await self.send_game_state()
|
||||
await self.end_game()
|
||||
self.reset_ball()
|
||||
|
||||
@@ -197,7 +199,8 @@ class Game:
|
||||
'player': disconnected_name
|
||||
})
|
||||
if not self.botgame:
|
||||
await remaining_player.send(message)
|
||||
if not self.localgame:
|
||||
await remaining_player.send(message)
|
||||
# Notify both players that the game has ended
|
||||
end_message = json.dumps({
|
||||
'type': 'game_ended',
|
||||
|
||||
@@ -4,25 +4,34 @@ from django.shortcuts import get_object_or_404
|
||||
from django.db.models import Max, Sum, F
|
||||
from datetime import timedelta
|
||||
from channels.db import database_sync_to_async
|
||||
#from asgiref.sync import database_sync_to_async
|
||||
|
||||
|
||||
async def endfortheouche(p1, p2, s_p1, s_p2, bt_p1, bt_2, dur, is_tournoi, name_tournament):
|
||||
try:
|
||||
print("here endfortheouche §!!!")
|
||||
if not await database_sync_to_async(Player.objects.filter(name=p1).exists)():
|
||||
|
||||
# Handle Player 1
|
||||
exists = await database_sync_to_async(Player.objects.filter(name=p1).exists)()
|
||||
if exists:
|
||||
print(f"Player {p1} exists.")
|
||||
else:
|
||||
print(f"Player {p1} does not exist.")
|
||||
|
||||
player_1 = await get_name(p1)
|
||||
print(f"Player 1 retrieval result: {player_1}")
|
||||
if player_1 is None:
|
||||
print("############# CREATING PLAYER")
|
||||
player_1 = await create_player(p1)
|
||||
print("############# PLAYER DONE")
|
||||
else:
|
||||
player_1 = await database_sync_to_async(Player.objects.get)(name=p1)
|
||||
|
||||
print("ok")
|
||||
|
||||
if not await database_sync_to_async(Player.objects.filter(name=p2).exists)():
|
||||
print("############# PLAYER FOUND")
|
||||
|
||||
# Handle Player 2
|
||||
player_2 = await get_name(p2)
|
||||
print(f"Player 2 retrieval result: {player_2}")
|
||||
if player_2 is None:
|
||||
print("############# CREATING PLAYER")
|
||||
player_2 = await create_player(p2)
|
||||
print("############# PLAYER DONE")
|
||||
else:
|
||||
player_2 = await database_sync_to_async(Player.objects.get)(name=p2)
|
||||
print("############# PLAYER FOUND")
|
||||
|
||||
print("############# BEFORE MATCH")
|
||||
await create_match(player_1, player_2, s_p1, s_p2, bt_p1, bt_2, dur, is_tournoi, name_tournament)
|
||||
@@ -31,9 +40,19 @@ async def endfortheouche(p1, p2, s_p1, s_p2, bt_p1, bt_2, dur, is_tournoi, name_
|
||||
await update_player_statistics(p1)
|
||||
print("############# END STAT P1")
|
||||
await update_player_statistics(p2)
|
||||
print("############# END STAT P2")
|
||||
except Exception as e:
|
||||
print(f"Error in endfortheouche: {e}")
|
||||
|
||||
@database_sync_to_async
|
||||
def get_name(p):
|
||||
print(f"in get_name({p})..")
|
||||
try:
|
||||
return Player.objects.get(name=p)
|
||||
except Player.DoesNotExist:
|
||||
print("get_name() exception")
|
||||
return None
|
||||
|
||||
@database_sync_to_async
|
||||
def create_player(
|
||||
name,
|
||||
|
||||
Reference in New Issue
Block a user