我对 C++ 编码相当陌生,我正在为我正在开发的文本 RPG 开发菜单系统。您可以查看您的统计数据、查看您的库存、查看项目统计数据和丢弃项目。然而,在物品被丢弃后,被丢弃的物品所在的插槽仍然是空的,在游戏中,丢弃对象 2 是没有意义的,然后对象 3 仍然是对象 3。对象 3 应该变成 2。所以我想知道如何用我当前的代码做到这一点。
#include <iostream>
#include <string>
using namespace std;
bool running = 1;
void titleFunc();
void newGameFunc();
void menuFuncNav();
void menuFuncInfo();
void menuFuncItems();
string itemNames[] = {"Iron Short Sword", "Iron Long Sword", "Iron Two-Handed Sword", "Iron War Hammer", "Iron Mace", "Iron Dagger", "Wooden Staff", "Wooden Shield", "Oak Shortbow", "Oak Longbow", "Oak Crossbow", "Hard Leather Chest-Piece", "Hard Leather Leggings", "Soft Leather Chest-Piece", "Soft Leather Leggings", "Cloak"};
short playerItemCount = 0;
int userInput = 0;
int talkInput = 0;
int playerInfo[3];
int playerLocation = 0;
const int MAX_ITEMS = 100;
int playerItems[MAX_ITEMS][11];
void menuFuncItems()
{
int i = 0;
for( int i = 0; i < playerItemCount; i++ )
{
cout << i+1 << ": ";
cout << itemNames[playerItems[i][0]];
cout << endl;
}
cin >> i;
if( playerItems[i - 1][1] == 1 )
{
cout << "Press 1 to view stats." << endl;
cout << "Press 2 to equip." << endl;
cout << "Press 3 to discard." << endl;
cin >> userInput;
cout << endl;
if( userInput == 1 )
{
cout << "Name: " << itemNames[playerItems[i - 1][0]] << endl;
cout << "Physical Attack:" << playerItems[i - 1][2] << endl;
}
else if( userInput == 2 )
{
}
else
{
playerItems[i - 1][0]--;
playerItems[i - 1][0]--;
cout << "Item discarded." << endl;
}
}
所以在这段代码中,玩家丢弃了第一个库存槽中的物品。
- 铁长剑
- 木盾
- 硬皮胸甲
- 硬皮打底裤
丢弃第 1 项后应该变成:
- 木盾
- 硬皮胸甲
- 硬皮打底裤
对不起,如果我在帖子中做错了什么。这是我在这个网站上的第一篇文章。:) 谢谢。