X-Git-Url: https://git.ucc.asn.au/?p=progcomp2013.git;a=blobdiff_plain;f=qchess%2Fsrc%2Fgame.py;h=1aabe4aad760f53a6ab38601638907497ebb8bcf;hp=09c73c22b34f6da99911921299335e10a58d5ba6;hb=df2c20df9b55fd3ab24c494d745a260662f1da67;hpb=f7cca7e99d39a6b04b605e988d182a9b8a9e4be3 diff --git a/qchess/src/game.py b/qchess/src/game.py index 09c73c2..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,24 +28,26 @@ class GameThread(StoppableThread): for p in self.players: with self.lock: - if isinstance(p, Network) and p.baseplayer != None: - self.state["turn"] = p.baseplayer # "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 isinstance(p, Network) == False or p.server == True: - 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: - result = p.get_response() - self.board.update(result) - + result = self.board.select(x, y, colour = p.colour) + + 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) @@ -72,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) +