示例#1
0
    def parser(self, level_number):
        result = Level()

        self.bricks = self.get_lines()

        if len(self.bricks) == 0:
            self.max_level_number = level_number
        else:
            self.width = len(self.bricks[0])
            self.height = len(self.bricks)

            for y in range(self.height):
                for x in range(self.width):
                    if self.bricks[y][x] == '1':
                        result.bricks.append(Brick(x * 40, y * 20, 1))
                    elif self.bricks[y][x] == '2':
                        result.bricks.append(Brick(x * 40, y * 20, 2))
                    elif self.bricks[y][x] == '3':
                        result.bricks.append(Brick(x * 40, y * 20, 3))
                    elif self.bricks[y][x] == '4':
                        result.bricks.append(Brick(x * 40, y * 20, 4))
                    elif self.bricks[y][x] == '5':
                        result.bricks.append(Brick(x * 40, y * 20, 2, True))

        return result.bricks
示例#2
0
 def test_hit_brick(self):
     ""
     """ Удар мяча по кирпичу снизу """
     self.ball = Ball(200, 200, 14, 4, -6)
     self.brick = Brick(180, 180, 1)
     self.ball.hit_brick(self.brick)
     self.assertEqual(self.ball.speed_x, 4)
     self.assertEqual(self.ball.speed_y, 6)
     """ Удар мяча по кирпичу сверху """
     self.ball = Ball(200, 200, 14, 6, 4)
     self.brick = Brick(180, 220, 1)
     self.ball.hit_brick(self.brick)
     self.assertEqual(self.ball.speed_x, 6)
     self.assertEqual(self.ball.speed_y, -4)
     """ Удар мяча по кирпичу слева """
     self.ball = Ball(200, 200, 14, 5, 5)
     self.brick = Brick(214, 200, 1)
     self.ball.hit_brick(self.brick)
     self.assertEqual(self.ball.speed_x, -5)
     self.assertEqual(self.ball.speed_y, 5)
     """ Удар мяча по кирпичу справа """
     self.ball = Ball(200, 200, 14, -5, 5)
     self.brick = Brick(160, 200, 1)
     self.ball.hit_brick(self.brick)
     self.assertEqual(self.ball.speed_x, 5)
     self.assertEqual(self.ball.speed_y, 5)
示例#3
0
def create_maze(screen, gm_setting, maze, bricks, i, j):
    # 根据迷宫的二维列表来创建单个砖块加入编组
    brick = Brick(gm_setting, screen)
    brick.pos = (i, j)
    brick.rect.bottom = brick.width * (i + 1)
    brick.rect.right = brick.width * (j + 1)
    brick.color = gm_setting.maze_color[maze.m[i][j]]
    bricks.add(brick)
示例#4
0
 def test_break_brick(self):
     brick = Brick(250, 400, 1)
     self.bricks.append(Brick(250, 400, 1))
     length = len(self.bricks)
     self.assertEqual(length, 1)
     self.assertEqual(1, self.bricks[0].brick_health)
     for el in self.bricks:
         if brick.x == el.x and brick.y == el.y:
             el.break_brick(el, self.bricks)
             self.assertEqual(0, el.brick_health)
             break
     self.assertLess(len(self.bricks), length)
示例#5
0
    def test_multiple_hit(self):
        self.bricks = [Brick(250, 300, 3)]
        el = self.bricks[0]

        self.assertEqual(3, el.brick_health)

        el.break_brick(el, self.bricks)
        el.break_brick(el, self.bricks)
        el.break_brick(el, self.bricks)

        self.assertEqual(0, el.brick_health)
        self.assertEqual(0, len(self.bricks))
示例#6
0
    def test_check_on_brick_health(self):
        self.bricks = [
            Brick(250, 400, 1),
            Brick(250, 340, 2),
            Brick(250, 300, 3)
        ]

        el = self.bricks[0]
        self.assertEqual(1, el.brick_health)
        el.break_brick(el, self.bricks)
        self.assertEqual(0, el.brick_health)

        el = self.bricks[0]
        self.assertEqual(2, el.brick_health)
        el.break_brick(el, self.bricks)
        self.assertEqual(1, el.brick_health)

        el = self.bricks[1]
        self.assertEqual(3, el.brick_health)
        el.break_brick(el, self.bricks)
        self.assertEqual(2, el.brick_health)
示例#7
0
    def test_game_completed(self):
        self.game.bricks = [Brick(0, 0, 1)]
        self.game.level_number = self.game.level.max_level_number
        self.assertFalse(self.game.game_completed())

        self.game.bricks = []
        self.game.level_number = self.game.level.max_level_number
        self.assertTrue(self.game.game_completed())

        self.game.bricks = []
        self.game.level_number = 1
        self.game.level.max_level_number = 3
        self.assertFalse(self.game.game_completed())
示例#8
0
    def test_level_completed(self):
        self.game.bricks = [Brick(0, 0, 1)]
        self.assertFalse(self.game.level_completed())

        self.game.bricks.clear()
        self.assertTrue(self.game.level_completed())
示例#9
0
    def test_brick_invisibility(self):
        self.bricks = [Brick(250, 260, 3, True)]
        self.assertTrue(self.bricks[0].is_invisibility)

        self.bricks = [Brick(100, 100, 3)]
        self.assertFalse(self.bricks[0].is_invisibility)