示例#1
0
文件: board.py 项目: yangjiao2/Python
    def _on_mouse_click(self, event):
        if self._have_drew_board:
            board_width = self._board.winfo_width()
            board_height = self._board.winfo_height()
            gapx = (board_width) / (self._rows + 2)
            gapy = (board_height) / (self._cols + 2)
            self._gap = min(gapx, gapy)
            self._logic_row = int(event.x // self._gap) - 1
            self._logic_column = int(event.y // self._gap) - 1
            self._logicpos = (int(event.x // self._gap) - 1,
                              int(event.y // self._gap) - 1)

            if not gamecode._game_is_over(self._turn, self._cols, self._rows,
                                          self._logicboard):
                if gamecode._is_in_the_board(self._cols, self._rows,
                                             self._logic_column,
                                             self._logic_row):

                    if gamecode._is_a_valid_move(self._turn, self._cols,
                                                 self._rows, self._logicboard,
                                                 self._logicpos):
                        self._logicboard = gamecode.place_a_disc(
                            self._turn, self._cols, self._rows,
                            self._logicboard, self._logicpos)
                        self._turn = gamecode._opposite_turn(self._turn)
                        self._board = engine.Othello._apply_discs_from_logic_board(
                            self, self._board, self._logicboard)
                        if gamecode._no_valid_move_on_the_board(
                                self._turn, self._cols, self._rows,
                                self._logicboard):
                            if self._turn == BLACK:
                                self._turn = gamecode._opposite_turn(
                                    self._turn)
                                self._gamereport.set(
                                    'No valid move for Black.\nChange to White\'s turn.'
                                )
                            elif self._turn == WHITE:
                                self._turn = gamecode._opposite_turn(
                                    self._turn)
                                self._gamereport.set(
                                    'No valid move for White.\nChange to Black\'s turn.'
                                )
                        else:
                            if self._turn == BLACK:
                                self._gamereport.set('It is Black\'s turn!')
                            else:
                                self._gamereport.set('It is White\'s turn!')
                        counter = gamecode.counter(self._logicboard,
                                                   self._cols, self._rows)
                        self._blackreport.set('Black: ' + str(counter['b']))
                        self._whitereport.set('White: ' + str(counter['w']))
                        self._choose_the_winner()
                else:
                    pass
            else:
                pass

        else:
            pass
示例#2
0
 def take_turns(self):
     while not gamecode._game_is_over(self._turn, self._cols, self._rows, self._board):
         if _no_valid_move_on_the_board(self._turn, self._cols, self._rows, self._board):
             self._turn = gamecode._opposite_turn(self._turn)
         gamecode.print_board_and_information(self._board, self._cols, self._rows)
         gamecode.print_turn(self._turn)
         col = _get_move_col(self._cols)
         row = _get_move_row(self._rows)
         pos = (col - 1, row - 1)
         while not gamecode._is_a_valid_move(self._turn, self._cols, self._rows, self._board, pos):
             board = self._board
             print (board)
             print ('The move '+ str((col, row))+' is invalid. Please try again...')
             col = _get_move_col(self._cols)
             row = _get_move_row(self._rows)
             pos = (col - 1, row - 1)
         self._board = gamecode.place_a_disc(self._turn, self._cols, self._rows, self._board, pos)
         self._turn = gamecode._opposite_turn(self._turn)
示例#3
0
文件: board.py 项目: yangjiao2/Python
    def _on_mouse_click(self, event):
        if self._have_drew_board:
            board_width = self._board.winfo_width()
            board_height = self._board.winfo_height()
            gapx = (board_width ) / (self._rows + 2)
            gapy = (board_height) / (self._cols + 2)
            self._gap = min(gapx, gapy)
            self._logic_row = int(event.x//self._gap) - 1
            self._logic_column = int(event.y //self._gap) - 1
            self._logicpos = (int(event.x//self._gap) - 1, int(event.y //self._gap) - 1)
            
            if not gamecode._game_is_over(self._turn, self._cols, self._rows, self._logicboard):
                if gamecode._is_in_the_board(self._cols, self._rows, self._logic_column, self._logic_row):

                    if gamecode._is_a_valid_move(self._turn, self._cols, self._rows, self._logicboard, self._logicpos):
                        self._logicboard = gamecode.place_a_disc(self._turn, self._cols, self._rows, self._logicboard, self._logicpos)
                        self._turn = gamecode._opposite_turn(self._turn)
                        self._board = engine.Othello._apply_discs_from_logic_board(self, self._board, self._logicboard)
                        if gamecode._no_valid_move_on_the_board(self._turn, self._cols, self._rows, self._logicboard):
                            if self._turn == BLACK:
                                self._turn = gamecode._opposite_turn(self._turn)
                                self._gamereport.set('No valid move for Black.\nChange to White\'s turn.')
                            elif self._turn == WHITE:
                                self._turn = gamecode._opposite_turn(self._turn)
                                self._gamereport.set('No valid move for White.\nChange to Black\'s turn.')
                        else:
                            if self._turn == BLACK:
                                self._gamereport.set('It is Black\'s turn!')
                            else:
                                self._gamereport.set('It is White\'s turn!')
                        counter = gamecode.counter(self._logicboard, self._cols, self._rows)
                        self._blackreport.set('Black: '+ str(counter['b']))
                        self._whitereport.set('White: ' + str(counter['w']))
                        self._choose_the_winner()
                else:
                    pass
            else:
                pass

        else:
            pass
示例#4
0
 def take_turns(self):
     while not gamecode._game_is_over(self._turn, self._cols, self._rows,
                                      self._board):
         if _no_valid_move_on_the_board(self._turn, self._cols, self._rows,
                                        self._board):
             self._turn = gamecode._opposite_turn(self._turn)
         gamecode.print_board_and_information(self._board, self._cols,
                                              self._rows)
         gamecode.print_turn(self._turn)
         col = _get_move_col(self._cols)
         row = _get_move_row(self._rows)
         pos = (col - 1, row - 1)
         while not gamecode._is_a_valid_move(self._turn, self._cols,
                                             self._rows, self._board, pos):
             board = self._board
             print(board)
             print('The move ' + str((col, row)) +
                   ' is invalid. Please try again...')
             col = _get_move_col(self._cols)
             row = _get_move_row(self._rows)
             pos = (col - 1, row - 1)
         self._board = gamecode.place_a_disc(self._turn, self._cols,
                                             self._rows, self._board, pos)
         self._turn = gamecode._opposite_turn(self._turn)
示例#5
0
文件: board.py 项目: yangjiao2/Python
 def _choose_the_winner(self):
     if gamecode._game_is_over(self._turn, self._cols, self._rows,
                               self._logicboard):
         winner = gamecode.choose_the_winner(self._cols, self._rows,
                                             self._logicboard, self._rule)
         self._gamereport.set(winner + ' wins!')
示例#6
0
文件: board.py 项目: yangjiao2/Python
 def _choose_the_winner(self):
     if gamecode._game_is_over(self._turn, self._cols, self._rows, self._logicboard):
         winner = gamecode.choose_the_winner(self._cols, self._rows, self._logicboard, self._rule)
         self._gamereport.set(winner + ' wins!')