Ejemplo n.º 1
0
def test_attack():
    unit1 = Unit('SoLdIeR', 100, 100, 10)
    unit2 = Unit('SoLdIeR', 100, 100, 10)
    assert unit1.hp == 100
    assert unit2.hp == 100
    unit1.attack(unit2)
    assert unit1.hp == 95
    assert unit2.hp == 90
Ejemplo n.º 2
0
def test_unit_attack():
    soldier = Unit('Soldier', 100, 20)
    warrior = Unit('Warrior', 100, 20)

    assert soldier.hp == 100
    assert warrior.hp == 100

    soldier.attack(warrior)

    assert soldier.hp == 90
    assert warrior.hp == 80
Ejemplo n.º 3
0
def test_unit_attack_exception():
    soldier = Unit('Soldier', 0, 20)
    warrior = Unit('Warrior', 100, 20)

    with pytest.raises(UnitIsDeadException):
        soldier.attack(warrior)

    with pytest.raises(UnitIsDeadException):
        soldier.counter_attack(warrior)

    with pytest.raises(UnitIsDeadException):
        soldier.take_damage(warrior.damage)
Ejemplo n.º 4
0
def test_unit_constructor():
    soldier = Unit('Soldier', 100, 20)

    assert soldier.name == 'Soldier'
    assert soldier.hp == 100
    assert soldier.max_hp == 100
    assert soldier.damage == 20
Ejemplo n.º 5
0
 def _create_unit(self, unit_type, count):
     sapcing = 30
     tmp = 0
     x = 0
     while count > tmp:
         alien = Unit.create_unit(unit_type)
         alien.rect.x += x
         x = alien.rect.x + alien.width + sapcing
         tmp += 1
         self.unit_list.add(alien)
Ejemplo n.º 6
0
def alien_list(setting):
    aliens = Group()
    sapcing = 30
    tmp = 0
    count = 6
    while (count > 0):
        alien = Unit.create_unit('Alien')
        aliens.add(alien)
        alien.rect.x += tmp
        tmp = alien.rect.x + alien.width + sapcing
        count -= 1
    return aliens
Ejemplo n.º 7
0
def test_addHitPoints():
    unit1 = Unit('SoLdIeR', 50, 100, 10)
    unit1.addHitPoints(40)
    assert unit1.hp == 90

    unit1.addHitPoints(40)
    assert unit1.hp == 100
Ejemplo n.º 8
0
def test_unit_setter():
    soldier = Unit('Soldier', 100, 20)

    assert soldier.hp == 100

    soldier.hp = 50
    assert soldier.hp == 50

    soldier.hp += 50
    assert soldier.hp == 100

    soldier.hp -= 90
    assert soldier.hp == 10

    with pytest.raises(ValueError):
        soldier.hp = -100

    assert soldier.hp == 10

    with pytest.raises(ValueError):
        soldier.hp -= 100

    assert soldier.hp == 10
Ejemplo n.º 9
0
def run_game():
    pygame.init()
    ai_settings = Setting()
    gf.register_unit()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("Alien Invasion")
    ship = Unit.create_unit('Ship')
    level_manager = LevelManager(ship, screen)
    config = Config()
    config.load_config('config.json')

    while True:
        level_manager.load(config)
        while level_manager.is_end is False:
            level_manager.run()
Ejemplo n.º 10
0
def test_unit_setters():
    soldier = Unit('SoLdIeR', 100, 100, 20)
    assert soldier.hp == 100

    soldier.hp = 50
    assert soldier.hp == 50

    soldier.hp += 50
    assert soldier.hp == 100

    soldier.maxHP -= 90
    assert soldier.maxHP == 10

    with pytest.raises(ValueError):
        soldier.hp = -100

    with pytest.raises(ValueError):
        soldier.hp -= 100

    soldier.dmg = 50
    assert soldier.dmg == 50

    soldier.name = 'Ivan'
    assert soldier.name == 'Ivan'
Ejemplo n.º 11
0
def test_takeDamage():
    unit1 = Unit('SoLdIeR', 100, 100, 10)
    unit1.takeDamage(40)
    assert unit1.hp == 60
Ejemplo n.º 12
0
def test_add_hit_points(actual, expected):
    unit = Unit('Soldier', 100, 20)
    unit.hp = 50
    unit.add_hit_points(actual)
    assert unit.hp == expected
Ejemplo n.º 13
0
def test_unit_to_string():
    soldier = Unit('Soldier', 100, 20)

    assert str(soldier) == 'Soldier: (100/100), dmg: 20'
Ejemplo n.º 14
0
def test_counter_attack_exception():
    unit1 = Unit('SoLdIeR', 100, 100, 50)
    unit2 = Unit('SoLdIeR', 100, 100, 210)
    with pytest.raises(UnitIsDeadException):
        unit1.attack(unit2)
Ejemplo n.º 15
0
def test_damage_greater_than_hp():
    soldier = Unit('Soldier', 20, 20)

    soldier.take_damage(30)
    assert soldier.hp == 0
Ejemplo n.º 16
0
 def load(self, gene):
     return Unit(gene=gene)
Ejemplo n.º 17
0
def test__check_type_exception(value2, exception_type2):
    soldier = Unit('SoLdIeR', 100, 100, 20)

    with pytest.raises(exception_type2):
        soldier.check_type(value2)