Example #1
0
    def ev_keydown(self, event: tcod.event.KeyDown) -> Optional[Action]:
        action: Optional[Action] = None
        key = event.sym
        player = self.engine.player

        # Fancy conditional movement to make it feel right.
        if key in CURSOR_Y_KEYS:
            adjust = CURSOR_Y_KEYS[key]
            if adjust < 0 and self.cursor == 0:
                # Only move from the top to the bottom when you're on the edge.
                self.cursor = self.log_length - 1
            elif adjust > 0 and self.cursor == self.log_length - 1:
                # Same with bottom to top movement.
                self.cursor = 0
            else:
                # Otherwise move while staying clamped to the bounds of the history log.
                self.cursor = max(
                    0, min(self.cursor + adjust, self.log_length - 1))

        #exit game
        if key == tcod.event.K_ESCAPE:
            action = EscapeAction(player)

        # #start new game
        # elif key == tcod.event.K_RETURN:
        #     self.engine.event_handler = IntroScreen(self.engine).startover

        # No valid key was pressed
        return action
Example #2
0
    def ev_keydown(self, event: tcod.event.KeyDown) -> Optional[Action]:
        action: Optional[Action] = None

        key = event.sym

        if key == tcod.event.K_KP_8 or tcod.event.KP_w:
            action = MovementAction(dx=0, dy=-1)
        elif key == tcod.event.K_KP_2 or tcod.event.KP_x:
            action = MovementAction(dx=0, dy=1)
        elif key == tcod.event.K_KP_4 or tcod.event.KP_a:
            action = MovementAction(dx=-1, dy=0)
        elif key == tcod.event.K_KP_6 or tcod.event.KP_d:
            action = MovementAction(dx=1, dy=0)
        elif key == tcod.event.K_KP_7 or tcod.event.KP_q:
            action = MovementAction(dx=-1, dy=-1)
        elif key == tcod.event.K_KP_9 or tcod.event.KP_e:
            action = MovementAction(dx=1, dy=-1)
        elif key == tcod.event.K_KP_1 or tcod.event.KP_z:
            action = MovementAction(dx=-1, dy=1)
        elif key == tcod.event.K_KP_3 or tcod.event.KP_c:
            action = MovementAction(dx=1, dy=1)

        elif key == tcod.event.K_ESCAPE:
            action = EscapeAction()

        return action
    def ev_keydown(self, event: "tcod.event.KeyDown") -> Optional[Action]:
        """
        Receive key press events and return an 'Action' or None
        if no valid key was pressed

        :param event: a key press
        :return: and 'Action' or None
        """
        #  action will default to None or be assigned an 'Action'
        action: Optional[Action] = None
        # key holds which key was pressed (doesn't include modifiers like shift or alt
        key = event.sym
        # create a 'MovementAction' with the desired direction
        if key == tcod.event.K_UP:
            action = MovementAction(dx=0, dy=-1)
        elif key == tcod.event.K_DOWN:
            action = MovementAction(dx=0, dy=1)
        elif key == tcod.event.K_LEFT:
            action = MovementAction(dx=-1, dy=0)
        elif key == tcod.event.K_RIGHT:
            action = MovementAction(dx=1, dy=0)
        # if the 'escape' key is pressed return an 'EscapeAction'
        elif key == tcod.event.K_ESCAPE:
            action = EscapeAction()

        # no valid key was pressed (returns None)
        return action
Example #4
0
    def ev_keydown(self, event: tcod.event.KeyDown) -> Optional[Action]:
        action: Optional[Action] = None
        key = event.sym
        player = self.engine.player
        # print(self.task["motivation"])

        #accept/reject task
        if key == tcod.event.K_n:
            action = HandleTaskAction(player).perform(
                decision=False,
                motivation=self.task["motivation"],
                t_energyGain=self.task["T Energy Gain"],
                special=self.task["special"])
        elif key == tcod.event.K_y:
            action = HandleTaskAction(player).perform(
                decision=True,
                motivation=self.task["motivation"],
                t_energyGain=self.task["T Energy Gain"],
                special=self.task["special"])

        #quick quit game
        elif key == tcod.event.K_ESCAPE:
            action = EscapeAction(player)

        # No valid key was pressed
        return action
Example #5
0
    def ev_keydown(self, event: tcod.event.KeyDown) -> Optional[Action]:
        action: Optional[Action] = None

        key = event.sym

        if key == tcod.event.K_UP or key == tcod.event.K_KP_8:
            action = MovementAction(dx=0, dy=-1)
        elif key == tcod.event.K_DOWN or key == tcod.event.K_KP_2:
            action = MovementAction(dx=0, dy=1)
        elif key == tcod.event.K_LEFT or key == tcod.event.K_KP_4:
            action = MovementAction(dx=-1, dy=0)
        elif key == tcod.event.K_RIGHT or key == tcod.event.K_KP_6:
            action = MovementAction(dx=1, dy=0)
        elif key == tcod.event.K_KP_7:
            action = MovementAction(dx=-1, dy=-1)
        elif key == tcod.event.K_KP_9:
            action = MovementAction(dx=1, dy=-1)
        elif key == tcod.event.K_KP_1:
            action = MovementAction(dx=-1, dy=1)
        elif key == tcod.event.K_KP_3:
            action = MovementAction(dx=1, dy=1)
        elif key == tcod.event.K_ESCAPE:
            action = EscapeAction()

        # No valid key pressed
        return action
Example #6
0
    def ev_keydown(self, event: tcod.event.KeyDown) -> Optional[Action]:
        action: Optional[Action] = None

        key = event.sym

        player = self.engine.player

        if key == tcod.event.K_k:
            action = BumpAction(player, dx=0, dy=-1)
        elif key == tcod.event.K_j:
            action = BumpAction(player, dx=0, dy=1)
        elif key == tcod.event.K_h:
            action = BumpAction(player, dx=-1, dy=0)
        elif key == tcod.event.K_l:
            action = BumpAction(player, dx=1, dy=0)
        elif key == tcod.event.K_u:
            action = BumpAction(player, dx=1, dy=-1)
        elif key == tcod.event.K_y:
            action = BumpAction(player, dx=-1, dy=-1)
        elif key == tcod.event.K_b:
            action = BumpAction(player, dx=-1, dy=1)
        elif key == tcod.event.K_n:
            action = BumpAction(player, dx=1, dy=1)
        elif key == tcod.event.K_ESCAPE:
            action = EscapeAction(player)

        return action
    def ev_keydown(self, event: tcod.event.KeyDown) -> Optional[T]:
        action: Optional[Action] = None
        key = event.sym

        if key == tcod.event.K_ESCAPE:
            action = EscapeAction(self.engine.player)

        # No valid key was pressed
        return action
Example #8
0
    def ev_keydown(self, event: tcod.event.KeyDown) -> Optional[Action]:
        '''
        same as the 'MainGameEventHandler.ev_keydown()' method but only allows for 'ESC' key. Player and Engine objects are omitted.
        '''
        action: Optional[Action] = None

        key = event.SystemExit

        if key == tcod.event.K_ESCAPE:
            action = EscapeAction(self.engine.player)

        # No valud keypress, return a blank object ('None')
        return action
Example #9
0
    def ev_keydown(self, event: tcod.event.KeyDown) -> Optional[Action]:
        action: Optional[Action] = None
        key = event.sym
        if key == tcod.event.K_UP:
            action = MovementAction(dx=0, dy=-1)
        elif key == tcod.event.K_DOWN:
            action = MovementAction(dx=0, dy=1)
        elif key == tcod.event.K_LEFT:
            action = MovementAction(dx=-1, dy=0)
        elif key == tcod.event.K_RIGHT:
            action = MovementAction(dx=1, dy=0)
        elif key == tcod.event.K_ESCAPE:
            action = EscapeAction()

        return action
Example #10
0
    def ev_keydown(self, event: tcod.event.KeyDown) -> Optional[Action]:
        action: Optional[Action] = None

        key = event.sym

        player = self.engine.player

        if key in MOVE_KEYS:
            dx, dy = MOVE_KEYS[key]
            action = BumpAction(player, dx, dy)
        elif key in WAIT_KEYS:
            action = WaitAction(player)
        elif key in ESCAPE_KEYS:
            action = EscapeAction(player)

        return action
Example #11
0
    def ev_keydown(self, event: tcod.event.KeyDown) -> Optional[Action]:
        action: Optional[Action] = None
        key = event.sym
        player = self.engine.player
        # print(self.task["motivation"])

        #start game
        if key == tcod.event.K_RETURN:
            self.engine.event_handler = MainEventHandler(self.engine)

        #quick quit game
        elif key == tcod.event.K_ESCAPE:
            action = EscapeAction(player)

        # No valid key was pressed
        return action
Example #12
0
    def ev_keydown(self, event: tcod.event.KeyDown) -> None:
        action = None
        key = event.sym

        if key == tcod.event.K_UP:
            action = MovementAction(0, -1)
        elif key == tcod.event.K_DOWN:
            action = MovementAction(0, 1)
        elif key == tcod.event.K_RIGHT:
            action = MovementAction(1, 0)
        elif key == tcod.event.K_LEFT:
            action = MovementAction(-1, 0)

        elif key == tcod.event.K_ESCAPE:
            action = EscapeAction()

        return action
Example #13
0
    def ev_keydown(self, event: tcod.event.KeyDown) -> Optional[Action]:
        action: Optional[Action] = None

        key = event.sym

        if key == tcod.event.K_i:
            action = EscapeAction(engine=self.engine,
                                  entity=self.engine.player)
        else:
            index = key - ord("a")
            print(index)

            if 0 <= index <= 15:
                action = MenuSelectAction(engine=self.engine,
                                          entity=self.engine.player,
                                          index=index)

        return action
Example #14
0
    def ev_keydown(self, event: tcod.event.KeyDown) -> Optional[Action]:
        # action variable will hold whatever subclass of Action we assign it to, if no input it will store None
        action: Optional[Action] = None

        key = event.sym

        player = self.engine.player

        if key in MOVE_KEYS:
            dx, dy = MOVE_KEYS[key]
            action = BumpAction(player, dx, dy)
        elif key in WAIT_KEYS:
            action = WaitAction(player)

        elif key == tcod.event.K_ESCAPE:
            action = EscapeAction(player)

        return action
Example #15
0
    def ev_keydown(self, event: tcod.event.KeyDown) -> Optional[Action]:
        action: Optional[Action] = None

        key = event.sym

        if key == tcod.event.K_UP:
            action = BumpAction(dx=0, dy=-1)
        elif key == tcod.event.K_DOWN:
            action = BumpAction(dx=0, dy=1)
        elif key == tcod.event.K_LEFT:
            action = BumpAction(dx=-1, dy=0)
        elif key == tcod.event.K_RIGHT:
            action = BumpAction(dx=1, dy=0)

        elif key == tcod.event.K_ESCAPE:
            action = EscapeAction()

        #no valid key was pressed
        return action
Example #16
0
    def ev_keydown(self, event: tcod.event.KeyDown) -> Optional[Action]:
        action: Optional[Action] = None

        key = event.sym

        # Common arguments for player actions.
        context = (self.engine, self.engine.player)

        if key in (tcod.event.K_UP, tcod.event.K_k):
            action = BumpAction(*context, dx=0, dy=-1)
        elif key in (tcod.event.K_DOWN, tcod.event.K_j):
            action = BumpAction(*context, dx=0, dy=1)
        elif key in (tcod.event.K_LEFT, tcod.event.K_h):
            action = BumpAction(*context, dx=-1, dy=0)
        elif key in (tcod.event.K_RIGHT, tcod.event.K_l):
            action = BumpAction(*context, dx=1, dy=0)

        elif key == tcod.event.K_y:
            action = BumpAction(*context, dx=-1, dy=-1)
        elif key == tcod.event.K_u:
            action = BumpAction(*context, dx=1, dy=-1)
        elif key == tcod.event.K_b:
            action = BumpAction(*context, dx=-1, dy=1)
        elif key == tcod.event.K_n:
            action = BumpAction(*context, dx=1, dy=1)

        elif key == tcod.event.K_PERIOD:
            action = WaitAction(*context)

        elif key == tcod.event.K_ESCAPE:
            action = EscapeAction(*context)

        elif key == tcod.event.K_g:
            action = PickupAction(*context)

        elif key == tcod.event.K_i:
            action = ShowInventoryAction(*context)

        elif key == tcod.event.K_d:
            action = ShowInventoryAction(*context, dropping=True)

        # No valid key was pressed
        return action
    def ev_keydown(self, event: tcod.event.KeyDown) -> Optional[Action]:
        action: Optional[Action] = None

        key = event.sym

        player = self.engine.player

        if key == tcod.event.K_UP:
            action = BumpAction(player, dx=0, dy=-1)
        elif key == tcod.event.K_DOWN:
            action = BumpAction(player, dx=0, dy=1)
        elif key == tcod.event.K_LEFT:
            action = BumpAction(player, dx=-1, dy=0)
        elif key == tcod.event.K_RIGHT:
            action = BumpAction(player, dx=1, dy=0)

        elif key == tcod.event.K_ESCAPE:
            action = EscapeAction(player)

        return action
    def ev_keydown(self, event: tcod.event.KeyDown) -> Optional[Action]:
        # holds the subclass of action that we assign it to, if none is assigned it will remain set to none
        action: Optional[Action] = None
        # holds the key press
        key = event.sym

        if key == tcod.event.K_UP:
            action = MovementAction(dx=0, dy=-1)
        elif key == tcod.event.K_DOWN:
            action = MovementAction(dx=0, dy=1)
        elif key == tcod.event.K_LEFT:
            action = MovementAction(dx=-1, dy=0)
        elif key == tcod.event.K_RIGHT:
            action = MovementAction(dx=1, dy=0)

        elif key == tcod.event.K_ESCAPE:
            action = EscapeAction()

        # No valid key was pressed
        return action
    def ev_keydown(self, event: tcod.event.KeyDown) -> Optional[Action]:
        action: Optional[Action] = None

        key = event.sym

        player = self.engine.player

        if key in MOVE_KEYS:
            dx, dy = MOVE_KEYS[key]
            action = BumpAction(player, dx, dy)
        elif key in WAIT_KEYS:
            action = WaitAction(player)

        elif key == tcod.event.K_ESCAPE:
            action = EscapeAction(player)
        elif key == tcod.event.K_v:
            self.engine.event_handler = HistoryViewer(self.engine)

        # No valid key was pressed
        return action
Example #20
0
    def ev_keydown(self, event: tcod.event.KeyDown) -> Optional[Action]:
        # 'action' holds whatever subclass we end up assigning it to
        action: Optional[Action] = None

        # 'key' holds the key pressed.
        # Doesn't include modifiers i.e. shift, alt, ctrl
        key = event.sym

        # directional keys modify dx and dy
        if key == tcod.event.K_UP:
            action = BumpAction(dx=0, dy=-1)
        elif key == tcod.event.K_DOWN:
            action = BumpAction(dx=0, dy=1)
        elif key == tcod.event.K_LEFT:
            action = BumpAction(dx=-1, dy=0)
        elif key == tcod.event.K_RIGHT:
            action = BumpAction(dx=1, dy=0)

        elif key == tcod.event.K_ESCAPE:
            action = EscapeAction()

        return action
Example #21
0
    def ev_keydown(self, event: tcod.event.KeyDown) -> Optional[Action]:
        # Set the default action to 'none' (returned when no key/invalid key is pressed)
        action: Optional[Action] = None

        # Capture the key pressed and grab the 'player' instance from the engine object
        key = event.sym
        player = self.engine.player

        # Check if keypress matches a valid keypress in the pre-defined Dict objects
        if key in MOVE_KEYS:
            dx, dy = MOVE_KEYS[key]
            action = BumpAction(player, dx, dy)

        elif key in WAIT_KEYS:
            action = WaitAction(player)

        # The 'ESC' key returns an 'escape' action
        elif key == tcod.event.K_ESCAPE:
            action = EscapeAction(player)

        # Returns the resulting action type (defualt = 'none')
        return action
Example #22
0
    def ev_keydown(self, event: tcod.event.KeyDown) -> Optional[Action]:
        action: Optional[Action] = None

        key = event.sym

        if key == tcod.event.K_UP:
            action = MovementAction(dx=0, dy=-1)
        elif key == tcod.event.K_DOWN:
            action = MovementAction(dx=0, dy=1)
        elif key == tcod.event.K_LEFT:
            action = MovementAction(dx=-1, dy=0)
        elif key == tcod.event.K_RIGHT:
            action = MovementAction(dx=1, dy=0)

        # alt+enter
        # if key.vk == tcod.KEY_ENTER and key.lalt:
        #     return {'fullscreen': True}

        elif key == tcod.event.K_ESCAPE:
            action = EscapeAction()

        # no valid key pressed
        return action
    def ev_keydown(self, event: tcod.event.KeyDown) -> Optional[Action]:

        #action is the variable we use to hold whatever subclass of Action
        action: Optional[Action] = None

        key = event.sym

        #possible keys pressed
        if key == tcod.event.K_UP:
            action = MovementAction(dx=0, dy=-1)
        elif key == tcod.event.K_DOWN:
            action = MovementAction(dx=0, dy=1)
        elif key == tcod.event.K_LEFT:
            action = MovementAction(dx=-1, dy=0)
        elif key == tcod.event.K_RIGHT:
            action = MovementAction(dx=1, dy=0)

        #used to escape the game
        elif key == tcod.event.K_ESCAPE:
            action = EscapeAction()

        #No valid key was pressed
        return action
Example #24
0
    def ev_keydown(self, event: tcod.event.KeyDown) -> Optional[Action]:
        action: Optional[Action] = None
        key = event.sym
        modifier = event.mod
        player = self.engine.player

        #take stairs
        if key == tcod.event.K_PERIOD and modifier & (tcod.event.KMOD_LSHIFT |
                                                      tcod.event.KMOD_RSHIFT):
            return TakeStairsAction(player)

        #movement
        if key in MOVE_KEYS:
            dx, dy = MOVE_KEYS[key]
            action = BumpAction(player, dx, dy)
        elif key in WAIT_KEYS:
            action = WaitAction(player)

        #game mode
        elif key == tcod.event.K_s:
            # print("switch game mode")
            action = GameModeAction(player)

        #full message log history
        elif key == tcod.event.K_v:
            self.engine.event_handler = HistoryViewer(self.engine)

        #quit game, see score without exit app
        elif key == tcod.event.K_q:
            self.engine.event_handler = GameOverEventHandler(self.engine)

        #exit game
        elif key == tcod.event.K_ESCAPE:
            action = EscapeAction(player)

        # No valid key was pressed
        return action