コード例 #1
0
ファイル: DivingBelt.cpp プロジェクト: sshillyer/OSU-CS
/*********************************************************************
** Function:         print_items()
** Description:      Prints all of the items in bag and presents user
**                   with a menu of options.
** Parameters:       Player* pointer
** Pre-Conditions:   Player must exist, bag can be empty though.
** Post-Conditions:  User may inspect, use, remove item; or leave menu
********************************************************************/
void DivingBelt::print_items(Player* player) {
  UserInterface::print_bar(34);
  Menu item_menu;
  item_menu.set_header("- Diving Belt Inventory -");

  if (quantity == 0) {
    item_menu.print();
    std::cout << "You are not carrying anything.\n";
  }

  // else there must be some items, build the menu and prompt user.
  else {
    for (int i = 0; i < quantity; i++) {
      if (items[i] != NULL) {
  		    item_menu.push_back(items[i]->get_label());
      }
    }
    item_menu.print(); // prints the list of items
    UserInterface::print_bar(34);

    // prompt user what to do and handle the selection
    int input = belt_menu.prompt_user();
    switch (input) {
      case 1: // "Inspect an item"
        {
          int item_index = item_menu.prompt_user();
          --item_index; // offset by 1 because menu starts at 1
          items[item_index]->inspect();
        }
        break;
      case 2: // "Use an item"
        {
          int item_index = item_menu.prompt_user();
          --item_index; // offset by 1 because menu starts at 1
          use_item(item_index, player);
        }
        break;
      case 3: // "Drop an item"
        {
          int item_index = item_menu.prompt_user();
          --item_index; // offset by 1 because menu starts at 1
          remove_item(item_index);
        }
        break;
      case 4: // "Leave inventory"
      break;
    }
  }
}
コード例 #2
0
void PlayerInst::perform_action(GameState* gs, const GameAction& action) {
	event_log("Player id=%d performing act=%d, xy=(%d,%d), frame=%d, origin=%d, room=%d, use_id=%d, use_id2=%d\n",
			this->player_entry(gs).net_id,
			action.act, action.action_x,
			action.action_y, action.frame, action.origin, action.room,
			action.use_id, action.use_id2);
	switch (action.act) {
	case GameAction::MOVE:
		return use_move(gs, action);
	case GameAction::USE_WEAPON:
		return use_weapon(gs, action);
	case GameAction::USE_SPELL:
		return use_spell(gs, action);
	case GameAction::USE_REST:
		return use_rest(gs, action);
	case GameAction::USE_PORTAL:
		return use_dngn_portal(gs, action);
	case GameAction::USE_ITEM:
		return use_item(gs, action);
	case GameAction::PICKUP_ITEM:
		return pickup_item(gs, action);
	case GameAction::DROP_ITEM:
		return drop_item(gs, action);
	case GameAction::DEEQUIP_ITEM:
		return equipment().deequip_type(action.use_id);
	case GameAction::REPOSITION_ITEM:
		return reposition_item(gs, action);
	case GameAction::CHOSE_SPELL:
		spellselect = action.use_id;
		return;
	case GameAction::PURCHASE_FROM_STORE:
		return purchase_from_store(gs, action);
	default:
		printf("PlayerInst::perform_action() error: Invalid action id %d!\n",
				action.act);
		break;
	}
}
コード例 #3
0
ファイル: player.c プロジェクト: happyponyland/smallrl
static turn_command_t process_input_map(game_t * game, int input)
{
    int move;
    item_t ** itemsel;

    switch (input)
    {
        case 'Q':
            if (prompt_yn("Do you want to quit?"))
                return turn_command_quit;
            return turn_command_void;

        case 'g':
        case ',':
            ;
            item_t * item = game->level->map[game->player.mob->position.y * game->level->width + game->player.mob->position.x].item;

            if (item == 0)
            {
                print_msg("Nothing here!");
                return turn_command_void;
            }

            char item_n[100];
            char line[MSGLEN];

            item_name(item_n, item);

            if (!try_give_item(&(game->player), item))
            {
                print_msg("You're carrying too much shit already.");
                wait();
            }
            else
            {
                snprintf(line, MSGLEN,
                         "Okay -- you now have %s.", item_n);
                print_msg(line);
                wait();
                game->level->map[game->player.mob->position.y * game->level->width + game->player.mob->position.x].item = 0;
            }

            clear_msg();
            return turn_command_complete;

        case 'd':
        case 'u':
            if (count_items(&(game->player)) == 0)
            {
                print_msg("You have no items.");
                return turn_command_void;
            }

            if (input == 'd')
                print_msg("Drop which item?");
            else if (input == 'u')
                print_msg("Use which item?");

            itemsel = list_and_select_items(&(game->player), game->player.inventory);

            /* restore view */
            clear_msg();
            draw_map(game->input_type, game->level);

            if (itemsel != NULL)
            {
                if (input == 'd')
                    drop_item(&(game->player), game->level, itemsel);
                else if (input == 'u')
                    use_item(game, itemsel);

                return turn_command_complete;
            }
            return turn_command_void;

        case '.':
            /* Rest/wait/meditate */
            return turn_command_complete;


        case ' ':
            //clear_msg();
            return turn_command_void;

        case '+':
            chaos_duel();
            return turn_command_void;

        case KEY_LEFT:
        case KEY_RIGHT:
        case KEY_UP:
        case KEY_DOWN:
            move = player_move(game, input);
            return move;

        default:
            return turn_command_void;
    }
}