I'm building text-rpg inventory system but I'm not really sure how to properly create equipable items. For example, I can equip item which is in player inventory but I cannot identify what kind of item that is(Sword, Shield, Gloves or something else..) because item should be equiped in proper place(Helmet on head, sword in hands and so on). Is there any way to do so?
#include <iostream>
#include <vector>
#include <Windows.h>
#include <string>
using namespace std;
void Red()
{
SetConsoleTextAttribute
(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_INTENSITY);
} //Intensive red console text color.
void Green()
{
SetConsoleTextAttribute
(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_INTENSITY);
} //Intensive green console text color.
void Normal()
{
SetConsoleTextAttribute
(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE);
} //Default console text color.
struct Item{
string name; //Item name.
int price; //Item price.
int purpose; // 0 - Head, 1 - Neck, 2 - Torso, 3 - Hands, 4 - Legs, 5 - Feets.
int attribute; //Attack, Defense...
};
int main()
{
//Isn't the smartest way to do so...
Item Sword{
"Sword", //This item name is 'Short Sword'.
87, //Cost 87 gold pieces.
3, //Use this item with hands. :D.
10 //+10 attack.
};
string input; // input is for player commands.
vector<string> Equipment = { "<Empty>", "<Empty>", "<Empty>", "<Empty>", "<Empty>","<Empty>" }; //Current equipment.
vector<string> Inventory = {Sword.name}; //Player Inventory.
string InventorySlots[] = { "Head", "Neck", "Torso", "Hands", "Legs", "Feets" }; //Player parts where items can be equiped.
while (true){
cin >> input;
if (input == "equipment"){
for (int i = 0; i < 6; i++){
Normal();
cout << InventorySlots[i];
if (Equipment[i] == "<Empty>")
Red();
cout << " " << Equipment[i] << endl << endl;
}
Normal();
}
if (input == "equip"){
cout << "What do you want to equip? ";
cin >> input;
for (int i = 0; i < Inventory.size(); i++){
//Search for item player want to equip and equip it in the right place.
if (input == Inventory[i]){
//Inventory[i] = input;
//But how to identify what kind of item it is?
cout << "Successfully equiped!" << endl;
}
}
}
if(input == "inventory"){
for (int i = 0; i < Inventory.size(); i++){
cout << "______________________________________________________________" << endl;
cout << "| " << Inventory[i] << endl;
cout << "| Carried items " << Inventory.size() << " / " << 20 << endl;
cout << "|_____________________________________________________________" << endl;
}
}
}
system("PAUSE"); // or 'cin.get()'
return 0;
}