コード例 #1
0
def menu(header, options, width):
    if len(options) > 26:
        raise ValueError('Cannot have a menu with more than 26 options.')
    header_text = textwrap.wrap(header, width)
    header_height = len(header_text)
    if header == '':
        header_height = 0
    height = len(options) + header_height

    # top left corner of menu
    x = var.SCREEN_WIDTH / 2 - width / 2
    y = var.SCREEN_HEIGHT / 2 - height / 2

    terminal.color(terminal.color_from_name('white'))
    terminal.bkcolor(terminal.color_from_name('transparent'))
    y_location = 0
    letter_index = ord('a')
    for line in header_text:
        terminal.printf(x, y + y_location, line)
        y_location += 1
    for option_text in options:
        text = '(' + chr(letter_index) + ')' + option_text
        terminal.printf(x, y + y_location, text)
        y_location += 1
        letter_index += 1
    terminal.refresh()

    key = terminal.read()

    # if key == terminal.TK_MOUSE_LEFT:
    #     (menu_x, menu_y) = (terminal.state(terminal.TK_MOUSE_X), terminal.state(terminal.TK_MOUSE_Y))
    #     # check if click is within the menu and on a choice
    #     if menu_x >= x and menu_x < x + width and menu_y >= y + header_height and menu_y < y + height - header_height:
    #         return menu_y
    #
    # if key == terminal.TK_MOUSE_RIGHT or key == terminal.TK_ESCAPE:
    #     return None # cancel if the player right-clicked or pressed escape
    if key == terminal.TK_ENTER and terminal.check(terminal.TK_ALT):
        # alt+enter changes fullscreen
        fullscreen = terminal.check(terminal.TK_FULLSCREEN)
        fullscreen = not fullscreen
        terminal.set('window.fullscreen=' + fullscreen)

    if terminal.check(terminal.TK_WCHAR):
        index = terminal.state(terminal.TK_WCHAR) - ord('a')
        if index >= 0 and index < len(options):
            return index
        return None

    terminal.clear()
    return None
コード例 #2
0
def main():
    terminal.open()

    # generate opening scene
    UIManager.push(TitleScene())
    key = 0
    shift_down = False

    # main game loop
    while key != terminal.TK_CLOSE:
        terminal.clear()
        UIManager.render()
        terminal.refresh()
        GAME.scheduler.process()
        key = terminal.read()
        shift_down = bool(terminal.check(terminal.TK_SHIFT))
        player_cmd = UIManager.peek().handle_input(key, shift_down)
        GAME.player.push_player_action(player_cmd)

        # if no UIs to show, game is closed
        if UIManager.empty:
            break

    # cleanup
    UIManager.clear()  # if the close button was clicked with UIs on the stack
    terminal.close()
コード例 #3
0
ファイル: text_input.py プロジェクト: phomm/blt_samples
def test_text_input():
    blt.set("window.title='Omni: text input'")
    blt.composition(False)

    max_chars = 32
    text = ""
    character = ' '
    result = 0
    char_result = 0

    while True:
        blt.clear()
        blt.color("white")

        blt.puts(2, 1, "Select different input tests by pressing corresponding number:")

        blt.puts(2, 3, "[color=orange]1.[/color] read_str")
        draw_frame(5, 4, max_chars + 2, 3)
        blt.puts(6, 5, "%s" % text)
        blt.puts(5 + max_chars + 2 + 1, 5, "[color=gray] %s" % ("OK" if result >= 0 else "Cancelled"))

        blt.puts(2, 8, "[color=orange]2.[/color] read_char")
        draw_frame(5, 9, 5, 3)
        blt.put(7, 10, character)
        blt.puts(11, 10, "[color=gray]%s" % key_names.get(char_result, str(char_result)))

        blt.refresh()

        key = blt.read()
        if key in (blt.TK_CLOSE, blt.TK_ESCAPE):
            break

        elif key == blt.TK_1:
            blt.color("orange")
            draw_frame(5, 4, max_chars + 2, 3)
            result, text = blt.read_str(6, 5, text, max_chars)

        elif key == blt.TK_2:
            blt.color("orange")
            draw_frame(5, 9, 5, 3)

            while True:
                blt.put(7, 10, character)  
                blt.clear_area(11, 10, 16, 1)
                blt.puts(11, 10, "[color=gray]%s" % key_names.get(char_result, str(char_result)))
                blt.refresh()

                character = ' '
                key = blt.read()
                if key in (blt.TK_ESCAPE, blt.TK_CLOSE, blt.TK_RETURN):
                    break
                elif blt.check(blt.TK_WCHAR):
                    character = blt.state(blt.TK_WCHAR)
                    char_result = key
                elif key < blt.TK_KEY_RELEASED:
                    char_result = key
コード例 #4
0
ファイル: game.py プロジェクト: deadhandfailsafe/downfall
def handle_keys():
    global game_state

    user_input = blt.read()

    if user_input == blt.TK_W:
        player.move(0, -1)
    elif user_input == blt.TK_S:
        player.move(0, 1)
    elif user_input == blt.TK_A:
        player.move(-1, 0)
    elif user_input == blt.TK_D:
        player.move(1, 0)
    elif user_input == blt.TK_Q and \
            blt.check(blt.TK_CONTROL):
        game_state = False
    elif user_input == blt.TK_G and \
            blt.check(blt.TK_SHIFT):
        ent.make_map(map_height, map_width)
コード例 #5
0
def handle_player_dead_keys(key):
    if key == terminal.TK_I:
        return {'show_inventory': True}

    if key == terminal.TK_ENTER and terminal.check(terminal.TK_ALT):
        # Alt+Enter: toggle full screen
        return {'fullscreen': True}

    elif key == terminal.TK_ESCAPE:
        # Exit the game
        return {'exit': True}
    return {}
コード例 #6
0
ファイル: main copy.py プロジェクト: caretop/partyRL
def menu(header, options, width, title=None):
    global FOV_CALCULATE

    FOV_CALCULATE = True

    menu_x = int((120 - width) // 4)

    if len(options) > 26:
        raise ValueError('Cannot have a menu with more than 26 options.')

    header_height = 2

    menu_h = int(header_height + 1 + 26)
    menu_y = int((25 - menu_h) // 2)

    # create a window

    create_window(menu_x, menu_y, width, menu_h, title)
    create_window(2, 30, 27, 9, 'd')
    create_window(31, 30, 27, 9, 'd')
    create_window(60, 30, 27, 9, 'd')
    create_window(89, 30, 27, 9, 'd')

    blt.puts(menu_x, menu_y, header)

    # print all the options
    y = menu_y + header_height + 1
    letter_index = ord('a')
    for option_text in options:
        text = '(' + chr(letter_index) + ') ' + option_text
        blt.puts(menu_x, y, text)
        y += 1
        letter_index += 1

    blt.refresh()
    # present the root console to the player and wait for a key-press
    blt.set('input: filter = [keyboard]')
    while True:
        key = blt.read()
        if blt.check(blt.TK_CHAR):
            # convert the ASCII code to an index; if it corresponds to an option, return it
            key = blt.state(blt.TK_CHAR)
            index = key - ord('a')
            if 0 <= index < len(options):
                blt.set('input: filter = [keyboard, mouse+]')
                blt.composition(True)
                return index
        else:
            blt.set('input: filter = [keyboard, mouse+]')
            blt.composition(True)
            return None
コード例 #7
0
def gameinput():
    for key in read():
        if key == blt.TK_Q and blt.check(blt.TK_SHIFT):
            blt.close()
            break
        elif key == blt.TK_UP or key == blt.TK_K:
            yield ('move', 0, -1)
        elif key == blt.TK_DOWN or key == blt.TK_J:
            yield ('move', 0, 1)
        elif key == blt.TK_LEFT or key == blt.TK_H:
            yield ('move', -1, 0)
        elif key == blt.TK_RIGHT or key == blt.TK_L:
            yield ('move', 1, 0)
    yield ('quit',)
コード例 #8
0
ファイル: main.py プロジェクト: caretop/partyRL
def game_handle_keys():
    global FOV_CALCULATE

    key = blt.read()

    if key in (blt.TK_ESCAPE, blt.TK_CLOSE):
        return "QUIT"

    # Player movement
    if key == blt.TK_UP:
        PLAYER.creature.move(0, -1)
        FOV_CALCULATE = True
        return "player-moved"
    if key == blt.TK_DOWN:
        PLAYER.creature.move(0, 1)
        FOV_CALCULATE = True
        return "player-moved"
    if key == blt.TK_LEFT:
        PLAYER.creature.move(-1, 0)
        FOV_CALCULATE = True
        return "player-moved"
    if key == blt.TK_RIGHT:
        PLAYER.creature.move(1, 0)
        FOV_CALCULATE = True
        return "player-moved"

    # use the stairs if any
    if key == blt.TK_PERIOD and blt.check(blt.TK_SHIFT):
        if GAME.current_map[PLAYER.x][PLAYER.y].stairs:
            GAME.next_level()

    # items
    if key == blt.TK_G:
        ent = map_check_for_item(PLAYER.x, PLAYER.y)
        #for ent in objects:
        ent.item.pick_up(PLAYER)

    if key == blt.TK_D:
        if len(PLAYER.container.inventory) > 0:
            #drop the last item
            PLAYER.container.inventory[-1].item.drop(PLAYER.x, PLAYER.y)

    if key == blt.TK_I:
        chosen_item = inventory_menu("Inventory", PLAYER)
        if chosen_item is not None:
            if chosen_item.item:
                chosen_item.item.use(PLAYER)

    
    return "no-action"
コード例 #9
0
def blt_handle_global_input(game_state) -> str or int or None:
    
    command = {}
    if terminal.has_input():
        key = terminal.read()
        if key == terminal.TK_CLOSE:
            exit(0)
        else:
            if not 88 < key < 99 and terminal.check(terminal.TK_CHAR):
                key = chr(terminal.state(terminal.TK_CHAR))
            keymap = options.key_maps[0]
            if keymap.get(key) is not None:
                command = keymap.get(key)
    return command
コード例 #10
0
 def handle_key(self, key):
     try:
         return self.handle_move(Direction(key))
     except ValueError:
         pass
     if bearlib.check(bearlib.TK_SHIFT):
         try:
             return self.__shift_command_map[ShiftCommand(key)]()
         except ValueError:
             pass
     else:
         try:
             return self.__command_map[Command(key)]()
         except ValueError:
             pass
コード例 #11
0
def handle_player_turn_keys(key):
    # Movement keys
    if key == terminal.TK_UP or key == terminal.TK_KP_8:
        return {'move': (0, -1)}
    elif key == terminal.TK_DOWN or key == terminal.TK_KP_2:
        return {'move': (0, 1)}
    elif key == terminal.TK_LEFT or key == terminal.TK_KP_4:
        return {'move': (-1, 0)}
    elif key == terminal.TK_RIGHT or key == terminal.TK_KP_6:
        return {'move': (1, 0)}
    elif key == terminal.TK_HOME or key == terminal.TK_KP_7:
        return {'move': (-1, -1)}
    elif key == terminal.TK_PAGEUP or key == terminal.TK_KP_9:
        return {'move': (1, -1)}
    elif key == terminal.TK_END or key == terminal.TK_KP_1:
        return {'move': (-1, 1)}
    elif key == terminal.TK_PAGEDOWN or key == terminal.TK_KP_3:
        return {'move': (1, 1)}
    elif key == terminal.TK_KP_5:
        pass  # do nothing ie wait for the monster to come to you

    if key == terminal.TK_G:
        return {'pickup': True}
    elif key == terminal.TK_I:
        return {'goto_equip': True}
    elif key == terminal.TK_D:
        return {'drop_equip': True}
    elif key == terminal.TK_T:
        return {'set_target': True}

    if key == terminal.TK_ENTER and terminal.check(terminal.TK_ALT):
        # Alt+Enter: toggle full screen
        return {'fullscreen': True}
    elif key == terminal.TK_ESCAPE:
        # Exit the game
        return {'exit': True}

    if key == terminal.TK_MOUSE_LEFT:
        # Get the coordinates
        return {'left_click': [terminal.TK_MOUSE_X, terminal.TK_MOUSE_Y]}
    elif key == terminal.TK_MOUSE_RIGHT:
        # Get the coordinates
        return {'right_click': [terminal.state(terminal.TK_MOUSE_X), terminal.state(terminal.TK_MOUSE_Y)]}

    # No key was pressed
    return {}
コード例 #12
0
def blt_handle_keys(game_state, menu_dict, key = None) -> str or None:
    if key is None:
        key = terminal.read()
    command = {}
    menu_options = menu_dict.get('options')

    if key == terminal.TK_CLOSE:
        exit()
    else:
        if game_state != GameStates.menu:
            if not 88 < key < 99 and terminal.check(terminal.TK_CHAR):
                key = chr(terminal.state(terminal.TK_CHAR))
            keymap = options.key_maps[game_state.value - 1]
            command = keymap.get(key)
        elif key is not None and menu_options is not None:
            if key in menu_options:
                keymap = options.key_maps[0]
                command = keymap.get(key)

    
    return command
コード例 #13
0
    def prompt(self, check_y, check_x):
        self.view_index = 0

        self.check_y = check_y
        self.check_x = check_x

        self.move_camera()
        self._print()

        proceed = True

        while proceed:
            while terminal.has_input() and proceed:
                self.dir = terminal.read()
                if terminal.check(terminal.TK_SHIFT):
                    self.dir_shift = True
                else:
                    self.dir_shift = False

                if not self.advance_input():
                    proceed = False
コード例 #14
0
ファイル: command.py プロジェクト: szszs/Roguelike
    def command(self, uinput, game):
        if terminal.check(terminal.TK_SHIFT):
            self.shift_on = True
        else:
            self.shift_on = False

        if uinput == terminal.TK_ESCAPE:
            game.proceed = False

        elif uinput in self.move.keys():
            #p movement_time = time.clock()

            newy = game.me.y + self.move[uinput][0]
            newx = game.me.x + self.move[uinput][1]

            if game.world.check_passable(newy,
                                         newx) or uinput == terminal.TK_R:
                if self.shift_on:
                    move_action = "sprint"
                else:
                    move_action = "walk"

                game.me.do_action(move_action, (game.me, newy, newx),
                                  (game.timer.time, ), game)
            else:
                game.message_panel.add_phrase('Cannot move there.',
                                              [255, 0, 0])
                game.message_panel.print_messages()

            #p print("movement update: --- %s seconds ---" % (time.clock() - movement_time))

        elif uinput == terminal.TK_W:
            time_advance = 100
            game.update(game.timer.time + time_advance)
            game.update_screen()
            game.message_panel.add_phrase('Time advanced by ' +
                                          str(time_advance))
            game.message_panel.print_messages()

        elif uinput == terminal.TK_M:
            while not terminal.has_input():
                dir = terminal.read()
                break
            game.message_panel.add_phrase(dir, [255, 0, 0])
            game.message_panel.print_messages()

        elif uinput == terminal.TK_X:
            check_y = game.me.y
            check_x = game.me.x

            game.info_panel.open(game.bg_windows)
            game.info_panel.prompt(check_y, check_x)
            game.info_panel.exit(game.bg_windows)
            game.world.view()
            terminal.refresh()

        elif uinput == terminal.TK_H:
            for dynam_stat in game.me.dynam_stats:
                dynam_stat.alter(-1)
            game.me.printstats()

        elif uinput == terminal.TK_ENTER:
            message_test_popup = windows.text_input_popup(
                'Enter test message to be displayed on the message panel:',
                game=game,
                title='test title',
                only_ascii=False)
            message_test = message_test_popup.init()
            if message_test is not None:
                if message_test == 'Lorem Ipsum':
                    game.message_panel.add_phrase(
                        "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec lacus urna, rhoncus eget eros id, aliquet efficitur quam. Cras aliquam malesuada ex ut dapibus. Aliquam non nisl diam. Ut eget enim gravida, convallis nunc vel, consequat massa. Praesent ultricies lorem fringilla mauris lobortis, quis tincidunt velit vulputate. Aenean luctus dolor quis nisl vestibulum, tristique sagittis nisi bibendum. Cras molestie pulvinar tortor vitae elementum. Ut eu erat at neque dapibus commodo. Cras a ligula hendrerit est tincidunt accumsan. Ut sed interdum turpis, suscipit mollis eros. Suspendisse libero nunc, sodales eu diam nec, feugiat pharetra felis. Nullam vitae gravida justo. Proin volutpat vestibulum pulvinar. Aliquam gravida suscipit odio in placerat. \\v Cras est orci, dapibus vel semper nec, luctus vel nisl. Maecenas scelerisque imperdiet vestibulum. Cras sed ligula sit amet nisi dictum euismod sit amet nec lacus. Curabitur dapibus tellus nec orci luctus, nec hendrerit diam ornare. Curabitur sed ipsum a ligula vulputate iaculis. Morbi dignissim lectus vitae mattis ultricies. In sem magna, vestibulum rutrum elementum sed, maximus eu turpis. Morbi laoreet lorem diam, et porta nunc vestibulum a. Pellentesque varius hendrerit lectus, id dignissim arcu porta sit amet. Curabitur in facilisis turpis, vitae consectetur ex. Aliquam erat ipsum, porttitor a ullamcorper at, mattis ac eros. \\v Curabitur maximus efficitur interdum. Vivamus varius fermentum nibh, hendrerit laoreet elit sodales auctor. Suspendisse pellentesque turpis vel finibus varius. Phasellus vel lectus vitae odio auctor vehicula at vitae lacus. Nunc sagittis pharetra nulla, sed pharetra sem volutpat a. Aliquam finibus nulla quis metus ultrices vulputate. Pellentesque gravida fermentum quam, a fringilla sem tempor et. Suspendisse porttitor sapien ac lacinia dignissim. Mauris ante sapien, malesuada vitae eros sed, egestas aliquam ipsum. Nunc venenatis, risus sit amet gravida malesuada, erat libero egestas nisl, eu gravida velit diam sit amet nisi. In sit amet mollis ante, a dictum mi. Fusce gravida nulla id justo porta, at euismod nulla porta. In non quam ex."
                    )
                else:
                    game.message_panel.add_phrase(message_test)
                game.message_panel.print_messages()

        elif uinput == terminal.TK_A:
            proceed = True
            dir = terminal.read()
            if dir == terminal.TK_ESCAPE:
                proceed = False
            while dir not in self.move.keys() and proceed:
                dir = terminal.read()

            if proceed:
                attack_y = game.me.y + self.move[dir][0]
                attack_x = game.me.x + self.move[dir][1]

                attack_action = "smite"

                game.me.do_action(
                    attack_action,
                    (game.me, attack_y, attack_x, game.all_mobs.mob_lib),
                    (game.timer.time, ), game)

        # other possibilities
        elif uinput == terminal.TK_RESIZED:
            # print '--------------------------!!!RESIZED!!!!!!!!!!--------------------'
            # game.w_ylen = terminal.state(terminal.TK_HEIGHT)
            # game.w_xlen = terminal.state(terminal.TK_WIDTH)

            # game.world.recalc_win(game.w_ylen, game.w_xlen)

            # game.message_panel.recalc_win(game.w_ylen, game.w_xlen)

            # game.info_panel.recalc_win(game.w_ylen, game.w_xlen)

            # game.me.recalc_win(game.w_ylen, game.w_xlen)

            # game.all_mobs.recalc_win(game.w_ylen, game.w_xlen)

            # game.bg_windows.recalc_win(game.w_ylen, game.w_xlen, 0, 0, 150)

            # game.bg_windows.recalc_borders()
            # game.bg_windows.print_borders()

            self.update_view(game)

        # wizard mode
        elif uinput == terminal.TK_BACKSLASH:  # text_input_popup
            wizard_popup = windows.text_input_popup('Enter your command:',
                                                    game=game,
                                                    only_ascii=False)
            wizard_command = wizard_popup.init()
            if wizard_command:
                self.wizard_commands.process_request(wizard_command, game)
コード例 #15
0
    def take_turn(self):
        global vCount
        GameState.render_all()


        mouse = Input.mouse


        while True:

            # print "Waiting for input"

            """
            On player turn this loops continuasouly waiting for user input
            """
            Input.update()
            key = Input.key
            GameState.render_ui()



            """
            Check mouse status
            """
            mouse_click_value = self.process_mouse_clicks(mouse)
            mouse_hover_value = self.process_mouse_hover(mouse)
            if mouse_click_value > 0:
                return self.end_turn(mouse_click_value)
            if mouse_hover_value > 0:
                return self.end_turn(mouse_hover_value)


            """
            Auto-Walking
            """
            # TODO: Make autowalk pathing calculate paths based on NO monsters. Otherwise you can tell when paths are blocked. Stop when encounter...
            if GameState.continue_walking:
                self.owner.walk_path()
                # print "Auto-Walking"
                return self.end_turn(Constants.TURN_COST)
            elif not GameState.continue_walking:
                self.owner.clear_path()

            """
            Basic User Input
            """

            # TODO: Make movement cost relative to terrain. (add terrain cost to TILE)  WATER / TAR / OIL / SAND = Slower, Road / Trail = Fsater
            # TODO: Make turns not pass as you bumb into walls.

            # TODO: Add 'Auto-Explore' --- Search for Not self.Explored, path to it as if you right clicked.

            if key == terminal.TK_KP_8 or key == terminal.TK_UP:
                GameState.player_move_or_interact(0, -1)
                return self.end_turn(Constants.TURN_COST)
            elif key == terminal.TK_KP_2 or key == terminal.TK_DOWN:
                GameState.player_move_or_interact(0, 1)
                return self.end_turn(Constants.TURN_COST)
            elif key == terminal.TK_KP_4 or key == terminal.TK_LEFT:
                GameState.player_move_or_interact(-1, 0)
                return self.end_turn(Constants.TURN_COST)
            elif key == terminal.TK_KP_6 or key == terminal.TK_RIGHT:
                GameState.player_move_or_interact(1, 0)
                return self.end_turn(Constants.TURN_COST)
            elif key == terminal.TK_KP_7: # or (terminal.TK_LEFT and terminal.TK_UP):
                GameState.player_move_or_interact(-1, -1)
                return self.end_turn(Constants.TURN_COST)
            elif key == terminal.TK_KP_9:
                GameState.player_move_or_interact(1, -1)
                return self.end_turn(Constants.TURN_COST)
            elif key == terminal.TK_KP_1:
                GameState.player_move_or_interact(-1, 1)
                return self.end_turn(Constants.TURN_COST)
            elif key == terminal.TK_KP_3:
                GameState.player_move_or_interact(1, 1)
                return self.end_turn(Constants.TURN_COST)
            elif key == terminal.TK_KP_5:
                return self.end_turn(Constants.TURN_COST)
            elif key == terminal.TK_X:
                GameState.current_level.require_recompute()
                Constants.DEBUG = not Constants.DEBUG
                GameState.render_all()
            elif key == terminal.TK_G:
                # pick up an item
                for object in GameState.current_level.get_all_objects():  # look for an item in the player's tile
                    if object.x == self.owner.x and object.y == self.owner.y and object.item:
                        object.item.pick_up()
                        break
            elif key == terminal.TK_F:
                for obj in GameState.get_all_equipped(self.owner):
                    if obj.owner.ranged:
                        outcome = obj.owner.ranged.fire()
                        if outcome == 'cancelled':
                            return 0
                        else:
                            return self.end_turn(Constants.TURN_COST)
            elif key == terminal.TK_B:
                title = "Beastiary"

                text = '\n\nDrag Header to move window\n\n'

                pal = UI.Palette(width=20, height=20, title='Title', text=text)

                pal.draw()
            elif key == terminal.TK_COMMA and terminal.check(terminal.TK_SHIFT):
                # go down stairs, if the player is on them
                stairs = GameState.current_level.get_stairs()
                if stairs.x == self.owner.x and stairs.y == self.owner.y:
                    GameState.next_level()
                    return 1
            elif key == terminal.TK_ESCAPE:
                GameState.save_game()
                UI.display_mainMenu()
            elif key == terminal.TK_L:
                GameState.load_game()
                return 1
            elif key == terminal.TK_T:
                GameState.add_animation('FadeText', {'origin': (self.owner.x, self.owner.y),
                                                     'target': (self.owner.x, self.owner.y-1)})

            elif key == terminal.TK_O:
                print GameState.current_level.fov_map
            elif key == terminal.TK_RBRACKET:
                equipped_ranged = [equip.name for equip in GameState.inventory if equip.equipment.is_equipped and equip.ranged]

                if equipped_ranged[0] == "pistol":
                    new_weapon = [equip for equip in GameState.inventory if
                                       equip.name == 'laser']
                    new_weapon[0].equipment.equip()
                elif equipped_ranged[0] == "laser":
                    new_weapon = [equip for equip in GameState.inventory if
                                  equip.name == 'rpg']
                    new_weapon[0].equipment.equip()
                elif equipped_ranged[0] == "rpg":
                    new_weapon = [equip for equip in GameState.inventory if
                                  equip.name == 'ice wand']
                    new_weapon[0].equipment.equip()
                elif equipped_ranged[0] == "ice wand":
                    new_weapon = [equip for equip in GameState.inventory if
                                  equip.name == 'pistol']
                    new_weapon[0].equipment.equip()

            elif key == terminal.TK_LBRACKET:
                pass

                '''
コード例 #16
0
ファイル: map.py プロジェクト: BrettWitty/runner-rl
 def handleScroll(self, off):
     if term.check(term.TK_SHIFT):
         offset = np.array([off, 0])
     else:
         offset = np.array([0, off])
     self.moveOffset(offset)
コード例 #17
0
ファイル: handle_keys.py プロジェクト: nuzcraft/RLTut
def handle_keys():
    # movement keys
    if terminal.has_input():
        key = terminal.read()
        if var.game_state == 'playing':
            # this section is inputs that take a turn
            if key == terminal.TK_RIGHT or key == terminal.TK_KP_6:
                # move the player right
                player_move_or_attack(1, 0)
                var.fov_recompute = True
                return
            elif key == terminal.TK_LEFT or key == terminal.TK_KP_4:
                player_move_or_attack(-1, 0)
                var.fov_recompute = True
                return
            elif key == terminal.TK_UP or key == terminal.TK_KP_8:
                player_move_or_attack(0, -1)
                var.fov_recompute = True
                return
            elif key == terminal.TK_DOWN or key == terminal.TK_KP_2:
                player_move_or_attack(0, 1)
                var.fov_recompute = True
                return
            elif key == terminal.TK_HOME or key == terminal.TK_KP_7:
                # move the player up-left
                player_move_or_attack(-1, -1)
                var.fov_recompute = True
                return
            elif key == terminal.TK_PAGEUP or key == terminal.TK_KP_9:
                player_move_or_attack(1, -1)
                var.fov_recompute = True
                return
            elif key == terminal.TK_END or key == terminal.TK_KP_1:
                player_move_or_attack(-1, 1)
                var.fov_recompute = True
                return
            elif key == terminal.TK_PAGEDOWN or key == terminal.TK_KP_3:
                player_move_or_attack(1, 1)
                var.fov_recompute = True
                return
            elif key == terminal.TK_KP_5:
                var.fov_recompute = True
                return  # do nothing
            elif key == terminal.TK_G:
                # pick up an item
                for ent in var.entities:  # look for an item at the players tile
                    if ent.x == var.player.x and ent.y == var.player.y and ent.item:
                        ent.item.pick_up()
                        break
            elif key == terminal.TK_I:
                # show the inventory
                chosen_item = inventory_menu(
                    'Press the key next to an item to use it, or any other to cancel. \n'
                )
                if chosen_item is not None:
                    chosen_item.use()
            elif key == terminal.TK_D:
                # show the inventory, if an item is selected, drop it
                chosen_item = inventory_menu(
                    'Press the key next to an item to drop it, or any other to cancel.\n'
                )
                if chosen_item is not None:
                    chosen_item.drop()
        if key == terminal.TK_C:
            # show character info
            level_up_xp = var.LEVEL_UP_BASE + var.player.level * var.LEVEL_UP_FACTOR
            msgbox(
                'Character Information\n\nLevel: ' + str(var.player.level) +
                '\nExperience: ' + str(var.player.fighter.xp) +
                '\nExperience to level up: ' + str(level_up_xp) +
                '\n\nMaximum HP: ' + str(var.player.fighter.max_hp) +
                '\nAttack: ' + str(var.player.fighter.power) + '\nDefense: ' +
                str(var.player.fighter.defense), var.CHARACTER_SCREEN_WIDTH)
        if key == terminal.TK_COMMA and terminal.check(terminal.TK_SHIFT):
            # go down stairs if the player is on them
            if var.stairs.x == var.player.x and var.stairs.y == var.player.y:
                next_level()
        if key == terminal.TK_ENTER and terminal.check(terminal.TK_ALT):
            # alt+enter swaps fullscreen
            fullscreen = terminal.check(terminal.TK_FULLSCREEN)
            fullscreen = not fullscreen
            terminal.set('window.fullscreen=' + fullscreen)
        if key == terminal.TK_ESCAPE or key == terminal.TK_CLOSE:
            return 'exit'
    return 'didnt-take-turn'