def draw(self, widget=None, events=None): self.drawingarea.window.draw_pixbuf( None, self.scaledbackground, 0, 0, int(round(self.shift_x)), int(round(self.shift_y)) ) for i in range(self.request.board_model.get_size()): for j in range(self.request.board_model.get_size()): player = self.request.board_model.get(i, j) if player == Player.WHITE: self.draw_cell(i, j, self.scaledwhite) elif player == Player.BLACK: self.draw_cell(i, j, self.scaledblack) elif ( self.yourturn and self.toolbuttonShowHint.get_active() and GameLogic.is_valid_position(self.request.board_model, i, j, self.player) ): self.draw_cell(i, j, self.scaledhint) if ( self.yourturn and self.selection_row is not None and self.selection_column is not None and self.selection_valid ): self.drawingarea.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.HAND2)) self.draw_cell( self.selection_row, self.selection_column, self.scaledwhite if self.player == Player.WHITE else self.scaledblack, ) else: self.drawingarea.window.set_cursor(None)
def place_pdu(self, context, client, x, y): if client == context.socket_player_white: if GameLogic.is_valid_position(context.boardmodel, x, y, Player.WHITE): affected_positions = GameLogic.get_affected_positions(context.boardmodel, x, y, Player.WHITE) GameLogic.apply_move(context.boardmodel, x, y, Player.WHITE) board_pdu = GameClientPDUCodec.update_board_pdu(Player.WHITE, affected_positions) context.request.send_req(context.socket_player_white, board_pdu) context.request.send_req(context.socket_player_black, board_pdu) next_turn_player = GameLogic.next_turn_player(context.boardmodel, Player.WHITE) white_count, black_count = context.boardmodel.count_disks() # if white_count > 4: # context.end_game() if next_turn_player == Player.WHITE: context.turn = context.socket_player_white context.state = context.WHITE_TURN context.state.turn_req(context) elif next_turn_player == Player.BLACK: context.turn = context.socket_player_black context.state = context.BLACK_TURN context.state.turn_req(context) else: # no valid movements->board full or no valid placements for any player context.end_game() else: context.request.send_req(client, GameClientPDUCodec.place_error_pdu()) context.request.send_req(client, GameClientPDUCodec.turn_pdu()) else: # not your turn # read protocol, I don't remember if it's specified to report the error or not context.request.send_req(client, GameClientPDUCodec.place_error_pdu())