Esempio n. 1
0
    def ev_keydown(self,
                   event: tcod.event.KeyDown) -> Optional[ActionOrHandler]:
        action: Optional[Action] = None
        key = event.sym
        modifier = event.mod
        player = self.engine.player

        if key == tcod.event.K_PERIOD and modifier & (tcod.event.KMOD_LSHIFT |
                                                      tcod.event.KMOD_RSHIFT):
            return actions.TakeStairsAction(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:
            raise SystemExit()
        elif key == tcod.event.K_v:
            return HistoryViewer(self.engine)
        elif key == tcod.event.K_g:
            action = PickupAction(player)

        elif key == tcod.event.K_i:
            return InventoryActivateHandler(self.engine)
        elif key == tcod.event.K_d:
            return InventoryDropHandler(self.engine)
        elif key == tcod.event.K_c:
            return CharacterScreenEventHandler(self.engine)
        elif key == tcod.event.K_SLASH:
            return LookHandler(self.engine)

        return action
Esempio n. 2
0
    def ev_keydown(self, event: tcod.event.KeyDown) -> Optional[ActionOrHandler]:
        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:
            raise SystemExit()
        elif key == tcod.event.K_v:
            return HistoryViewer(self.engine)
        elif key == tcod.event.K_g:
            action = PickupAction(player)
        elif key == tcod.event.K_i:
            return InventoryActivateHandler(self.engine)
        elif key == tcod.event.K_d:
            return InventoryDropHandler(self.engine)
        elif key == tcod.event.K_c:
            return CharacterScreenEventHandler(self.engine)
        elif key == tcod.event.K_l:
            return LookHandler(self.engine)
        elif key == tcod.event.K_y:
            return actions.TakeStairsAction(player)

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

        key = event.sym
        modifier = event.mod

        player = self.engine.player

        if key == tcod.event.K_SPACE:
            return actions.TakeStairsAction(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:
            raise SystemExit()
        elif key == tcod.event.K_m:
            return HistoryViewer(self.engine)
        elif key == tcod.event.K_g:
            action = PickupAction(player)
        elif key == tcod.event.K_i:
            return InventoryActivateHandler(self.engine)
        elif key == tcod.event.K_SLASH:
            return LookHandler(self.engine)
        elif key == tcod.event.K_TAB:
            return ControlsEventHandler(self.engine)

        # Был нажат невалидный ключ.
        return action
Esempio n. 4
0
    def ev_keydown(self,
                   event: tcod.event.KeyDown) -> Optional[ActionOrHandler]:
        super().ev_keydown(event)
        action: Optional[Action] = None

        key = event.sym
        modifier = event.mod

        player = self.engine.player

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

        # If fullscreen was toggled, keep input handler active
        if event.sym == tcod.event.K_RETURN and event.mod & tcod.event.KMOD_ALT:
            self.engine.toggle_fullscreen()
            return None

        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:
            raise SystemExit()

        elif key == tcod.event.K_v:
            return HistoryViewer(self.engine)

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

        elif key == tcod.event.K_i:
            return InventoryActivateHandler(self.engine)

        elif key == tcod.event.K_d:
            return InventoryDropHandler(self.engine)

        elif key == tcod.event.K_c:
            return CharacterScreenEventHandler(self.engine)

        elif key == tcod.event.K_m:
            return LookHandler(self.engine)

        return action
Esempio n. 5
0
    def ev_keydown(self, event: str) -> Optional[ActionOrHandler]:
        action: Optional[Action] = None

        key = event
        modifier = event

        player = self.engine.player

        # if key == tcod.event.K_PERIOD and modifier & (
        #     tcod.event.KMOD_LSHIFT | tcod.event.KMOD_RSHIFT
        # ):

        if key == "spacebar":
            return actions.TakeStairsAction(player)
        if key == "numpad0":
            return actions.KillAllAction(player)
        if key == "numpadenter":
            return actions.SwitchViewMode(player)
        if key == "numpadadd":
            return actions.CheatTakeStairsAction(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 == "escape":
            raise SystemExit()
        elif key == "v":
            return HistoryViewer(self.engine)

        elif key == "g":
            action = PickupAction(player)

        elif key == "i":
            return InventoryActivateHandler(self.engine)
        elif key == "d":
            return InventoryDropHandler(self.engine)
        elif key == "c":
            return CharacterScreenEventHandler(self.engine)
        elif key == "/":
            return LookHandler(self.engine)

        # No valid key was pressed
        return action
Esempio n. 6
0
    def ev_keydown(self,
                   event: tcod.event.KeyDown) -> Optional[ActionOrHandler]:
        """ Registering af key presses.
         Returnerer type `None` hvis invalid key press.
         """

        action: Optional[Action] = None
        key = event.sym
        modifier = event.mod

        player = self.engine.player

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

        if key in MOVE_KEYS:
            dir_x, dir_y = MOVE_KEYS[key]
            action = BumpAction(player, dir_x, dir_y)
        elif key in WAIT_KEYS:
            action = WaitAction(player)
        # Exit the game
        elif key == tcod.event.K_ESCAPE:
            raise SystemExit(0)
        # Message Log
        elif key == tcod.event.K_v:
            return HistoryViewer(self.engine)
        # Pick up item
        elif key == tcod.event.K_g:
            action = PickUpAction(player)
        elif key == tcod.event.K_i:
            return InventoryActiveHandler(self.engine)
        elif key == tcod.event.K_d:
            return InventoryDropHandler(self.engine)
        elif key == tcod.event.K_c:
            return CharacterScreenEventHandler(self.engine)
        elif key == tcod.event.K_MINUS:
            return LookHandler(self.engine)

        # Hvis en ikke valid tast blev trykket
        return action
Esempio n. 7
0
    def ev_keydown(self,
                   event: tcod.event.KeyDown) -> Optional[ActionOrHandler]:
        #action holds whatever subclass of Action we end up assigning it to. Defaults to none.
        action: Optional[Action] = None
        #key holds the actual key that we pressed
        key = event.sym
        modifier = event.mod
        player = self.engine.player

        if key == tcod.event.K_PERIOD and modifier & (tcod.event.KMOD_LSHIFT |
                                                      tcod.event.KMOD_RSHIFT):
            return actions.TakeStairsAction(player)
        #create a MovementAction for the up, down, left and right keys if any of them are pressed
        if key in MOVE_KEYS:
            dx, dy = MOVE_KEYS[key]
            action = BumpAction(player, dx, dy)
        elif key in WAIT_KEYS:
            action = WaitAction(player)

        #if the user presses the escape key, return EscapeAction, which will exit the game. This will exit menus in the future
        elif key == tcod.event.K_ESCAPE:
            raise SystemExit()

        elif key == tcod.event.K_v:
            return HistoryViewer(self.engine)

        elif key == tcod.event.K_e:
            action = PickupAction(player)

        elif key == tcod.event.K_i:
            return InventoryActivateHandler(self.engine)
        elif key == tcod.event.K_d:
            return InventoryDropHandler(self.engine)
        elif key == tcod.event.K_SLASH:
            return LookHandler(self.engine)
        elif key == tcod.event.K_c:
            return CharacterScreenEventHandler(self.engine)

        #Whether a valid key is pressed or not, we return the value of action, which is none by default.
        return action
Esempio n. 8
0
    def ev_keydown(self,
                   event: tcod.event.KeyDown) -> Optional[ActionOrHandler]:
        action: Optional[Action] = None

        key = event.sym
        modifier = event.mod

        player = self.engine.player

        if key == tcod.event.K_PERIOD and modifier & (tcod.event.KMOD_LSHIFT |
                                                      tcod.event.KMOD_RSHIFT):
            if self.engine.game_world.current_floor == 8:
                return WinEventHandler(self.engine)
            else:
                return actions.TakeStairsAction(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:
            raise SystemExit()
        elif key == tcod.event.K_v:
            return HistoryViewer(self.engine)
        elif key == tcod.event.K_g:
            action = PickupAction(player)
        elif key == tcod.event.K_i:
            return InventoryActivateHandler(self.engine)
        elif key == tcod.event.K_d:
            return InventoryDropHandler(self.engine)
        elif key == tcod.event.K_c:
            return CharacterScreenEventHandler(self.engine)
        elif key == tcod.event.K_q:
            return ControlsScreenEventHandler(self.engine)

        # No valid key was pressed
        return action