예제 #1
0
파일: engine.py 프로젝트: aaoi990/hero-egg
 def __init__(self, game_map: GameMap, player: Actor):
     self.event_handler: EventHandler = MainGameEventHandler(self)
     self.game_map = game_map
     self.message_log = MessageLog(x=21, y=45, width=60, height=4)
     self.mouse_location = (0, 0)
     self.player = player
     self.update_fov()
예제 #2
0
 def __init__(
     self,
     player: Actor,
 ):
     self.event_handler: EventHandler = MainGameEventHandler(self)
     self.message_log = MessageLog()
     self.mouse_location = (0, 0)
     self.player = player
예제 #3
0
    def perform(self) -> bool:
        from input_handlers import MainGameEventHandler, InventoryEventHandler

        if not isinstance(self.entity, Actor):
            return False

        try:
            # Get the item at the index the player selected
            selected_item = self.entity.inventory.items[self.index]

            # Check if the player is trying to consume or drop an item, which can be determined by looking at the
            # "dropping" attribute in the event handler class.
            if isinstance(self.engine.event_handler, InventoryEventHandler) and self.engine.event_handler.dropping:
                self.entity.inventory.drop(selected_item, self.engine)

                # Switch the event handler back to the main game, so the inventory menu closes.
                self.engine.event_handler = MainGameEventHandler(
                    engine=self.engine)

                # Dropping an item takes a turn.
                return True

            elif selected_item.consumable:
                # Try consuming the item. It's possible the item cannot be consumed.
                item_consumed = selected_item.consumable.consume(
                    self.entity, self.engine)

                if item_consumed:
                    # Remove the item from the inventory.
                    index = self.entity.inventory.items.index(selected_item)
                    self.entity.inventory.items[index] = ''

                    # Switch the event handler back to the main game, so the inventory menu closes.
                    self.engine.event_handler = MainGameEventHandler(
                        engine=self.engine)

                    # Consuming an item takes a turn.
                    return True

        except (IndexError, AttributeError):
            self.engine.message_log.add_message(
                "Invalid entry.", (255, 255, 0))

        # An item was not consumed, so don't make a turn pass.
        return False
예제 #4
0
 def __init__(self,
              player: Actor):
     self.event_handler: EventHandler = MainGameEventHandler(self)
     self.message_log = MessageLog()
     self.mouse_location = (0, 0)
     self.player = player
     self.map_index = 0
     self.game_maps = []
     self.turn_queue = TurnQueue()
     # For the sake of laziness
     self.schedule = self.turn_queue.schedule
예제 #5
0
    def perform(self) -> bool:
        from input_handlers import InventoryEventHandler

        if isinstance(self.engine.event_handler, InventoryEventHandler):
            from input_handlers import MainGameEventHandler

            self.engine.event_handler = MainGameEventHandler(
                engine=self.engine)
        else:
            raise SystemExit()

        return False
예제 #6
0
def temp_startup():
    from generators import entity_factories
    import copy
    from engine import Engine
    from game_map import GameMap
    from input_handlers import MainGameEventHandler
    player = copy.deepcopy(entity_factories.human)
    engine = Engine(player)

    engine.game_map = GameMap(engine, DUNGEON_WIDTH, DUNGEON_HEIGHT)
    # engine.game_map = GameMap(engine, DUNGEON_WIDTH, DUNGEON_HEIGHT)
    # engine.game_map = GameMap(engine, CONSOLE_WIDTH, CONSOLE_HEIGHT)
    engine.player.place(100, 100, engine.game_map)

    return MainGameEventHandler(engine)
예제 #7
0
 def __init__(self, player: Actor):
     """
     Vars:
         player_path:
             Uses deque data structure to save player's path when the player uses mouse driven movements.
         player_dir:
             Uses tuple to save player's action direction(dx,dy) when the player uses mouse driven actions.
         actors_in_sight, items_in_sight:
             Set of actors/items that are currently in player's visible area.
         prev_actors_in_sight, prev_items_in_sight:
             Set of actors/items that was in player's visible area one turn ago.
         context:
             The actual window screen that shows the game.
         game_map:
             Current gamemap that player is in.
         world:
             Collection of entire gamemaps created.
     """
     self.event_handler: EventHandler = MainGameEventHandler(self)
     self.message_log = MessageLog(engine=self)
     self.mouse_location = (0, 0)
     self.mouse_dir = (1, 1)
     self.player = player
     self.player_path = deque([])
     self.player_dir = None
     self.actors_in_sight = set()
     self.items_in_sight = set()
     self.prev_actors_in_sight = set()
     self.prev_items_in_sight = set()
     self.game_turn = 0
     self.config = None  # Set from initialization
     self.console = None
     self.context = None
     self.camera = None
     self.world = {}
     self.game_map: GameMap = None
     self.depth: int = 0
예제 #8
0
 def __init__(self, player: Actor):
     self.event_handler: EventHandler = MainGameEventHandler(self)
     self.player = player
예제 #9
0
 def __init__(self, player: Actor):
     # The engine listens for events and updates the game map and player state (location and FOV) accordingly.
     self.event_handler: EventHandler = MainGameEventHandler(self)
     self.player = player