Пример #1
0
 def inventory_menu(self, header, state):
   # show a menu with each item of the inventory as an option
   if len(self.inventory) == 0:
     options = ['Inventory is empty.']
   else:
     options = []
     for item in state.player_inventory.inventory:
       text = item.name
       if item.equipment and item.equipment.is_equipped:
         text = text + ' (on ' + item.equipment.slot + ')'
       options.append(text)
   index = self.menu.display_menu_return_index(header, options, Constants.INVENTORY_WIDTH, state.con)
   if index is None or len(self.inventory) == 0:
     state.set_player_action(Constants.NOT_VALID_KEY)
     Util.refresh(state)
     return None
   return self.inventory[index].item
Пример #2
0
  def target_tile(state, start_x=None, start_y=None):
    state.set_game_state(Constants.TARGETING)
    if start_x is None or start_y is None:
      state.set_target(state.player.x, state.player.y)
    else:
      state.set_target(start_x, start_y)
    while state.get_game_state() == Constants.TARGETING:
      Input.handle_keys(state)
      Util.refresh(state)

    if state.get_game_state() == Constants.FOUND_TARGET:
      x, y = state.get_target_coords()
      state.set_game_state(Constants.PLAYING)
    # TODO: Make target class? how to save/where to save targeting coords?
    # while
    if state.get_target_x() is None or state.get_target_y() is None:
      return Constants.CANCELLED
    state.game_map.get_map()[state.get_target_x()][state.get_target_y()].set_targeted(False)
    return state.get_target_x(), state.get_target_y()
Пример #3
0
  def spell_menu(self, header, state):
    # show a menu with each item of the inventory as an option
    if len(self.spells) == 0:
      options = ['You have no spells.']
    else:
      options = []
      for spell_name in state.player.caster.spells:
        spell = state.magic.spells[spell_name]
        text = spell_name + ' : ' + spell.description + ', mp cost: ' + str(spell.mp_cost) + ', spell range: ' + str(
          spell.range) + \
               ', spell power: ' + str(spell.power)
        options.append(text)

    index = self.menu.display_menu_return_index(header, options, Constants.INVENTORY_WIDTH, state.con)
    if index is not None:
      spell_name = options[index].split(' : ')[0]

    if index is None or len(self.spells) == 0:
      state.set_player_action(Constants.NOT_VALID_KEY)
      Util.refresh(state)
      return None
    return state.magic.spells[spell_name]
Пример #4
0
 def handle_playing_keys(key, state):
   if key.vk == libtcod.KEY_CHAR:
     if key.c == ord('k'):
       Util.player_move_or_attack(state, 0, -1)
     elif key.c == ord('j'):
       Util.player_move_or_attack(state, 0, 1)
     elif key.c == ord('h'):
       Util.player_move_or_attack(state, -1, 0)
     elif key.c == ord('l'):
       Util.player_move_or_attack(state, 1, 0)
     elif key.c == ord('y'):
       Util.player_move_or_attack(state, -1, -1)
     elif key.c == ord('u'):
       Util.player_move_or_attack(state, 1, -1)
     elif key.c == ord('b'):
       Util.player_move_or_attack(state, -1, 1)
     elif key.c == ord('n'):
       Util.player_move_or_attack(state, 1, 1)
     elif key.c == ord('.'):
       pass
     elif key.c == ord('v'):
       Input.look(state)
       state.set_player_action(Constants.NOT_VALID_KEY)
     elif key.c == ord('i'):
       chosen_item = state.player_inventory.inventory_menu(
         'Press the key next to an item to use it, or any other to cancel.\n', state)
       if chosen_item is not None:
         chosen_item.use(state)
         # else:
         #     state.set_player_action(Constants.NOT_VALID_KEY)
     elif key.c == ord('I'):
       chosen_spell = state.player_spell_inventory.spell_menu(
         'Press the key next to a spell to use it, or any other to cancel.\n', state)
       if chosen_spell is not None:
         chosen_spell.cast(state, state.player)
     elif key.c == ord('d'):
       chosen_item = state.player_inventory.inventory_menu(
         'Press the key next to an item to drop it, or any other to cancel.\n', state)
       if chosen_item is not None:
         chosen_item.drop(state)
     elif key.c == ord('g'):
       # pick up an item
       for object in state.objects:  # look for an item in the player's tile
         if object.x == state.player.x and object.y == state.player.y and object.item:
           object.item.pick_up(state)
           break
     elif key.c == ord('>'):
       padded_player_coords = Util.get_padded_coords(state.player.x, state.player.y)
       if padded_player_coords in state.stairs[state.dungeon_level][MapConstants.DOWN_STAIRS_OBJECT].keys():
         state.set_player_action(Constants.NEXT_LEVEL)
     elif key.c == ord('<'):
       padded_player_coords = Util.get_padded_coords(state.player.x, state.player.y)
       if padded_player_coords in state.stairs[state.dungeon_level][MapConstants.UP_STAIRS_OBJECT].keys():
         state.set_player_action(Constants.PREVIOUS_LEVEL)
     elif key.c == ord('c'):
       # show character information
       level_up_xp = Constants.LEVEL_UP_BASE + state.player.level * Constants.LEVEL_UP_FACTOR
       Util.show_character_screen(state, level_up_xp)
       Util.refresh(state)
     else:
       state.set_player_action(Constants.NOT_VALID_KEY)