예제 #1
0
 def dragon_collide_enemy(self):
     arena = Arena((100, 100))
     dragon = Dragon(arena, (50, 0))
     enemy = Enemy((47, 0), arena)
     dragon.go_left()
     dragon.move()
     dragon.collide(enemy)
     self.assertTrue(len(arena.actors()) == 1)
예제 #2
0
 def dragon_collide_bubble(self):
     arena = Arena((100, 100))
     dragon = Dragon(arena, (50, 0))
     bubble = Bubble(arena, (47, 0), 0)
     dragon.go_left()
     dragon.move()
     dragon.collide(bubble)
     self.assertTrue(len(arena.actors()) == 1)
예제 #3
0
 def dragon_collide_platform(self):
     arena = Arena((100, 100))
     dragon = Dragon(arena, (0, 0))
     platform = Platform(arena, (30, 0), 2, 1)
     dragon.move()
     dragon.collide(platform)
     self.assertTrue(dragon.position() == (10, 0, 20, 20))
예제 #4
0
 def enemy_lives(self):
     arena = Arena((100, 100))
     bubble = Bubble(arena, (47, 0), 0)
     enemy = Enemy((50, 0), arena)
     lives0 = enemy.lives()
     enemy.go_left()
     enemy.move()
     enemy.collide(bubble)
     self.assertTrue(enemy.lives() == lives0())
예제 #5
0
 def enemy_collide_bubble(self):
     arena = Arena((100, 100))
     bubble = Bubble(arena, (47, 0), 0)
     enemy = Enemy((50, 0), arena)
     enemy.go_left()
     enemy.move()
     enemy.collide(bubble)
     bubble.go_left()
     bubble.move()
     self.assertTrue(enemy.position() == bubble.position())
    def __init__(self):
        self._arena = Arena((W, H))
        self._platform = []
        self._bubble = []
        self._bonus = []
        self._enemy = []
        self._playtime = PLAY_TIME  # seconds

        global TOTAL_POINTS

        with open("platform.txt") as f:
            for line in f:
                x, y, w, h = line.split(",")
                self._platform.append(
                    Platform(self._arena, (int(x), int(y)), int(w), int(h)))
            f.close()

        with open("dragon.txt") as f:
            line = f.readline()
            x, y = line.split(",")
            self._dragon = Dragon(self._arena, (int(x), int(y)))
            line = f.readline()
            x, y = line.split(",")
            self._dragon1 = Dragon(self._arena, (int(x), int(y)))
            f.close()

        with open("enemy.txt") as f:
            for line in f:
                x, y = line.split(",")
                self._enemy.append(Enemy((int(x), int(y)), self._arena))
            f.close()

        with open("bonus.txt") as f:
            for line in f:
                x, y = line.split(",")
                self._bonus.append(Bonus(self._arena, (int(x), int(y))))
                TOTAL_POINTS += 5
            f.close()
예제 #7
0
 def enemy_move_up(self):
     arena = Arena((100, 100))
     enemy = Enemy((50, 50), arena)
     enemy.go_up()
     enemy.move()
     self.assertTrue(enemy.position() == (50, 0, 20, 20))
예제 #8
0
 def dragon_move_left(self):
     arena = Arena((100, 100))
     dragon = Dragon(arena, (50, 0))
     dragon.go_left()
     dragon.move()
     self.assertTrue(dragon.position() == (47, 0, 20, 20))
class BubbleGame:
    def __init__(self):
        self._arena = Arena((W, H))
        self._platform = []
        self._bubble = []
        self._bonus = []
        self._enemy = []
        self._playtime = PLAY_TIME  # seconds

        global TOTAL_POINTS

        with open("platform.txt") as f:
            for line in f:
                x, y, w, h = line.split(",")
                self._platform.append(
                    Platform(self._arena, (int(x), int(y)), int(w), int(h)))
            f.close()

        with open("dragon.txt") as f:
            line = f.readline()
            x, y = line.split(",")
            self._dragon = Dragon(self._arena, (int(x), int(y)))
            line = f.readline()
            x, y = line.split(",")
            self._dragon1 = Dragon(self._arena, (int(x), int(y)))
            f.close()

        with open("enemy.txt") as f:
            for line in f:
                x, y = line.split(",")
                self._enemy.append(Enemy((int(x), int(y)), self._arena))
            f.close()

        with open("bonus.txt") as f:
            for line in f:
                x, y = line.split(",")
                self._bonus.append(Bonus(self._arena, (int(x), int(y))))
                TOTAL_POINTS += 5
            f.close()

    def arena(self) -> Arena:
        return self._arena

    def hero(self) -> Dragon:
        return self._dragon

    def hero1(self) -> Dragon:
        return self._dragon1

    def enemy(self) -> Enemy:
        return self._enemy

    def enemy_lives(self):
        total_lives = 0
        for enemy in self._enemy:
            total_lives += enemy.lives()
        return total_lives

    def bubble(self) -> Bubble:
        return self._bubble

    def platform(self) -> Platform:
        return self._platform

    def game_over(self) -> bool:
        return (self._dragon.lives() <= 0 or self._dragon1.lives() <= 0
                ) or self.remaining_time() <= 0 and self.enemy_lives() > 0

    def game_won(self) -> bool:
        return self.enemy_lives() == 0 and (
            self.hero().points() + self.hero1().points()) == TOTAL_POINTS

    def remaining_time(self) -> int:
        return (self._playtime - self._arena.count() // 30)