X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=qchess%2Fsrc%2Fgame.py;h=1aabe4aad760f53a6ab38601638907497ebb8bcf;hb=df2c20df9b55fd3ab24c494d745a260662f1da67;hp=8b279fb9f5fad1e037c691d75b0791a284f4d20e;hpb=639646adb020e0be9433da7b3d5ef6b987c99f71;p=progcomp2013.git diff --git a/qchess/src/game.py b/qchess/src/game.py index 8b279fb..1aabe4a 100644 --- a/qchess/src/game.py +++ b/qchess/src/game.py @@ -5,7 +5,7 @@ # A thread that runs the game class GameThread(StoppableThread): - def __init__(self, board, players): + def __init__(self, board, players, server = True): StoppableThread.__init__(self) self.board = board self.players = players @@ -14,6 +14,10 @@ class GameThread(StoppableThread): self.lock = threading.RLock() #lock for access of self.state self.cond = threading.Condition() # conditional for some reason, I forgot self.final_result = "" + self.server = server + + + @@ -24,26 +28,26 @@ class GameThread(StoppableThread): for p in self.players: with self.lock: - if isinstance(p, NetworkSender): - self.state["turn"] = p.base_player # "turn" contains the player who's turn it is - else: - self.state["turn"] = p + self.state["turn"] = p.base_player() #try: if True: [x,y] = p.select() # Player selects a square if self.stopped(): break - - if not (isinstance(p, Network) and p.server == False): - result = self.board.select(x, y, colour = p.colour) + + if isinstance(p, NetworkPlayer): + if p.network.server == True: + result = self.board.select(x, y, colour = p.colour) + else: + result = None + else: - #debug(str(self) + " don't update local board") - result = "" + result = self.board.select(x, y, colour = p.colour) - result = p.update(result) + result = p.update(result) for p2 in self.players: if p2 != p: - result = p2.update(result) # Inform players of what happened + p2.update(result) # Inform players of what happened log(result) @@ -74,14 +78,25 @@ class GameThread(StoppableThread): if self.stopped(): break - - result = str(x) + " " + str(y) + " -> " + str(x2) + " " + str(y2) - log(result) - - self.board.update_move(x, y, x2, y2) + if isinstance(p, NetworkPlayer): + if p.network.server == True: + result = str(x) + " " + str(y) + " -> " + str(x2) + " " + str(y2) + self.board.update_move(x, y, x2, y2) + else: + result = None + + else: + result = str(x) + " " + str(y) + " -> " + str(x2) + " " + str(y2) + self.board.update_move(x, y, x2, y2) + + result = p.update(result) for p2 in self.players: - p2.update(result) # Inform players of what happened + if p2 != p: + p2.update(result) # Inform players of what happened + + log(result) +