def run_game(vcstate): ''' The main game loop. Params: vcstate: An object that handles rendering & IO. ''' halfwidth = int(level_dim / 2) midpoint = Point(halfwidth, halfwidth) player = Player() area = Area(new_level(player, midpoint, 1, level_dim)) history = [''] vcwrapper = VCWrapper(vcstate) while True: # render & check IO vcwrapper.vcstate.render(player, area, history) time_taken = vcwrapper.run(player, area, history) if vcwrapper.done(): return if not time_taken: continue # cooldowns for abil in player.abilities: abil.cooldown = max(0, abil.cooldown - 1) # run the rest of the simulation if on_stairs(player, area): move_to_new_level(player, area, history) continue to_act = area.all_actors() while to_act: waiting_actors = [] for actor in to_act: actor_done = actor.act(area, history) if not actor_done: waiting_actors.append(actor) if waiting_actors == to_act: break to_act = waiting_actors if to_act: vcwrapper.vcstate.render(player, area, history) time.sleep(0.1) for actor in area.all_actors(): actor.end_of_turn_cleanup()