コード例 #1
0
ファイル: a3.py プロジェクト: sd-link/python-gui-game
    def get_wave(self, wave):
        """Returns enemies in the 'wave_n'th wave

        Parameters:
            wave_n (int): The nth wave

        Return:
            list[tuple[int, AbstractEnemy]]: A list of (step, enemy) pairs in the
                                             wave, sorted by step in ascending order 
        """
        enemies = []

        if wave == 1:
            # A hardcoded singleton list of (step, enemy) pairs

            enemies = [(10, SimpleEnemy())]
        elif wave == 2:
            # A hardcoded list of multiple (step, enemy) pairs

            enemies = [(10, SimpleEnemy()), (15, SimpleEnemy()),
                       (30, SimpleEnemy())]
        elif 3 <= wave < 10:
            # List of (step, enemy) pairs spread across an interval of time (steps)

            steps = int(
                40 *
                (wave**.5))  # The number of steps to spread the enemies across
            count = wave * 2  # The number of enemies to spread across the (time) steps

            for step in self.generate_intervals(steps, count):
                enemies.append((step, SimpleEnemy()))

        elif wave == 10:
            # Generate sub waves
            sub_waves = [
                # (steps, number of enemies, enemy constructor, args, kwargs)
                (50, 10, SimpleEnemy, (), {}),  # 10 enemies over 50 steps
                (100, None, None, None, None),  # then nothing for 100 steps
                (50, 10, SimpleEnemy, (), {}
                 )  # then another 10 enemies over 50 steps
            ]

            enemies = self.generate_sub_waves(sub_waves)

        else:  # 11 <= wave <= 20
            # Now it's going to get hectic

            sub_waves = [
                (
                    int(13 * wave),  # total steps
                    int(25 * wave**(wave / 50)),  # number of enemies
                    SimpleEnemy,  # enemy constructor
                    (),  # positional arguments to provide to enemy constructor
                    {},  # keyword arguments to provide to enemy constructor
                ),
                # ...
            ]
            enemies = self.generate_sub_waves(sub_waves)

        return enemies
コード例 #2
0
ファイル: a3.py プロジェクト: mj221/CSSE1001
    def _step(self):
        """
        Perform a step every interval

        Triggers a game step and updates the view

        Returns:
            (bool) True if the game is still running
        """
        self._game.step()
        self.refresh_view()
        if self._step_number % 2 ==0:   # Let boss spawn a minion (simple enemy) using steps
            if call_enemy._spawn_count == 50:
                
                minion = SimpleEnemy()
                boss = BossEnemy()
                minion.position = self._game.grid.cell_to_pixel_centre(self._game.grid.pixel_to_cell((call_enemy._position)))
                minion.set_cell_size(self._game.grid.cell_size)
                self._game.enemies.append(minion)
                
##        self.refresh_view_shop()      Refer to ShopTowerView(tk.Frame), as to why I commented this method out.
        return not self._won
コード例 #3
0
ファイル: model.py プロジェクト: yuanwang7/TowerDefenceGame
    def send_wave(self, clear=False, enemies=20, steps=200):
        """Send a wave of randomly generated enemies
        
        Parameters:
            clear (bool): If True, clears the current enemies
            enemies (int): The number of enemies to generate
            steps (int): The number of steps over which to generate the enemies
        """
        print(enemies, steps)
        offset = self._current_step + 1

        wave = []

        # randomly generate enemies and their start steps
        for _ in range(enemies):
            step = int(offset + steps - random.triangular(0, steps, 0))
            wave.append((step, SimpleEnemy(self.grid.cell_size)))

        self.queue_wave(wave, clear=clear)
コード例 #4
0
 def __init__(self):
     self.enemy_datas = []
     self.addEnemy(SimpleEnemy(1))
コード例 #5
0
    def get_wave(self, wave):
        """Returns enemies in the 'wave_n'th wave

        Parameters:
            wave_n (int): The nth wave

        Return:
            list[tuple[int, AbstractEnemy]]: A list of (step, enemy) pairs in the
                                             wave, sorted by step in ascending order 
        """
        enemies = []

        if wave == 1:
            # A hardcoded singleton list of (step, enemy) pairs

            enemies = [(10, SimpleEnemy())]
        elif wave == 2:
            # A hardcoded list of multiple (step, enemy) pairs

            enemies = [(10, SimpleEnemy()), (15, SimpleEnemy()),
                       (30, SimpleEnemy())]
        elif 3 <= wave < 8:
            # List of (step, enemy) pairs spread across an interval of time (steps)

            steps = int(
                20 *
                (wave**.5))  # The number of steps to spread the enemies across
            count = wave * 2  # The number of enemies to spread across the (time) steps

            for step in self.generate_intervals(steps, count):
                enemies.append((step, SimpleEnemy()))
        elif 8 <= wave < 10:
            steps = int(
                25 *
                (wave**.5))  # The number of steps to spread the enemies across
            count = wave * 2  # The number of enemies to spread across the (time) steps

            for step in self.generate_intervals(steps, count):
                enemies.append((step, SimpleEnemy()))
            for step in self.generate_intervals(steps, count // 10):
                enemies.append((step, EnergyEnemy()))

        elif wave == 10:
            # Generate sub waves
            enemies = [(10, TankEnemy()), [15, TankEnemy()], [20, TankEnemy()]]

        elif 11 <= wave < 20:
            # Now it's going to get hectic

            steps = int(
                40 *
                (wave**.5))  # The number of steps to spread the enemies across
            count = wave * 5  # The number of enemies to spread across the (time) steps

            for step in self.generate_intervals(steps, count):
                enemies.append((step, SimpleEnemy()))
            for step in self.generate_intervals(steps, count // 10):
                enemies.append((step, EnergyEnemy()))
            for step in self.generate_intervals(steps, count // 55):
                enemies.append((step, TankEnemy()))
        else:  # The 20 wave with the special king boss
            enemies = [(10, TankEnemy()), (15, TankEnemy()),
                       (20, BarbarianKingEnemy()), (25, TankEnemy())]

        return enemies
コード例 #6
0
    def get_wave(self, wave, game):
        """Returns enemies in the 'wave_n'th wave

        Parameters:
            wave_n (int): The nth wave
            game (TowerGame): the instance of the game

        Return:
            list[tuple[int, AbstractEnemy]]: A list of (step, enemy) pairs in the
                                             wave, sorted by step in ascending order 
        """
        enemies = []

        if 1 <= wave <= 2:
            #A hardcoded singleton list of (step, enemy) pairs

            enemies = [ (10, SimpleEnemy()),(12, SimpleEnemy()),(14, SimpleEnemy())]


        elif 3 <= wave < 8:
            #List of (step, enemy) pairs spread across an interval of time (steps)

            steps = int(40 * (wave ** .5))  #The number of steps to spread the enemies across
            count = wave * 2  #The number of enemies to spread across the (time) steps

            for step in self.generate_intervals(steps, count):
                #make enemies have more health each wave!
                enemies.append((step, SimpleEnemy(health=wave/2*100)))
                #enemies.append((step+20, SwarmEnemy()))

        elif 7 <= wave < 10:
            #List of (step, enemy) pairs spread across an interval of time (steps)

            steps = int(40 * (wave ** .5))  #The number of steps to spread the enemies across
            count = wave  #The number of enemies to spread across the (time) steps

            for step in self.generate_intervals(steps, count):
                enemies.append((step, SimpleEnemy(health=wave/2*100)))
                enemies.append((step+20, HardenedEnemy(health=wave/2*100)))

        elif wave == 10:
            #Generate sub waves
            sub_waves = [
                #(steps, number of enemies, enemy constructor, args, kwargs)
                (50, 10, SimpleEnemy, (), {}),  #10 enemies over 50 steps
                (100, None, None, None, None),  #then nothing for 100 steps
                (50, 10, SimpleEnemy, (), {}),  #then another 10 enemies over 50 steps
                (30, 1, lambda game=game: SuperRichardEnemy(game,health=wave/2.5*1500), (), {}),
            ]

            enemies = self.generate_sub_waves(sub_waves)

        else:  #11 <= wave <= 20
            #Now it's going to get hectic

            sub_waves = [
                (
                    int(13 * wave),  #total steps
                    int(25 * wave ** (wave / 50)),  #number of enemies
                    SimpleEnemy,  #enemy constructor
                    (),  #positional arguments to provide to enemy constructor
                    {},  #keyword arguments to provide to enemy constructor
                ),
                (
                    int(13 * wave),  #total steps
                    int(25 * wave ** (wave / 50)),  #number of enemies
                    HardenedEnemy,  #enemy constructor
                    (),  #positional arguments to provide to enemy constructor
                    {},  #keyword arguments to provide to enemy constructor
                ),
                (
                    int(2 * wave),  #total steps
                    int(wave/8 + 1),  #number of enemies
                    lambda game=game: SuperRichardEnemy(game),  #enemy constructor
                    (),  #positional arguments to provide to enemy constructor
                    {},  #keyword arguments to provide to enemy constructor
                ),

            ]
            enemies = self.generate_sub_waves(sub_waves)

        return enemies
コード例 #7
0
    def get_wave(self, wave):
        """Returns enemies in the 'wave_n'th wave

        Parameters:
            wave_n (int): The nth wave

        Return:
            list[tuple[int, AbstractEnemy]]: A list of (step, enemy) pairs in the
                                             wave, sorted by step in ascending order 
        """
        enemies = []

        if wave == 1:
            # A hardcoded singleton list of (step, enemy) pairs

            enemies = [(10, SimpleEnemy())]
        elif wave == 2:
            # A hardcoded list of multiple (step, enemy) pairs

            enemies = [(10, SimpleEnemy()), (15, SimpleEnemy()),
                       (30, SimpleEnemy())]
        elif 3 <= wave < 10:
            # List of (step, enemy) pairs spread across an interval of time (steps)

            steps = int(
                40 *
                (wave**.5))  # The number of steps to spread the enemies across
            count = wave * 2  # The number of enemies to spread across the (time) steps

            for step in self.generate_intervals(steps, count):
                enemies.append((step, SimpleEnemy()))

        elif wave == 10:
            # Generate sub waves
            sub_waves = [
                # (steps, number of enemies, enemy constructor, args, kwargs)
                (50, 10, SimpleEnemy, (), {}),  # 10 enemies over 50 steps
                (100, None, None, None, None),  # then nothing for 100 steps
                (50, 10, SimpleEnemy, (), {}
                 )  # then another 10 enemies over 50 steps
            ]

            enemies = self.generate_sub_waves(sub_waves)

        elif 11 <= wave < 15:
            # Now it's going to get hectic

            sub_waves = [
                (
                    int(10 * wave),  # total steps
                    int(20 * wave * (wave / 40)),  # number of enemies
                    SimpleEnemy,  # enemy constructor
                    (),  # positional arguments to provide to enemy constructor
                    {},  # keyword arguments to provide to enemy constructor
                ),
                # ...
            ]
            enemies = self.generate_sub_waves(sub_waves)

        elif 15 <= wave <= 19:
            sub_waves = [
                # (steps, number of enemies, enemy constructor, args, kwargs)
                (100, 15, SimpleEnemy, (), {}),  # 15 enemies over 100 steps
                (50, None, None, None, None),  # then nothing for 50 steps
                (50, 15, InvincibleEnemy, (), {})  # then another 15
                #invincible enemies over 50 steps
            ]

            enemies = self.generate_sub_waves(sub_waves)

        else:  #20th wave
            # This is gonna be impossible

            enemies = [(20, SimpleEnemy()), (30, InvincibleEnemy()),
                       (50, AdvancedEnemy())]

            #3.2 Advanced Enemy Message
            messagebox.showinfo("Quick!",
                                "Kill Advanced Enemy before it kills you!")

        return enemies
コード例 #8
0
    def get_wave(self, wave):
        """Returns enemies in the 'wave_n'th wave

        Parameters:
            wave_n (int): The nth wave

        Return:
            list[tuple[int, AbstractEnemy]]: A list of (step, enemy) pairs in the
                                             wave, sorted by step in ascending order
        """
        enemies = []

        if wave == 1:
            # A hardcoded singleton list of (step, enemy) pairs

            enemies = [(10, custom.AdvancedEnemy())]
        elif wave == 2:
            # A hardcoded list of multiple (step, enemy) pairs

            enemies = [(10, custom.CustomEnemy()), (15, SimpleEnemy()),
                       (30, custom.CustomEnemy())]
        elif 3 <= wave < 10:
            # List of (step, enemy) pairs spread across an interval of time (steps)

            steps = int(
                40 *
                (wave**.5))  # The number of steps to spread the enemies across
            count = wave * 2  # The number of enemies to spread across the (time) steps
            counter = 0  # The counter to generate different enemies.

            for step in self.generate_intervals(steps, count):
                if counter % 2 == 0:
                    enemies.append((step, SimpleEnemy()))
                else:
                    enemies.append((step, custom.CustomEnemy()))
                counter += 1

        elif wave == 10:
            # Generate sub waves
            sub_waves = [
                # (steps, number of enemies, enemy constructor, args, kwargs)
                (150, 5, custom.AdvancedEnemy, (), {}
                 ),  # 5 advanced enemies over 150 steps
                (100, None, None, None, None),  # then nothing for 100 steps
                (50, 10, custom.CustomEnemy, (), {})
                # then 10 energy enemies over 50 steps
            ]

            enemies = self.generate_sub_waves(sub_waves)
        elif 10 < wave <= 20:
            # Now it's going to get hectic

            sub_waves = [
                (
                    int(13 * wave),  # total steps
                    int(25 * wave**(wave / 50)),  # number of enemies
                    SimpleEnemy,  # enemy constructor
                    (),  # positional arguments to provide to enemy constructor
                    {},  # keyword arguments to provide to enemy constructor
                ),
                # ...
            ]
            enemies = self.generate_sub_waves(sub_waves)
        elif 20 < wave <= 30:  # Creates all types enemy for each wave.
            # List of (step, enemy) pairs spread across an interval of time (steps)
            steps = int(
                120 * ((wave - 17)**
                       .5))  # The number of steps to spread the enemies across
            count = (
                wave - 20
            )  # The number of enemies to spread across the (time) steps

            for step in self.generate_intervals(steps, count):
                enemies.append((step, custom.AdvancedEnemy()))
                enemies.append(((step + 15), custom.CustomEnemy()))
                enemies.append(((step + 20), custom.CustomEnemy()))
                enemies.append(((step + 25), SimpleEnemy()))
                enemies.append(((step + 30), SimpleEnemy()))

        return enemies