Esempio n. 1
0
 def setUp(self):
     self.hero = Hero(health=100,
                      mana=50,
                      name="Yamamoto",
                      title="Samurai",
                      mana_regeneration_rate=2)
     self.enemy = Enemy(health=100, mana=100, damage=20)
Esempio n. 2
0
 def setUp(self):
     self.hero = Hero(name='Ivan',
                      title='Dr',
                      health=150,
                      mana=80,
                      mana_regeneration_rate=2)
     self.enemy = Enemy(health=150, mana=50, damage=20)
Esempio n. 3
0
def spawn_enemy():
    difficulty_choice = random.choice(["easy", "normal", "hard"])
    enemy_surface = random.choice(enemy_ships[difficulty_choice])
    enemy_ship = Ship(surface=enemy_surface)
    enemy = Enemy(ship=enemy_ship, difficulty=difficulty_choice)
    enemy.ship.pos_y = 1 - int(enemy.ship.height / 2)
    enemy.ship.pos_x = random.randint(30, W - enemy.ship.width)
    return enemy
Esempio n. 4
0
def enemy_start(settings, screen, enemies):
    global glob_last
    now = pygame.time.get_ticks()
    if now - glob_last >= 900:
        if len(enemies) < 5:
            new_enemy = Enemy(screen, settings)
            enemies.add(new_enemy)
            glob_last = now
Esempio n. 5
0
    def join(self, old_state=None):
        if old_state == 'menu':
            self.player = Player(self.width // 2, self.height - 20)
            self.enemies = [
                [],
                [],
                [],
                [],
            ]

            x = 100

            for enemies in self.enemies:
                Enemy.spawnEnemyRow(enemies, x)
                x += 50

            self.all_sprites = pygame.sprite.Group()
            self.all_sprites.add(self.player, self.enemies)
Esempio n. 6
0
 def setUp(self):
     self.hero = Hero(health=100, mana=50,
                      name="Yamamoto", title="Samurai", mana_regeneration_rate=2)
     self.enemy = Enemy(health=100, mana=100, damage=20)
     self.weapon = Weapon.generate(self.hero)
     self.spell = Spell(name="Fireball", damage=30,
                        mana_cost=50, cast_range=2)
     self.hero.learn(self.spell)
     self.hero.equip(self.weapon)
Esempio n. 7
0
    def update_scroller(self, game_state):
        if game_state["enemies"]: return
        if any([player.x <= 15 for player in game_state["players"]]): return
        for player in game_state["players"]:
            if player.x >= self.W - (self.W // 3) and player.MOV_RIGHT:
                self.SCROLL += player.speed

                for _player in game_state["players"]:
                    _player.x -= player.speed

                # spawn enemies
                for enemy in self.enemies:
                    if enemy["spawned"]: continue
                    if enemy["scroll"] <= self.SCROLL:
                        e = Enemy(enemy["template"])
                        e.set_state_handler(
                            enemy["state machine"].get_state_handler(e))
                        enemy["spawned"] = 1
                        game_state["enemies"].append(e)
                return
Esempio n. 8
0
    def __extract_enemies(self):
        self.__enemies = []
        fullPath = self.__fileDir + DEFAULT_ENEMY_FILE_NAME

        if os.path.exists(fullPath):
            with open(fullPath, 'r') as f:
                for line in csv.reader(f):
                    self.__enemies.append(
                        Enemy(name=line[0],
                              health=int(line[1]),
                              mana=int(line[2]),
                              damage=int(line[3])))
Esempio n. 9
0
 def __init__(self):
     pygame.init()
     self.settings = Settings()
     self.screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
     self.settings.screen_height = self.screen.get_rect().height
     self.settings.screen_width = self.screen.get_rect().width
     self.bg = pygame.image.load('../images/bg.png').convert()
     pygame.display.set_caption("Battle Tank")
     self.bullets = pygame.sprite.Group()
     self.player = Player(self)
     enemy = Enemy(self)
     self.enemies = pygame.sprite.Group()
     self.enemies.add(enemy)
     self.all_tanks = pygame.sprite.Group()
     self.all_tanks.add(self.player)
     self.all_tanks.add(enemy)
Esempio n. 10
0
    def __init__(self):
        pygame.init()
        self.screen = pygame.display.set_mode(
            (param.SCREEN_WIDTH, param.SCREEN_HEIGHT))
        pygame.display.set_caption('death shooter!')

        self.background = pygame.image.load(
            '../res/background/stg6bg.png').convert()  #convert???
        self.gameover_back = pygame.image.load('../res/background/cdbg05a.png')

        self.player = Player(
            '../res/player/pl00.png',
            (param.SCREEN_WIDTH / 2, param.SCREEN_HEIGHT - 200))
        self.enemys = []
        self.enemys.append(Enemy('../res/enemy/enemy.png', [200, 100]))
        #self.enemy_entrance(0, [200, 100])

        self.bonus = []

        etama2 = pygame.image.load('../res/bullet/etama2.png')
        self.field_img = etama2.subsurface((0, param.field_offset),
                                           (param.field_len, param.field_len))
        self.field_angle = 0
Esempio n. 11
0
 def check_next_map_tile(self, x, y):
     # todo: Fix Prints!!
     map_tile = self.layout[x][y]
     if map_tile == WALL:
         return False
     if map_tile == WALKABLE_PATH:
         self.set_hero_position(x, y)
         self.layout[x][y] = HERO
         return True
     if map_tile == ENEMY:
         self.set_hero_position(x, y)
         e = Enemy(health=70, mana=50, damage=15)
         f = Fight(enemy=e, hero=self.hero)
         f.start_fight()
         return True
     if map_tile == TREASURE:
         self.set_hero_position(x, y)
         self.get_treasure(self.treasure.pick_treasure())
         return True
     if map_tile == EXIT:
         print('found exit gj')
         self.set_hero_position(x, y)
         return True
Esempio n. 12
0
    def _cell_factory(self, sym, row, col):
        cls = self.__class_lookup.get(sym)

        if cls is None:
            raise ValueError(f'Unrecognized symbol: {sym}')

        obj = cls(row=row, col=col)

        if sym == Treasure.sym:
            treasure = Treasure(row=row, col=col)
            obj.trigger_enter_event(treasure)
            self.treasures.add(treasure)
        elif sym == Enemy.sym:
            enemy = Enemy(row=row,
                          col=col,
                          health=None,
                          mana=None,
                          damage=None)
            obj.trigger_enter_event(enemy)
            self.enemies.add(enemy)
        elif sym == Spawn.sym:
            self.spawnpoints.append(obj)

        return obj
Esempio n. 13
0
    def tick(self, clock):
        self.all_sprites.update()

        for enemies in self.enemies:
            Enemy.movement(enemies, self.width)
Esempio n. 14
0
'''this is going to be a manual test'''

from src.hero import Hero
from src.enemy import Enemy
from src.spell import Spell
from src.weapon import Weapon
from src.fight import Fight
from src.fight_status_bar import FightStatusBar

h = Hero(name="Genadi", title="Gopnik")

s = Spell(name="Kwass Molotov", damage=5, manaCost=10, castRange=7)
s1 = Spell(name="Magic spit", damage=10, manaCost=25, castRange=2)

w = Weapon(name="Beer Bottle", damage=25)
w1 = Weapon(name="Bat", damage=22)

h.equip(w)
h.learn(s)
h.coordinates = (0, 7)

e = Enemy()

e.learn(s1)
e.equip(w1)
e.coordinates = (0, 0)
"""
f = Fight(h, e,)
f.initialize_fight() """
Esempio n. 15
0
    def testGetScoreOfKilledEnemies(self):
        # No enemies:
        enemies = [[], [], []]
        self.assertEquals(self.board.getScoreOfKilledEnemies(enemies), 0)

        # 1 enemy at distance 1, with bomb range 1
        enemies = [[Tile.Balloom]]
        self.assertEqual(self.board.getScoreOfKilledEnemies(enemies), Enemy.getEnemy(Tile.Balloom)['points'])

        # 1 enemy at distance 1, with bomb range >1
        enemies = [[Tile.Balloom], [], []]
        self.assertEqual(self.board.getScoreOfKilledEnemies(enemies), Enemy.getEnemy(Tile.Balloom)['points'])

        # 1 enemy at distance >1
        enemies = [[], [Tile.Balloom], []]
        self.assertEqual(self.board.getScoreOfKilledEnemies(enemies), Enemy.getEnemy(Tile.Balloom)['points'])

        # 2 enemies at different distance
        enemies = [[Tile.Balloom], [], [Tile.Doll]]
        self.assertEqual(self.board.getScoreOfKilledEnemies(enemies), Enemy.getEnemy(Tile.Balloom)['points'] + 2*Enemy.getEnemy(Tile.Doll)['points'])

        # 2 enemies at same distance
        enemies = [[Tile.Doll, Tile.Balloom], [], []]
        self.assertEqual(self.board.getScoreOfKilledEnemies(enemies), Enemy.getEnemy(Tile.Balloom)['points'] + 2*Enemy.getEnemy(Tile.Doll)['points'])

        # multiple enemies at multiple distances
        enemies = [[Tile.Doll, Tile.Balloom, Tile.Doll], [], [Tile.Ovapi, Tile.Ovapi], [Tile.Pontan]]
        self.assertEqual(self.board.getScoreOfKilledEnemies(enemies), Enemy.getEnemy(Tile.Balloom)['points']
                                                                    + 2*Enemy.getEnemy(Tile.Doll)['points']
                                                                    + 4*Enemy.getEnemy(Tile.Doll)['points']
                                                                    + 8*Enemy.getEnemy(Tile.Ovapi)['points']
                                                                    + 16*Enemy.getEnemy(Tile.Ovapi)['points']
                                                                    + 32*Enemy.getEnemy(Tile.Pontan)['points'])
Esempio n. 16
0
class TestWarUnit(unittest.TestCase):
    def setUp(self):
        self.hero = Hero(health=100,
                         mana=50,
                         name="Yamamoto",
                         title="Samurai",
                         mana_regeneration_rate=2)
        self.enemy = Enemy(health=100, mana=100, damage=20)

    def test_is_alive(self):
        with self.subTest("Test if hero is alive"):
            self.assertTrue(self.hero.is_alive())

        self.hero.health = 0

        with self.subTest("Test if hero is dead"):
            self.assertFalse(self.hero.is_alive())

    def test_get_health(self):
        self.assertEqual(self.hero.get_health(), 100)

    def test_get_mana(self):
        self.assertEqual(self.hero.get_mana(), 50)

    def test_take_damage(self):
        with self.subTest("Test reduce the hero's health by damage"):
            self.hero.take_damage(10.5)
            # hero_healyh = self.hero.get_health()
            self.assertEqual(self.hero.get_health(), 89.5)

        with self.subTest("Test reduce the hero's health to negative value"):
            self.hero.take_damage(200)
            # hero_healyh = self.hero.get_health()
            self.assertEqual(self.hero.get_health(), 0)

        with self.subTest("Damage_points is positive"):
            with self.assertRaises(ValueError):
                self.hero.take_damage(-10)

        with self.subTest("Damage_points is int or float"):
            with self.assertRaises(TypeError):
                self.hero.take_damage("10.5")

    def test_take_healing(self):
        with self.subTest("healing_points is positive"):
            with self.assertRaises(AssertionError):
                self.hero.take_healing(-10)

        with self.subTest("Type of healing_points is int or float"):
            with self.assertRaises(TypeError):
                self.hero.take_healing("10")

        with self.subTest("Try to heal dead hero"):
            self.hero.health = 0
            self.assertFalse(self.hero.take_healing(10))
            # back the hero health

        self.hero.health = 50
        with self.subTest(
                "Try to heal hero with more than the max possible healing_points"
        ):
            self.hero.take_healing(200)
            self.assertEqual(self.hero.get_health(), self.hero._max_health)

        with self.subTest(
                "Is the hero's health is max possible health after the last healing - 200 points"
        ):
            self.assertEqual(self.hero.health, self.hero._max_health)

    def test_attack(self):
        weapon = Weapon(name="bow", damage=10)
        spell = Spell(name="Fireball", damage=30, mana_cost=50, cast_range=2)
        gun = Weapon(name="gun", damage=40)
        ice = Spell(name="Ice", damage=50, mana_cost=50, cast_range=1)
        self.hero.equip(weapon)
        self.hero.learn(spell)

        with self.subTest("Hero attack with spell.damage > weapon.damage"):
            self.assertEqual(self.hero.attack(), spell.damage)

        with self.subTest("Hero attack with weapon if hero dont know spell"):
            self.hero.weapon = None
            self.assertEqual(self.hero.attack(), spell.damage)

        with self.subTest("Enemy attack with only damage"):
            self.assertEqual(self.enemy.attack(), self.enemy.damage)

        with self.subTest("Enemy attack with weapon"):
            self.enemy.equip(gun)
            self.assertEqual(self.enemy.attack(), gun.damage)

        with self.subTest("Attack method by weapon"):
            self.hero.equip(weapon)
            self.assertEqual(self.hero.attack(by="weapon"), 10)

        with self.subTest("Attack method by spell"):
            self.assertEqual(self.hero.attack(by="spell"), 30)

        with self.subTest("Try to attack with non-existent weapon"):
            self.hero.weapon = None
            self.assertEqual(self.hero.attack(by="weapon"), 0)

        with self.subTest(
                "Try to attack with spell if hero's mana is lower than the Spell.mana_cost"
        ):
            with self.assertRaises(ValueError):
                self.hero.attack(by="spell")

    def test_take_mana(self):
        self.hero.take_mana(100)
        self.assertEqual(self.hero.mana, 50)

    def test_known_as(self):
        self.assertEqual(self.hero.known_as(), "Yamamoto the Samurai")

    def tearDown(self):
        self.hero = WarUnit(row=0, col=0, health=100, mana=50)
Esempio n. 17
0
def main():
    pg.init()
    pg.font.init()
    screen = pg.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
    pg.display.set_caption('My_game')
    clock = pg.time.Clock()

    # sprites
    img = load_image('player.png')
    Player.images = [img]
    img = load_image('player_shot.png')
    Player_shot.images = [img]
    img = load_image('enemy_new.png')
    Enemy.images = [img]

    # sounds
    crow_sound = load_sound('crow.wav')
    shot_sound = load_sound('shot.wav')
    shot_sound.set_volume(0.1)

    background = pg.Surface(SCREEN_RECT.size)
    background.fill(BACKGROUND_COLOR)
    screen.blit(background, (0, 0))

    pg.display.flip()

    # Создание контейнеров
    all = pg.sprite.RenderUpdates()
    shots = pg.sprite.Group()
    enemies = pg.sprite.Group()

    # Присвоение контейнеров
    Player.containers = all
    Player_shot.containers = all, shots
    Enemy.containers = all, enemies

    player = Player()
    # Таймеры появлений объектов
    gun_timer = 0
    enemy_spawn_timer = 0
    crow_sound_timer = 0
    score_delta = 0
    score = Score()
    game_over = False

    def check_quit_keys():
        for event in pg.event.get():
            if event.type == QUIT or \
                    (event.type == KEYDOWN and event.key == K_ESCAPE):
                return True

    if pg.font:
        all.add(score)

    # initialiaing fonts
    pg.font.init()
    my_font = pg.font.SysFont('Comic Sans MS', 40)
    my_font_bot = pg.font.SysFont('Comic Sans MS', 20)
    text_over = my_font.render('Game over', False, (0, 0, 0))
    text_score = my_font.render('Score: ' + str(score.score), False, (0, 0, 0))
    instruction = my_font_bot.render('Press S to start a new game ', False,
                                     (0, 0, 0))

    while player.alive():
        if check_quit_keys():
            break

        key_state = pg.key.get_pressed()
        horiz_direction = key_state[K_RIGHT] - key_state[K_LEFT]
        vert_direction = key_state[K_DOWN] - key_state[K_UP]
        player.move(horiz_direction, vert_direction)

        score_delta = 0

        for shot in shots:
            enemies_hit_list = pg.sprite.spritecollide(shot, enemies, True)
            if len(enemies_hit_list) > 0:
                if crow_sound_timer <= 0:
                    crow_sound.play()
                    crow_sound_timer = Enemy.CROW_SOUND_COOLDOWN
                shot.kill()
                score_delta += len(enemies_hit_list)
        crow_sound_timer -= 1

        if score_delta > 0:
            score.set_score_delta(score_delta)

        d = pg.sprite.spritecollide(player, enemies, True)
        if len(d) > 0:
            player.kill()
            text_score = my_font.render('Score: ' + str(score.score), False,
                                        (0, 0, 0))
            game_over = True

        if key_state[K_x]:
            if gun_timer != 0:
                gun_timer = gun_timer - 1
            else:
                Player_shot(player.get_guns()[0])
                Player_shot(player.get_guns()[1])
                shot_sound.play()
                gun_timer = Player_shot.GUN_RELOAD

        if enemy_spawn_timer != 0:
            enemy_spawn_timer = enemy_spawn_timer - 1
        else:
            Enemy()
            enemy_spawn_timer = Enemy.SPAWN_COOLDOWN

        all.clear(screen, background)
        all.update()
        pg.display.update(all.draw(screen))
        clock.tick(60)
    while game_over:
        if check_quit_keys():
            break

        key_state = pg.key.get_pressed()
        if key_state[K_s]:
            main()
            break
        screen.blit(background, (0, 0))
        screen.blit(text_over, (100, 0))
        screen.blit(text_score, (125, 100))
        screen.blit(instruction, (50, 600))
        pg.display.update()
        clock.tick(60)
    pg.quit()
Esempio n. 18
0
def init_enemy(size):
    for i in range(size):
        enemy = Enemy((random.randrange(0, WIDTH), random.randrange(0, 50)))
        enemy_sprites.add(enemy)
        all_sprites.add(enemy)
 def setUp(self):
     self.dummy = Enemy(health=100, mana=100, damage=20)
class EnemyTests(unittest.TestCase):
    def setUp(self):
        self.dummy = Enemy(health=100, mana=100, damage=20)

    def test_get_base_damage_method(self):
        self.assertEqual(self.dummy.get_base_damage(), 20)