Ejemplo n.º 1
0
    def test_is_path_exists(self):
        for i in self.field.width_r:
            self.field[(i, 2)] = Cell(Ball({BallColor.BROWN}))
        self.field[(0, 0)] = Cell(Ball({BallColor.RED}))

        self.assertTrue(self.field.is_path_exists((0, 0), (0, 1)))
        self.assertFalse(self.field.is_path_exists((0, 0), (3, 3)))
Ejemplo n.º 2
0
    def test_is_correct_move(self):
        for i in self.field.width_r:
            self.field[(i, 2)] = Cell(Ball({BallColor.BROWN}))
        self.field[(0, 0)] = Cell(Ball({BallColor.RED}))
        self.field[(1, 2)] = Cell(Ball({BallColor.BLUE}))

        self.assertFalse(self.field.is_correct_move((0, 2), (0, 2)))
        self.assertFalse(self.field.is_correct_move((0, 0), (3, 3)))
Ejemplo n.º 3
0
 def setUp(self):
     field = GameField(5)
     for i in field.width_r:
         field[(i, 0)] = Cell(Ball({BallColor.BROWN}))
     self.controller = Controller(field,
                                  ScoreBoard("", {"1": 100}, 1),
                                  False)
Ejemplo n.º 4
0
    def test_perform_move(self):
        ball = Ball({BallColor.RED})
        self.field[(0, 0)] = Cell(ball)

        self.field.perform_move((0, 0), (3, 3))

        self.assertTrue(self.field[(3, 3)].ball == ball)
Ejemplo n.º 5
0
    def test_get_set(self):
        coordinates = (1, 1)
        cell = Cell()

        self.field[coordinates] = cell

        self.assertTrue(self.field[coordinates] == cell)
        self.assertRaises(TypeError, self.field.__setitem__(coordinates, cell))
Ejemplo n.º 6
0
    def test_try_remove_lines(self):
        for i in self.field.width_r:
            self.field[(i, 0)] = Cell(Ball({BallColor.BROWN}))

        self.field.try_remove_lines(self.field.get_completed_lines((0, 0)))

        count = self.field.empty_cells_count
        self.assertTrue(count == 25)
Ejemplo n.º 7
0
 def setUp(self):
     self.ball_cell = Cell(Ball({BallColor.RED}))  # type: Cell
     self.cell = Cell()  # type: Cell
Ejemplo n.º 8
0
    def test_find_lines(self):
        for i in self.field.width_r:
            self.field[(i, 0)] = Cell(Ball({BallColor.BROWN}))

        self.assertTrue(len(self.field.find_lines((0, 0))) == 4)
Ejemplo n.º 9
0
    def test_get_completed_lines(self):
        for i in self.field.width_r:
            self.field[(i, 0)] = Cell(Ball({BallColor.BROWN}))

        self.assertTrue(self.field.get_completed_lines((0, 0)))
Ejemplo n.º 10
0
 def try_remove_lines(self, lines):
     if lines:
         longest_line = max(lines, key=len)
         for coordinates in longest_line.balls:
             self[coordinates] = Cell()
         return len(longest_line)
Ejemplo n.º 11
0
 def __init__(self, field_size: int):
     self._field = [[Cell() for _ in range(field_size)]
                    for _ in range(field_size)]
     self._empty_cells_count = field_size * field_size
     self.min_line_length = self.width // 2 + 1
Ejemplo n.º 12
0
 def perform_move(self, start, finish):
     self[finish] = self[start]
     self[start] = Cell()