def test_add_system_adds_systems(self): s1 = DummySystem() s2 = DummySystem() c = Container() c.add_system(s1) self.assertIn(s1, c._systems) self.assertNotIn(s2, c._systems)
def test_update_calls_update_on_all_systems(self): c = Container() s1 = DummySystem() c.add_system(s1) c.update() s2 = DummySystem() c.add_system(s2) c.update() self.assertEqual(s1.update_calls, 2) self.assertEqual(s2.update_calls, 1)
def test_no_coincident(self): """Target nothing if there are no coincident entities.""" container = Container() system = CursorSystem(container) cursor = Entity(PositionComponent(1, 1), CursorComponent()) first = Entity(PositionComponent(2, 2)) container.entities = [ cursor, first, ] system.check_target() self.assertIsNone(container.target)
def test_swap_second(self): """Target the first coincident entity with a RandomNumberComponent.""" container = Container() system = CursorSystem(container) cursor = Entity(PositionComponent(1, 1), CursorComponent()) first = Entity(PositionComponent(1, 1)) second = Entity(PositionComponent(1, 1), RandomNumberComponent()) container.entities = [ cursor, first, second, ] system.check_target() self.assertIs(container.target, second)
def test_stat_second(self): """Target the first coincident entity with a CombatComponent and InventoryComponent.""" container = Container() system = CursorSystem(container) cursor = Entity(PositionComponent(1, 1), CursorComponent()) first = Entity(PositionComponent(1, 1)) second = Entity(PositionComponent(1, 1), CombatComponent(0, 0, 0, 0, 0), InventoryComponent(0)) container.entities = [ cursor, first, second, ] system.check_target() self.assertIs(container.target, second)
def __init__(self): pygame.init() pygame.display.set_caption(TITLE) pygame.display.set_icon(S_PLAYER) pygame.key.set_repeat(200, 40) self.display = pygame.display.set_mode((WIDTH, HEIGHT)) self.clock = pygame.time.Clock() self.quit = False self.level_system = LevelSystem(1) self.camera_system = CameraSystem() self.fov_system = FovSystem(self.level_system.level) self.display_system = DisplaySystem(self.display, self.camera_system, self.level_system.level) self.action_system = ActionSystem(self.level_system.level) self.ai_system = AiSystem(self.level_system.level) self.input_system = InputSystem() self.player = Player(DisplayComponent(S_PLAYER, self.level_system.map.spawn[0], self.level_system.map.spawn[1], alpha=True), ActionComponent(), InputComponent(), CameraComponent(), FovComponent(self.fov_system.fov_map), name="player") self.container = Container() self.container.add_system(self.action_system) self.container.add_system(self.ai_system) self.container.add_system(self.input_system) self.container.add_system(self.display_system) self.container.add_system(self.level_system) self.container.add_system(self.fov_system) self.container.add_entity(self.player) for entity in self.level_system.map.entities: self.container.add_entity(entity)
def __init__(self): self.container = Container() self.ai_system = AISystem(self.container) self.combat_system = CombatSystem(self.container) self.cursor_system = CursorSystem(self.container) self.death_system = DeathSystem(self.container) self.display_system = DisplaySystem(self.container) self.durability_system = DurabilitySystem(self.container) self.game_state_system = GameStateSystem(self.container) self.inventory_system = InventorySystem(self.container) self.item_pickup_system = ItemPickupSystem(self.container) self.keyboard_input_system = KeyboardInputSystem(self.container) self.level_system = LevelSystem(self.container) self.message_system = MessageSystem(self.container) self.move_system = MoveSystem(self.container) self.throne_system = ThroneSystem(self.container) self.turn_order_system = TurnOrderSystem(self.container) self.vision_system = VisionSystem(self.container) self.container.systems = [ self.message_system, self.combat_system, self.ai_system, self.item_pickup_system, self.cursor_system, self.death_system, self.display_system, self.durability_system, self.game_state_system, self.inventory_system, self.keyboard_input_system, self.level_system, self.move_system, self.throne_system, self.turn_order_system, self.vision_system, ]
def test_add_entity_adds_it_to_entities(self): e = Entity() c = Container() c.add_entity(e) self.assertIn(e, c._entities)