def test_units_assigned_correct_positions(self): unit = Unit(pos_x=1, pos_y=2, alignment=Alignment.ENEMY) unit2 = Unit(pos_x=2, pos_y=1, alignment=Alignment.ENEMY) level = Level(LEVEL_DATA, [unit, unit2]) self.assertEqual(level.unit_positions[2][1], unit) self.assertEqual(level.unit_positions[1][2], unit2)
def test_on_enemy_phase_movement_data_affected_by_allied_units(self): correct_data = [[1, sys.maxsize, 1], [1, sys.maxsize, sys.maxsize], [1, sys.maxsize, 1]] unit = Unit(pos_x=1, pos_y=2, alignment=Alignment.ALLY) unit2 = Unit(pos_x=2, pos_y=1, alignment=Alignment.ALLY) level = Level(LEVEL_DATA, [unit, unit2]) self.assertEqual(level.get_movement_data_with_units(False), correct_data)
def setUp(self): self.units = [] unit = Unit(pos_x=0, pos_y=2, alignment=Alignment.ENEMY) unit2 = Unit(pos_x=2, pos_y=3) self.units.append(unit) self.units.append(unit2) self.level = Level(LEVEL_DATA, self.units) self.pathfinding = PathFinding(1, 1, self.level.movement_data) self.ai = Ai(self.units, self.pathfinding, self.level)
def test_updating_unit_position_functions_correctly(self): unit = Unit(pos_x=0, pos_y=0) correct_positions = [[None, None, None], [None, None, None], [None, None, unit]] level = Level(LEVEL_DATA, [unit]) level.update_unit_position(unit, 2, 2) self.assertEqual(level.unit_positions, correct_positions)
def setUp(self): self.unit1 = Unit(2, 2) self.unit2 = Unit(3, 4) self.units = [self.unit1, self.unit2]
def setUp(self): self.unit = Unit(1, 2, name="Testboy") self.unit2 = Unit(1, 2, name="Testman") self.unit3 = Unit(1, 5, hp=20, strength=1, speed=18, defense=6) self.unit4 = Unit(1, 5, hp=20, strength=20, speed=18, defense=6)
def main(): screen_width = 640 screen_height = 640 screen = pygame.display.set_mode((screen_width, screen_height)) pygame.display.set_caption("Faux Emblem") camera = Camera(0, 0) units = [] units.append( Unit(1, 4, name="Ferdinand", strength=8, speed=6, defense=5, offset_x=camera.offset_x, offset_y=camera.offset_y)) units[0].items.append(Item(3, 3, 0)) units[0].items.append(Item(3, 3, 0)) units[0].items.append(Item(3, 3, 0)) units.append( Unit(1, 5, name="Sylvain", strength=4, speed=2, defense=8, offset_x=camera.offset_x, offset_y=camera.offset_y)) units.append( Unit(3, 6, Alignment.ENEMY, offset_x=camera.offset_x, offset_y=camera.offset_y)) units.append( Unit(6, 6, Alignment.ENEMY, offset_x=camera.offset_x, offset_y=camera.offset_y)) units.append( Unit(12, 4, Alignment.ENEMY, offset_x=camera.offset_x, offset_y=camera.offset_y)) units.append( Unit(9, 7, Alignment.ENEMY, offset_x=camera.offset_x, offset_y=camera.offset_y)) units.append( Unit(2, 5, Alignment.ENEMY, offset_x=camera.offset_x, offset_y=camera.offset_y)) pygame.font.init() font = pygame.font.SysFont("Arial", 20) font2 = pygame.font.SysFont("Arial", 14) clock = GameClock() level = [[0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1], [0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1], [0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1], [0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1]] test_level = Level(level, units) tile_map = TileMap(level) test_level.get_movement_data_with_units(True) pathfinding = PathFinding(1, 1, test_level.movement_data) target_selector = TargetSelector() enemy_ai = Ai(units, pathfinding, test_level) game_loop = GameLoop(screen, SpriteRenderer(), Cursor(1, 4, camera.offset_x, camera.offset_y), MenuCursor(), EventQueue(), units, MovementDisplay(pathfinding), font, font2, clock, target_selector, camera, test_level, tile_map, enemy_ai) pygame.init() game_loop.start() pygame.quit()
def setUp(self): self.item = Item(3, 2, ItemType.POTION.value) self.unit = Unit(1, 2) self.unit.items.append(self.item)
def setUp(self): self.cursor = Cursor(1, 2) self.unit = Unit(1, 2)
def setUp(self): self.unit = Unit(1, 2, Alignment.ALLY, 15, 5, 2, 3)
class TestUnit(unittest.TestCase): def setUp(self): self.unit = Unit(1, 2, Alignment.ALLY, 15, 5, 2, 3) def test_x_position_set_correctly(self): self.assertEqual(self.unit.position_x, 1) def test_y_position_set_correctly(self): self.assertEqual(self.unit.position_y, 2) def test_x_position_updates_correctly_(self): self.unit.update_position(3, 4) self.assertEqual(self.unit.position_x, 3) def test_y_position_updates_correctly_(self): self.unit.update_position(3, 4) self.assertEqual(self.unit.position_y, 4) def test_old_x_position_stored_correctly_on_update(self): self.unit.update_position(3, 4) self.assertEqual(self.unit.old_position_x, 1) def test_old_y_position_stored_correctly_on_update(self): self.unit.update_position(3, 4) self.assertEqual(self.unit.old_position_y, 2) def test_rect_x_set_correctly(self): self.assertEqual(self.unit.rect.x, 64) def test_rect_y_set_correctly(self): self.assertEqual(self.unit.rect.y, 128) def test_changing_offset_updates_rect_x_correctly(self): self.unit.update_offset(1, 1) self.assertEqual(self.unit.rect.x, 0) def test_changing_offset_updates_rect_y_correctly(self): self.unit.update_offset(1, 1) self.assertEqual(self.unit.rect.y, 64) def test_revert_position_reverts_x_position(self): self.unit.update_position(6, 6) self.unit.revert_position(0, 0) self.assertEqual(self.unit.position_x, 1) def test_revert_position_reverts_y_position(self): self.unit.update_position(6, 6) self.unit.revert_position(0, 0) self.assertEqual(self.unit.position_y, 2) def test_revert_position_updates_rect_x(self): self.unit.update_position(6, 6) self.unit.revert_position(0, 0) self.assertEqual(self.unit.rect.x, 64) def test_revert_position_updates_rect_y(self): self.unit.update_position(6, 6) self.unit.revert_position(0, 0) self.assertEqual(self.unit.rect.y, 128) def test_animation_frame_updates_correctly(self): current_frame = self.unit.active_sprite self.unit.update_animation() self.assertEqual(self.unit.active_sprite, current_frame + 0.1) def test_animation_frame_loops_correctly(self): self.unit.active_sprite = 15 self.unit.update_animation() self.assertEqual(self.unit.active_sprite, 0) def test_damage_changes_remaining_hp(self): self.unit.update_hp(10) self.assertEqual(self.unit.current_hp, 5) def test_lethal_damage_sets_unit_as_dead(self): self.unit.update_hp(25) self.assertEqual(self.unit.dead, True) def test_negative_damage_does_not_set_remaining_hp_above_max(self): self.unit.update_hp(-2000) self.assertEqual(self.unit.current_hp, 15) def test_deactivating_unit_works(self): self.unit.deactivate() self.assertEqual(self.unit.has_moved, True) def test_activating_unit_works(self): self.unit.deactivate() self.unit.activate() self.assertEqual(self.unit.has_moved, False)