I'm fairly new to coding in c++, and I'm working on a menu system for a text RPG I'm working on. You can view your stats, view your inventory, view item stats, and discard items. However, after the item is discarded, which ever slot the discarded item was in remains empty, and in a game it doesn't make sense to have object 2 be discarded, and then what was object number 3 remain object 3. Object 3 should become 2. So I was wondering how I could do this with my current code.
#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;
}
}
So in this code, the player discards the item in the first inventory slot.
- Iron Longsword
- Wooden shield
- Hard Leather Chest-Piece
- Hard Leather Leggings
Should become, after item 1 is discarded:
- Wooden Shield
- Hard Leather Chest-Piece
- Hard Leather Leggings
Sorry if I did something wrong in the post. This is my first post on this site. :) Thank you.