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
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
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)
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
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)
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
def test_addHitPoints(): unit1 = Unit('SoLdIeR', 50, 100, 10) unit1.addHitPoints(40) assert unit1.hp == 90 unit1.addHitPoints(40) assert unit1.hp == 100
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
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()
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'
def test_takeDamage(): unit1 = Unit('SoLdIeR', 100, 100, 10) unit1.takeDamage(40) assert unit1.hp == 60
def test_add_hit_points(actual, expected): unit = Unit('Soldier', 100, 20) unit.hp = 50 unit.add_hit_points(actual) assert unit.hp == expected
def test_unit_to_string(): soldier = Unit('Soldier', 100, 20) assert str(soldier) == 'Soldier: (100/100), dmg: 20'
def test_counter_attack_exception(): unit1 = Unit('SoLdIeR', 100, 100, 50) unit2 = Unit('SoLdIeR', 100, 100, 210) with pytest.raises(UnitIsDeadException): unit1.attack(unit2)
def test_damage_greater_than_hp(): soldier = Unit('Soldier', 20, 20) soldier.take_damage(30) assert soldier.hp == 0
def load(self, gene): return Unit(gene=gene)
def test__check_type_exception(value2, exception_type2): soldier = Unit('SoLdIeR', 100, 100, 20) with pytest.raises(exception_type2): soldier.check_type(value2)