# 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
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
+
+
+
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)
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)
+