How to use the flax.component.GameOver function in flax

To help you get started, we’ve selected a few flax examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eevee / flax / flax / component.py View on Github external
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
github eevee / flax / flax / world.py View on Github external
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)
github eevee / flax / flax / world.py View on Github external
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)
github eevee / flax / flax / ui / console / game.py View on Github external
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()