Exemple #1
0
 def __init__(self, canvas):
     # canvas this board is placed on
     self.__canvas = canvas
     # othello is played on an 8 x 8 board
     self.__size = 8
     # internal representation of this board
     self.__board = []
     for x in range(self.__size):
         vertical_strip = []
         for y in range(self.__size):
             if (x + y) % 2 == 0:
                 vertical_strip.append(Cell(canvas, x * 50 + 50, y * 50 + 50, 50, "grey"))
             else:
                 vertical_strip.append(Cell(canvas, x * 50 + 50, y * 50 + 50, 50, "white"))
         self.__board.append(vertical_strip)
     # othello board starts with four pieces in the middle
     Piece(self.__board[int(self.__size / 2)][int(self.__size / 2 - 1)], "black")
     Piece(self.__board[int(self.__size / 2 - 1)][int(self.__size / 2 - 1)], "white")
     Piece(self.__board[int(self.__size / 2 - 1)][int(self.__size / 2)], "black")
     Piece(self.__board[int(self.__size / 2)][int(self.__size / 2)], "white")
     # the first cell to be selected is at coordinates (0, 0)
     self.__cell_selected_coordinates = (0, 0)
     self.__board[self.__cell_selected_coordinates[0]][self.__cell_selected_coordinates[1]].set_is_selected(True)
     # number of turns played so far in game
     self.__turns_played = 0
Exemple #2
0
 def test_get_filled_with(self):
     tkinter = Tk()
     canvas = Canvas(tkinter, width=500, height=500)
     cell0 = Cell(canvas, 200, 300, 50, "grey")
     self.assertEqual(None, cell0.get_filled_with())
     piece0 = Piece(cell0, "white")
     self.assertEqual(piece0, cell0.get_filled_with())
Exemple #3
0
 def test_piece_constructor2(self):
     tkinter = Tk()
     canvas = Canvas(tkinter, width=500, height=500)
     cell0 = Cell(canvas, 200, 300, 50, "grey")
     try:
         piece0 = Piece(cell0, "green")
         print(str(piece0) + " did not throw an exception!")
     except ValueError:
         self.assertEqual(None, cell0.get_filled_with())
Exemple #4
0
 def key_pressed(self, event):
     new_x = self.__board_model.get_cell_selected_coordinates()[0]
     new_y = self.__board_model.get_cell_selected_coordinates()[1]
     if event.keysym == "Left":
         new_x = new_x - 1
     if event.keysym == "Right":
         new_x = new_x + 1
     if event.keysym == "Up":
         new_y = new_y - 1
     if event.keysym == "Down":
         new_y = new_y + 1
     self.__board_model.select_new_cell(new_x, new_y)
     if event.keysym == "Return":
         x = self.__board_model.get_cell_selected_coordinates()[0]
         y = self.__board_model.get_cell_selected_coordinates()[1]
         Piece(self.__board_model.get_board()[x][y],
               self.__board_model.next_to_play())
         self.__board_model.new_turn()
Exemple #5
0
 def test_fill(self):
     tkinter = Tk()
     canvas = Canvas(tkinter, width=500, height=500)
     cell0 = Cell(canvas, 200, 300, 50, "grey")
     cell1 = Cell(canvas, 200, 300, 50, "white")
     piece0 = Piece(cell0, "white")
     piece1 = Piece(cell1, "black")
     try:
         piece1 = Piece(cell0, "black")
         print(str(piece1) + " did not throw an exception!")
         self.assertNotEqual(piece1, cell0.get_filled_with())
     except ValueError:
         self.assertEqual(piece0, cell0.get_filled_with())
         self.assertEqual(cell1, piece1.get_cell())
     self.assertEqual(cell0, cell0.get_filled_with().get_cell())
Exemple #6
0
 def test_get_color(self):
     tkinter = Tk()
     canvas = Canvas(tkinter, width=500, height=500)
     cell0 = Cell(canvas, 200, 300, 50, "grey")
     piece0 = Piece(cell0, "white")
     self.assertEqual("white", piece0.get_color())