Beispiel #1
0
 def make_basic_game_grid(self):
     game = Blockies.Game(2)
     blue_squares = [(0, 0), (1, 1), (2, 2)]
     green_squares = [(9, 9), (8, 8), (7, 7)]
     for square in blue_squares:
         game.grid.set_square(
             square, Blockies.Piece('square', 1, 1, square, const.BLUE))
     for square in green_squares:
         game.grid.set_square(
             square, Blockies.Piece('square', 1, 1, square, const.GREEN))
     return game
Beispiel #2
0
 def test_grid_set_squares(self):
     grid = Blockies.Grid()
     square = (0, 9)
     grid.set_square(square,
                     Blockies.Piece('square', 1, 1, square, const.BLUE))
     self.assertIsNotNone(grid._squares[0][9])
     self.assertIsNone(grid._squares[1][8])
Beispiel #3
0
 def test_rotate_2_1_points_clockwise(self):
     piece = Blockies.Piece('rectangle', 2, 1, (2, 4), const.WHITE)
     initial_points = [(163, 323), (163, 397), (317, 397), (317, 323)]
     expected_points = [(163, 323), (163, 477), (237, 477), (237, 323)]
     self.assertEqual(set(piece.points), set(initial_points))
     piece.rotate_clockwise()
     self.assertEqual(set(piece.points), set(expected_points),
                      'rotated 2x1 rect does not occupy expected squares')
Beispiel #4
0
 def test_rotate_2_1_squares_clockwise(self):
     piece = Blockies.Piece('rectangle', 2, 1, (2, 4), const.WHITE)
     initial_squares = [(2, 4), (3, 4)]
     expected_squares = [(2, 4), (2, 5)]
     self.assertEqual(set(piece.squares), set(initial_squares))
     piece.rotate_clockwise()
     self.assertEqual(set(piece.squares), set(expected_squares),
                      'rotated 2x1 rect does not occupy expected squares')
Beispiel #5
0
 def test_rotate_3_2_rect_clockwise(self):
     piece = Blockies.Piece('rectangle', 3, 2, (2, 2), const.WHITE)
     initial_squares = [(2, 2), (3, 2), (4, 2), (2, 3), (3, 3), (4, 3)]
     expected_squares = [(1, 2), (2, 2), (1, 3), (2, 3), (1, 4), (2, 4)]
     self.assertEqual(set(piece.squares), set(initial_squares))
     piece.rotate_clockwise()
     self.assertEqual(set(piece.squares), set(expected_squares),
                      'rotated 3x2 rect does not occupy expected squares')
Beispiel #6
0
 def test_rotate_1_2_rect_clockwise(self):
     piece = Blockies.Piece('rectangle', 1, 2, (3, 6), const.WHITE)
     initial_squares = [(3, 6), (3, 7)]
     expected_squares = [(2, 6), (3, 6)]
     self.assertEqual(set(piece.squares), set(initial_squares))
     piece.rotate_clockwise()
     self.assertEqual(set(piece.squares), set(expected_squares),
                      'rotated 1x2 rect does not occupy expected squares')
Beispiel #7
0
    def test_find_corner_squares_3x3(self):

        piece = Blockies.Piece('square', 3, 3, (3, 3), const.WHITE)
        expected_squares = [(3, 3), (4, 3), (5, 3), (3, 4), (4, 4), (5, 4),
                            (3, 5), (4, 5), (5, 5)]
        expected_corners = [(3, 3), (3, 5), (5, 5), (5, 3)]
        self.assertEqual(piece.squares, expected_squares)
        self.assertEqual(Blockies.find_corners(piece.squares),
                         expected_corners)
Beispiel #8
0
 def make_game_full_grid(self):
     game = Blockies.Game(1)
     squares = []
     for i in range(const.SQ_COLUMNS):
         for j in range(const.SQ_COLUMNS):
             squares.append((i, j))
     for square in squares:
         game.grid.set_square(
             square, Blockies.Piece('square', 1, 1, square, const.BLUE))
     return game
Beispiel #9
0
 def test_grid_set_squares_3x_piece(self):
     grid = Blockies.Grid()
     square = (1, 2)
     grid.set_square(square,
                     Blockies.Piece('square', 3, 1, square, const.BLUE))
     self.assertIsNotNone(grid._squares[1][2])
     self.assertIsNotNone(grid._squares[2][2])
     self.assertIsNotNone(grid._squares[3][2])
     self.assertIsNone(grid._squares[4][2])
     self.assertIsNone(grid._squares[5][2])
     self.assertIsNone(grid._squares[0][2])
Beispiel #10
0
 def test_find_corner_coordinates(self):
     piece = Blockies.Piece('rectangle', 3, 2, (2, 2), const.WHITE)
     expected_squares = [(2, 2), (2, 3), (4, 2), (4, 3)]
     self.assertEqual(set(piece._get_corners_rectangle()),
                      set(expected_squares))
Beispiel #11
0
 def test_piece2_squares_taken(self):
     piece = Blockies.Piece('square', 2, 2, (1, 2), const.WHITE)
     expected_squares = [(1, 2), (2, 2), (1, 3), (2, 3)]
     self.assertEqual(set(piece.squares), set(expected_squares))
Beispiel #12
0
 def test_piece2_update_square_1x(self):
     piece = Blockies.Piece('square', 1, 1, (0, 0), const.WHITE)
     piece.move_to((2, 2))
     self.assertEqual(piece.squares, [(2, 2)])
Beispiel #13
0
 def test_piece2_construct_square_1x(self):
     piece = Blockies.Piece('square', 1, 1, (0, 0), const.WHITE)
     self.assertEqual(len(piece.matrix), 1)
     self.assertEqual(len(piece.matrix[0]), 1)
Beispiel #14
0
 def test_piece2_construct_square_2x(self):
     piece = Blockies.Piece('square', 2, 2, (0, 0), (100, 100, 100))
     self.assertEqual(len(piece.matrix), 2)
     self.assertEqual(len(piece.matrix[0]), 2)
     self.assertEqual(len(piece.matrix[1]), 2)
Beispiel #15
0
 def make_square_at(self, pos):
     return Blockies.Piece('square', 1, 1, pos, const.WHITE)