Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def do_die(event, combatant):
# TODO player death is a little different. should be a separate component,
# probably, instead of special-casing here (yikes)
# TODO i am not actually sure if using an exception here is a good idea
from flax.entity import Player
if combatant.entity.isa(Player):
raise GameOver("you died :(", success=False)
event.world.current_map.remove(combatant.entity)
# TODO and drop inventory, and/or a corpse
def change_map(self, map_name):
# TODO this is so stupidly special-casey, but i'm not really sure how
# or when a Win should be fired. i'd copy what Die does, but that's
# kinda broken too, lol. maybe the ladder should contain this
# logic?
if map_name == '__exit__':
# TODO starting to look like IContainer needs a .has()
from flax.entity import Crown
if any(item.isa(Crown) for item in IContainer(self.player).inventory):
raise GameOver(
"you found the Crown of Meeting Expectations and escaped "
"the dungeon! good for you, seriously.",
success=True)
else:
raise GameOver(
"you leave empty-handed. well, okay then.", success=True)
# TODO refund time? or only eat it after the events succeed
self.event_queue.clear()
self.floor_plan.change_map(map_name)
def change_map(self, map_name):
# TODO this is so stupidly special-casey, but i'm not really sure how
# or when a Win should be fired. i'd copy what Die does, but that's
# kinda broken too, lol. maybe the ladder should contain this
# logic?
if map_name == '__exit__':
# TODO starting to look like IContainer needs a .has()
from flax.entity import Crown
if any(item.isa(Crown) for item in IContainer(self.player).inventory):
raise GameOver(
"you found the Crown of Meeting Expectations and escaped "
"the dungeon! good for you, seriously.",
success=True)
else:
raise GameOver(
"you leave empty-handed. well, okay then.", success=True)
# TODO refund time? or only eat it after the events succeed
self.event_queue.clear()
self.floor_plan.change_map(map_name)
rel = next(iter(rels))
event = Unequip(self.world.player, rel.to_entity)
else:
pass
else:
return key
if event:
self.world.push_player_action(event)
# TODO um, shouldn't really advance the world if the player pressed a
# bogus key
# TODO should probably use the event loop? right?
try:
self.world.advance()
except GameOver:
# TODO is there a slightly cleaner way or better place to convert
# GameOver into a main loop exit? (consider that eventually a game
# end should be handled by the UI, not by crashing and burning.)
raise urwid.ExitMainLoop
# TODO unclear when the right time to update this is
self.tile_widget.update_from_tile(
self.world.current_map.find(self.world.player))
self.status_widget.update()
self.world_widget._invalidate()