// Hero's Inventory
//arrays
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
setlocale(LC_ALL, "Russian");
const int MAX_ITEMS = 10;
string inventory[MAX_ITEMS];
int numItems = 0;
inventory[numItems++] = "sword";
inventory[numItems++] = "armor";
inventory[numItems++] = "shield";
cout << "Your items:\n";
for (int i = 0; i < numItems; ++i)
{
cout << inventory[i] << endl;
}
cout << "\nYou trade your sword for a battle axe.";
inventory[0] = "battle axe";
cout << "Your items:\n";
for (int i = 0; i < numItems; ++i)
cout << inventory[i] << endl;
cout << "\nThe item name '" << inventory[0] << "' has ";
cout << inventory[0].size() << " letters in it.\n";
cout << "\nYou find a healing potion.";
if (numItems < MAX_ITEMS)
inventory[numItems++] = "healing potion";
else
cout << "You have too many items and can't carry another";
while (true)
{
string s;
getline(cin, s);
string toadd;
if (s == "S") {
toadd = "sword";
cout << "В ваш инвентарь добавлен меч\n";
}
else if (s == "H") {
toadd = "healing potion";
cout << "В ваш инвентарь добавлена хилка\n";
}
else if (s == "A") {
toadd = "armor";
cout << "В ваш инвентарь добавлена броня\n";
}
else if (s == "D") {
if (numItems == 0)
{
cout << "You have no items in inventory!\n";
}
else {
inventory[--numItems] = "";
cout << "Из вашего инвентаря удалён предмет\n\n";
}
continue;
}
else {
cout << "Input is not correct";
}
if (numItems < MAX_ITEMS)
inventory[numItems++] = toadd;
else
cout << "You have too many items and can't carry another";
}
cout << "Your items:\n";
for (int i = 0; i < numItems; ++i)
cout << inventory[i] << endl;
return 0;
}