add tournament code to win server game request
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
# By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
|
# By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2024/09/13 16:20:58 by tomoron #+# #+# #
|
# Created: 2024/09/13 16:20:58 by tomoron #+# #+# #
|
||||||
# Updated: 2024/10/14 20:32:47 by tomoron ### ########.fr #
|
# Updated: 2024/10/15 13:38:03 by tomoron ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ class Game:
|
|||||||
waitingForPlayer = None
|
waitingForPlayer = None
|
||||||
|
|
||||||
@multimethod
|
@multimethod
|
||||||
def __init__(self, p1 , p2 , isTournament = False):
|
def __init__(self, p1 , p2 , tournamentCode):
|
||||||
self.initAttributes()
|
self.initAttributes()
|
||||||
if(isinstance(p1, Bot) and isinstance(p2, Bot)):
|
if(isinstance(p1, Bot) and isinstance(p2, Bot)):
|
||||||
self.winner=1
|
self.winner=1
|
||||||
@ -37,7 +37,9 @@ class Game:
|
|||||||
elif(isinstance(p2,Bot)):
|
elif(isinstance(p2,Bot)):
|
||||||
p2,p1 = p1, p2
|
p2,p1 = p1, p2
|
||||||
self.withBot = isinstance(p1,Bot)
|
self.withBot = isinstance(p1,Bot)
|
||||||
self.isTournament = isTournament
|
self.tournamentCode = tournamentCode
|
||||||
|
self.p1 = p1
|
||||||
|
self.p2 = p2
|
||||||
p1.setGame(self)
|
p1.setGame(self)
|
||||||
p2.setGame(self)
|
p2.setGame(self)
|
||||||
print("game created with ", p1.socket.username, "vs", p2.socket.username)
|
print("game created with ", p1.socket.username, "vs", p2.socket.username)
|
||||||
@ -75,7 +77,7 @@ class Game:
|
|||||||
def initAttributes(self):
|
def initAttributes(self):
|
||||||
self.p1 = None
|
self.p1 = None
|
||||||
self.p2 = None
|
self.p2 = None
|
||||||
self.isTournament=False
|
self.tournamentCode = None
|
||||||
self.started = False
|
self.started = False
|
||||||
self.end = False
|
self.end = False
|
||||||
self.left = None
|
self.left = None
|
||||||
@ -160,9 +162,8 @@ class Game:
|
|||||||
def endGame(self, winner):
|
def endGame(self, winner):
|
||||||
if(self.end):
|
if(self.end):
|
||||||
return
|
return
|
||||||
if(self.p1 != None):
|
self.p1.socket.sync_send({"type":"game","content":{"action":10,"won":winner==1, "opponentLeft":self.left == 2, "tournamentCode":self.tournamentCode}})
|
||||||
self.p1.socket.sync_send({"type":"game","content":{"action":10,"won":winner==1, "opponentLeft":self.left == 2}})
|
self.p2.socket.sync_send({"type":"game","content":{"action":10,"won":winner==2, "opponentLeft":self.left == 1, "tournamentCode":self.tournamentCode}})
|
||||||
self.p2.socket.sync_send({"type":"game","content":{"action":10,"won":winner==2, "opponentLeft":self.left == 1}})
|
|
||||||
self.winner = winner
|
self.winner = winner
|
||||||
self.pWinner = self.p1 if winner == 1 else self.p2
|
self.pWinner = self.p1 if winner == 1 else self.p2
|
||||||
self.end = True
|
self.end = True
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
# By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
|
# By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2024/10/04 17:17:07 by tomoron #+# #+# #
|
# Created: 2024/10/04 17:17:07 by tomoron #+# #+# #
|
||||||
# Updated: 2024/10/14 20:23:18 by tomoron ### ########.fr #
|
# Updated: 2024/10/15 13:37:13 by tomoron ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
@ -108,7 +108,7 @@ class Tournament:
|
|||||||
else:
|
else:
|
||||||
right = self.createGames(players, level + 1)
|
right = self.createGames(players, level + 1)
|
||||||
left = self.createGames(players, level + 1)
|
left = self.createGames(players, level + 1)
|
||||||
return(TournamentGame(left, right))
|
return(TournamentGame(left, right, self.code))
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
self.started = True
|
self.started = True
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
# By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
|
# By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2024/10/12 22:49:00 by tomoron #+# #+# #
|
# Created: 2024/10/12 22:49:00 by tomoron #+# #+# #
|
||||||
# Updated: 2024/10/14 21:57:14 by edbernar ### ########.fr #
|
# Updated: 2024/10/15 13:36:34 by tomoron ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
@ -14,9 +14,10 @@ from .Game import Game
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
class TournamentGame:
|
class TournamentGame:
|
||||||
def __init__(self, left, right):
|
def __init__(self, left, right, code):
|
||||||
self.game = None
|
self.game = None
|
||||||
self.winner = None
|
self.winner = None
|
||||||
|
self.code = code
|
||||||
self.right = right
|
self.right = right
|
||||||
self.left = left
|
self.left = left
|
||||||
asyncio.create_task(self.loop())
|
asyncio.create_task(self.loop())
|
||||||
@ -26,11 +27,11 @@ class TournamentGame:
|
|||||||
r = None
|
r = None
|
||||||
print("start new game")
|
print("start new game")
|
||||||
if(isinstance(self.left,TournamentGame)):
|
if(isinstance(self.left,TournamentGame)):
|
||||||
self.game = Game(self.left.winner, self.right.winner, True)
|
self.game = Game(self.left.winner, self.right.winner, self.code)
|
||||||
l = self.left.winner
|
l = self.left.winner
|
||||||
r = self.right.winner
|
r = self.right.winner
|
||||||
else:
|
else:
|
||||||
self.game = Game(self.left, self.right, True)
|
self.game = Game(self.left, self.right, self.code)
|
||||||
l = self.left
|
l = self.left
|
||||||
r = self.right
|
r = self.right
|
||||||
l.socket.sync_send("tournament", {
|
l.socket.sync_send("tournament", {
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
# By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ #
|
# By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2024/09/09 16:10:26 by tomoron #+# #+# #
|
# Created: 2024/09/09 16:10:26 by tomoron #+# #+# #
|
||||||
# Updated: 2024/10/09 00:53:25 by tomoron ### ########.fr #
|
# Updated: 2024/10/15 13:43:13 by tomoron ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
@ -59,6 +59,7 @@ from .gameActions.ping import ping
|
|||||||
# 10: game end
|
# 10: game end
|
||||||
# - won : true/false
|
# - won : true/false
|
||||||
# - opponentLeft : true/false
|
# - opponentLeft : true/false
|
||||||
|
# - tournamentCode : null if not in a tournament
|
||||||
|
|
||||||
#client actions (actions sent by the client) :
|
#client actions (actions sent by the client) :
|
||||||
# 0 : start : starts a game
|
# 0 : start : starts a game
|
||||||
|
Reference in New Issue
Block a user