| | |
Text RPG Help
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2008
Posts: 60
Reputation:
Solved Threads: 0
Hello all,
My code isnt working. It is supposed to be a RPG World of Warcraft game lol.
1) When I have
2) My deleteItem() function dosnt work, is their another way to do this?
Here is the code:
My code isnt working. It is supposed to be a RPG World of Warcraft game lol.
1) When I have
c++ Syntax (Toggle Plain Text)
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:
c++ Syntax (Toggle Plain Text)
#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"); } }
•
•
•
•
1) When I havec++ Syntax (Toggle Plain Text)
if (inventory.size() == MAX_ITEMS) { inventory.push_back("Rusty Armor"); } else { deleteItem(); }
I think you meant to use
inventory.size() != MAX_ITEMS What are all those if() and array swaps in deleteItem()? It's unreadable, learn how to use loops.
Last edited by MosaicFuneral; Apr 6th, 2009 at 6:35 pm.
"Jedenfalls bin ich überzeugt, daß der Alte nicht würfelt."
"I became very sensitive to what will happen to all this and all of us." -Two geniuses named Albert
"I became very sensitive to what will happen to all this and all of us." -Two geniuses named Albert
•
•
Join Date: May 2008
Posts: 60
Reputation:
Solved Threads: 0
Well first:
OMG!!! I dont know what you were trying to mean by OMG and
but I did not KNOW about vector erase()!!!!!
2nd Their were 6 armors:
OMG!!! I dont know what you were trying to mean by OMG and
but I did not KNOW about vector erase()!!!!!2nd Their were 6 armors:
c++ Syntax (Toggle Plain Text)
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");
Last edited by gangsta gama; Apr 7th, 2009 at 8:15 pm.
Time to familiarize yourself with it: http://www.cplusplus.com/reference/stl/vector/erase/
"Jedenfalls bin ich überzeugt, daß der Alte nicht würfelt."
"I became very sensitive to what will happen to all this and all of us." -Two geniuses named Albert
"I became very sensitive to what will happen to all this and all of us." -Two geniuses named Albert
•
•
•
•
Well first:
OMG!!! I dont know what you were trying to mean by OMG and
I was exclaiming great surprise at the inefficiency of the code you posted.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: May 2008
Posts: 60
Reputation:
Solved Threads: 0
Again thank you for the link but, I dont get what its saying. How would I vector.erase() a variable? Like:
Is that right?
c++ Syntax (Toggle Plain Text)
cout << "What would u like to delete?" << endl; cin >> anyvar; // would I put: vector.erase(anyvar);
Is that right?
![]() |
Similar Threads
- Help me play-test my text adventure? (beginner) (Python)
- Help with text RPG and class (C++)
- Text RPG (Visual Basic 4 / 5 / 6)
- rpg phping, fighting sparring please look (PHP)
- Please Review My Harry Potter Rpg Site! (Website Reviews)
- Enhancing a Text based RPG (C++)
Other Threads in the C++ Forum
- Previous Thread: i need help using getlien and strtok, any ideas?
- Next Thread: semaphore.
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream image input int java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






