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()
def __init__( self, player: Actor, ): self.event_handler: EventHandler = MainGameEventHandler(self) self.message_log = MessageLog() self.mouse_location = (0, 0) self.player = player
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
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
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
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)
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
def __init__(self, player: Actor): self.event_handler: EventHandler = MainGameEventHandler(self) self.player = player
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