Hello all,
My code isnt working. It is supposed to be a RPG World of Warcraft game lol.
1) When I have
if (inventory.size() == MAX_ITEMS)
{
inventory.push_back("Rusty Armor");
}
else
{
deleteItem();
}
2) My deleteItem() function dosnt work, is their another way to do this?
Here is the code:
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
using namespace std;
char var;
char string1[100];
vector<string> inventory;
int MAX_ITEMS = 0;
string name;
int armor;
int newGame();
int loadGame();
int deleteItem();
int main()
{
cout << "WELCOME TO KYLES RPG GAME!!!" << endl << endl;
cout << "1.New Game" << endl;
cout << "2.Load Game" << endl << endl << endl;
cin >> var;
if (var == '1')
{
newGame();
}
else
{
loadGame();
}
}
int newGame()
{
inventory.push_back("Rusty Armor1");
inventory.push_back("Rusty Armor2");
inventory.push_back("Rusty Armor3");
inventory.push_back("Rusty Armor4");
inventory.push_back("Rusty Armor5");
inventory.push_back("Rusty Armor6");
system("CLS");
cout << "Your father has been fighting for the Horde ever sence you were born.";
cout << "On one day when you were twelve, a battle at a Horde's city, Terrin Mill ";
cout << "was occuring. Your father, Thrall is captured by Alliance and kept in who knows where. ";
cout << "It is your time know. Your time to train and fight against the Alliance." << endl << endl << endl << endl << endl;
system("PAUSE");
system("CLS");
cout << "You have arrived at Valley of Trails where you will train for a while." << endl << endl << endl << endl << endl;
system("PAUSE");
system("CLS");
cout << "What is your name, Orc?" << endl;
cin >> name;
system("CLS");
cout << name << ", eh? come with me I will suit you up." << endl << endl << endl << endl << endl;
system("PAUSE");
system("CLS");
cout << "My name is Kyle, I have been working with the Horde for quite a while now. ";
cout << "The first thing you will need is a bag...AH HA heres one, it has 6 slots, hope ";
cout << "you dont mind." << endl;
MAX_ITEMS = 6;
system("CLS");
cout << "Now...to get you some armor. Heres some, pretty rusty but it'll do." << endl;
if (inventory.size() == MAX_ITEMS)
{
inventory.push_back("Rusty Armor");
}
else
{
deleteItem();
}
system("PAUSE");
}
int loadGame()
{
system("PAUSE");
}
int deleteItem()
{
cout << "Sorry, inventory full. Would u like to delete an item for this item? (y or n)" << endl;
cin >> var;
switch(var)
{
case 'y':
for(int i = 0; i < inventory.size(); i++)
cout << inventory[i] << endl << endl;
cout << "Type an item that you want to delete." << endl;
cin >> string1;
if(string1 == inventory[0])
{
inventory[1] = inventory [0];
inventory[2] = inventory [1];
inventory[3] = inventory [2];
inventory[4] = inventory [3];
inventory[5] = inventory [4];
inventory[6] = inventory [5];
inventory[7] = inventory [6];
inventory[8] = inventory [7];
inventory[9] = inventory [8];
}
if(string1 == inventory[1])
{
inventory[2] = inventory [1];
inventory[3] = inventory [2];
inventory[4] = inventory [3];
inventory[5] = inventory [4];
inventory[6] = inventory [5];
inventory[7] = inventory [6];
inventory[8] = inventory [7];
inventory[9] = inventory [8];
}
if(string1 == inventory[2])
{
inventory[3] = inventory [2];
inventory[4] = inventory [3];
inventory[5] = inventory [4];
inventory[6] = inventory [5];
inventory[7] = inventory [6];
inventory[8] = inventory [7];
inventory[9] = inventory [8];
}
if(string1 == inventory[3])
{
inventory[4] = inventory [3];
inventory[5] = inventory [4];
inventory[6] = inventory [5];
inventory[7] = inventory [6];
inventory[8] = inventory [7];
inventory[9] = inventory [8];
}
if(string1 == inventory[4])
{
inventory[5] = inventory [4];
inventory[6] = inventory [5];
inventory[7] = inventory [6];
inventory[8] = inventory [7];
inventory[9] = inventory [8];
}
if(string1 == inventory[5])
{
inventory[6] = inventory [5];
inventory[7] = inventory [6];
inventory[8] = inventory [7];
inventory[9] = inventory [8];
}
if(string1 == inventory[6])
{
inventory[7] = inventory [6];
inventory[8] = inventory [7];
inventory[9] = inventory [8];
}
if(string1 == inventory[7])
{
inventory[8] = inventory [7];
inventory[9] = inventory [8];
}
if(string1 == inventory[8])
{
inventory[9] = inventory [8];
}
case 'Y':
for(int i = 0; i < inventory.size(); i++)
cout << inventory[i] << endl << endl;
cout << "Type an item that you want to delete." << endl;
cin >> string1;
if(string1 == inventory[0])
{
inventory[1] = inventory [0];
inventory[2] = inventory [1];
inventory[3] = inventory [2];
inventory[4] = inventory [3];
inventory[5] = inventory [4];
inventory[6] = inventory [5];
inventory[7] = inventory [6];
inventory[8] = inventory [7];
inventory[9] = inventory [8];
}
if(string1 == inventory[1])
{
inventory[2] = inventory [1];
inventory[3] = inventory [2];
inventory[4] = inventory [3];
inventory[5] = inventory [4];
inventory[6] = inventory [5];
inventory[7] = inventory [6];
inventory[8] = inventory [7];
inventory[9] = inventory [8];
}
if(string1 == inventory[2])
{
inventory[3] = inventory [2];
inventory[4] = inventory [3];
inventory[5] = inventory [4];
inventory[6] = inventory [5];
inventory[7] = inventory [6];
inventory[8] = inventory [7];
inventory[9] = inventory [8];
}
if(string1 == inventory[3])
{
inventory[4] = inventory [3];
inventory[5] = inventory [4];
inventory[6] = inventory [5];
inventory[7] = inventory [6];
inventory[8] = inventory [7];
inventory[9] = inventory [8];
}
if(string1 == inventory[4])
{
inventory[5] = inventory [4];
inventory[6] = inventory [5];
inventory[7] = inventory [6];
inventory[8] = inventory [7];
inventory[9] = inventory [8];
}
if(string1 == inventory[5])
{
inventory[6] = inventory [5];
inventory[7] = inventory [6];
inventory[8] = inventory [7];
inventory[9] = inventory [8];
}
if(string1 == inventory[6])
{
inventory[7] = inventory [6];
inventory[8] = inventory [7];
inventory[9] = inventory [8];
}
if(string1 == inventory[7])
{
inventory[8] = inventory [7];
inventory[9] = inventory [8];
}
if(string1 == inventory[8])
{
inventory[9] = inventory [8];
}
case 'n':
system("PAUSE");
case 'N':
system("PAUSE");
}
}