return self.gametime - time ############################################################################## from fsm_ex.base_entity import EntityManager, MessageDispatcher from fsm_ex.ent_miner import Miner from fsm_ex.ent_wife import Wife ############################################################################## if __name__ == "__main__": # Initialize Manager-type objects: MASTER_CLOCK = GameClock() ENTITY_MGR = EntityManager() MSG_DISPATCHER = MessageDispatcher(MASTER_CLOCK.now, ENTITY_MGR) # Create and register entities (Miner Bob and Wife Elsa) for (ename, etype) in [(BOB, Miner), (ELSA, Wife)]: new_entity = etype(ename,MSG_DISPATCHER) ENTITY_MGR.register(new_entity) # Main Loop while 1: try: MASTER_CLOCK.update() ENTITY_MGR.update() MSG_DISPATCHER.dispatch_delayed() except GameOver: break
############################################################################## from fsm_ex.base_entity import EntityManager, MessageDispatcher from fsm_student02.ent_attacker import Attacker from fsm_student02.ent_sentry import Sentry from fsm_student02.ent_wall import Wall ############################################################################## if __name__ == "__main__": # Initialize Manager-type objects: MASTER_CLOCK = GameClock() ENTITY_MGR = EntityManager() MSG_DISPATCHER = MessageDispatcher(MASTER_CLOCK.now, ENTITY_MGR) # Create and register entities # Wall must be initialized first WALLS = Wall(CASTLE_WALL, MSG_DISPATCHER) ENTITY_MGR.register(WALLS) # Sentries and attackers must be assigned to a wall ent_list = [(ATTACKER, Attacker), (DEFENDER, Sentry)] for (ename, etype) in ent_list: new_entity = etype(ename, MSG_DISPATCHER, WALLS) ENTITY_MGR.register(new_entity) # Start FSM logic: Must be done AFTER all entities are registered.