Text RPG Help

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2008
Posts: 60
Reputation: gangsta gama is an unknown quantity at this point 
Solved Threads: 0
gangsta gama gangsta gama is offline Offline
Junior Poster in Training

Text RPG Help

 
0
  #1
Apr 6th, 2009
Hello all,
My code isnt working. It is supposed to be a RPG World of Warcraft game lol.

1) When I have
  1. if (inventory.size() == MAX_ITEMS)
  2. {
  3. inventory.push_back("Rusty Armor");
  4. }
  5. else
  6. {
  7. deleteItem();
  8. }

2) My deleteItem() function dosnt work, is their another way to do this?

Here is the code:
  1. #include<iostream>
  2. #include<fstream>
  3. #include<string>
  4. #include<vector>
  5. using namespace std;
  6.  
  7. char var;
  8. char string1[100];
  9. vector<string> inventory;
  10. int MAX_ITEMS = 0;
  11. string name;
  12. int armor;
  13. int newGame();
  14. int loadGame();
  15. int deleteItem();
  16.  
  17. int main()
  18. {
  19. cout << "WELCOME TO KYLES RPG GAME!!!" << endl << endl;
  20. cout << "1.New Game" << endl;
  21. cout << "2.Load Game" << endl << endl << endl;
  22. cin >> var;
  23. if (var == '1')
  24. {
  25. newGame();
  26. }
  27. else
  28. {
  29. loadGame();
  30. }
  31. }
  32.  
  33. int newGame()
  34. {
  35. inventory.push_back("Rusty Armor1");
  36. inventory.push_back("Rusty Armor2");
  37. inventory.push_back("Rusty Armor3");
  38. inventory.push_back("Rusty Armor4");
  39. inventory.push_back("Rusty Armor5");
  40. inventory.push_back("Rusty Armor6");
  41. system("CLS");
  42. cout << "Your father has been fighting for the Horde ever sence you were born.";
  43. cout << "On one day when you were twelve, a battle at a Horde's city, Terrin Mill ";
  44. cout << "was occuring. Your father, Thrall is captured by Alliance and kept in who knows where. ";
  45. cout << "It is your time know. Your time to train and fight against the Alliance." << endl << endl << endl << endl << endl;
  46. system("PAUSE");
  47. system("CLS");
  48. cout << "You have arrived at Valley of Trails where you will train for a while." << endl << endl << endl << endl << endl;
  49. system("PAUSE");
  50. system("CLS");
  51. cout << "What is your name, Orc?" << endl;
  52. cin >> name;
  53. system("CLS");
  54. cout << name << ", eh? come with me I will suit you up." << endl << endl << endl << endl << endl;
  55. system("PAUSE");
  56. system("CLS");
  57. cout << "My name is Kyle, I have been working with the Horde for quite a while now. ";
  58. cout << "The first thing you will need is a bag...AH HA heres one, it has 6 slots, hope ";
  59. cout << "you dont mind." << endl;
  60. MAX_ITEMS = 6;
  61. system("CLS");
  62. cout << "Now...to get you some armor. Heres some, pretty rusty but it'll do." << endl;
  63. if (inventory.size() == MAX_ITEMS)
  64. {
  65. inventory.push_back("Rusty Armor");
  66. }
  67. else
  68. {
  69. deleteItem();
  70. }
  71. system("PAUSE");
  72. }
  73.  
  74. int loadGame()
  75. {
  76. system("PAUSE");
  77. }
  78.  
  79. int deleteItem()
  80. {
  81. cout << "Sorry, inventory full. Would u like to delete an item for this item? (y or n)" << endl;
  82. cin >> var;
  83. switch(var)
  84. {
  85. case 'y':
  86. for(int i = 0; i < inventory.size(); i++)
  87. cout << inventory[i] << endl << endl;
  88. cout << "Type an item that you want to delete." << endl;
  89. cin >> string1;
  90. if(string1 == inventory[0])
  91. {
  92. inventory[1] = inventory [0];
  93. inventory[2] = inventory [1];
  94. inventory[3] = inventory [2];
  95. inventory[4] = inventory [3];
  96. inventory[5] = inventory [4];
  97. inventory[6] = inventory [5];
  98. inventory[7] = inventory [6];
  99. inventory[8] = inventory [7];
  100. inventory[9] = inventory [8];
  101. }
  102. if(string1 == inventory[1])
  103. {
  104. inventory[2] = inventory [1];
  105. inventory[3] = inventory [2];
  106. inventory[4] = inventory [3];
  107. inventory[5] = inventory [4];
  108. inventory[6] = inventory [5];
  109. inventory[7] = inventory [6];
  110. inventory[8] = inventory [7];
  111. inventory[9] = inventory [8];
  112. }
  113. if(string1 == inventory[2])
  114. {
  115. inventory[3] = inventory [2];
  116. inventory[4] = inventory [3];
  117. inventory[5] = inventory [4];
  118. inventory[6] = inventory [5];
  119. inventory[7] = inventory [6];
  120. inventory[8] = inventory [7];
  121. inventory[9] = inventory [8];
  122. }
  123. if(string1 == inventory[3])
  124. {
  125. inventory[4] = inventory [3];
  126. inventory[5] = inventory [4];
  127. inventory[6] = inventory [5];
  128. inventory[7] = inventory [6];
  129. inventory[8] = inventory [7];
  130. inventory[9] = inventory [8];
  131. }
  132. if(string1 == inventory[4])
  133. {
  134. inventory[5] = inventory [4];
  135. inventory[6] = inventory [5];
  136. inventory[7] = inventory [6];
  137. inventory[8] = inventory [7];
  138. inventory[9] = inventory [8];
  139. }
  140. if(string1 == inventory[5])
  141. {
  142. inventory[6] = inventory [5];
  143. inventory[7] = inventory [6];
  144. inventory[8] = inventory [7];
  145. inventory[9] = inventory [8];
  146. }
  147. if(string1 == inventory[6])
  148. {
  149. inventory[7] = inventory [6];
  150. inventory[8] = inventory [7];
  151. inventory[9] = inventory [8];
  152. }
  153. if(string1 == inventory[7])
  154. {
  155. inventory[8] = inventory [7];
  156. inventory[9] = inventory [8];
  157. }
  158. if(string1 == inventory[8])
  159. {
  160. inventory[9] = inventory [8];
  161. }
  162. case 'Y':
  163. for(int i = 0; i < inventory.size(); i++)
  164. cout << inventory[i] << endl << endl;
  165. cout << "Type an item that you want to delete." << endl;
  166. cin >> string1;
  167. if(string1 == inventory[0])
  168. {
  169. inventory[1] = inventory [0];
  170. inventory[2] = inventory [1];
  171. inventory[3] = inventory [2];
  172. inventory[4] = inventory [3];
  173. inventory[5] = inventory [4];
  174. inventory[6] = inventory [5];
  175. inventory[7] = inventory [6];
  176. inventory[8] = inventory [7];
  177. inventory[9] = inventory [8];
  178. }
  179. if(string1 == inventory[1])
  180. {
  181. inventory[2] = inventory [1];
  182. inventory[3] = inventory [2];
  183. inventory[4] = inventory [3];
  184. inventory[5] = inventory [4];
  185. inventory[6] = inventory [5];
  186. inventory[7] = inventory [6];
  187. inventory[8] = inventory [7];
  188. inventory[9] = inventory [8];
  189. }
  190. if(string1 == inventory[2])
  191. {
  192. inventory[3] = inventory [2];
  193. inventory[4] = inventory [3];
  194. inventory[5] = inventory [4];
  195. inventory[6] = inventory [5];
  196. inventory[7] = inventory [6];
  197. inventory[8] = inventory [7];
  198. inventory[9] = inventory [8];
  199. }
  200. if(string1 == inventory[3])
  201. {
  202. inventory[4] = inventory [3];
  203. inventory[5] = inventory [4];
  204. inventory[6] = inventory [5];
  205. inventory[7] = inventory [6];
  206. inventory[8] = inventory [7];
  207. inventory[9] = inventory [8];
  208. }
  209. if(string1 == inventory[4])
  210. {
  211. inventory[5] = inventory [4];
  212. inventory[6] = inventory [5];
  213. inventory[7] = inventory [6];
  214. inventory[8] = inventory [7];
  215. inventory[9] = inventory [8];
  216. }
  217. if(string1 == inventory[5])
  218. {
  219. inventory[6] = inventory [5];
  220. inventory[7] = inventory [6];
  221. inventory[8] = inventory [7];
  222. inventory[9] = inventory [8];
  223. }
  224. if(string1 == inventory[6])
  225. {
  226. inventory[7] = inventory [6];
  227. inventory[8] = inventory [7];
  228. inventory[9] = inventory [8];
  229. }
  230. if(string1 == inventory[7])
  231. {
  232. inventory[8] = inventory [7];
  233. inventory[9] = inventory [8];
  234. }
  235. if(string1 == inventory[8])
  236. {
  237. inventory[9] = inventory [8];
  238. }
  239. case 'n':
  240. system("PAUSE");
  241. case 'N':
  242. system("PAUSE");
  243. }
  244. }
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 977
Reputation: MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice 
Solved Threads: 92
MosaicFuneral's Avatar
MosaicFuneral MosaicFuneral is offline Offline
Posting Shark

Re: Text RPG Help

 
0
  #2
Apr 6th, 2009
Originally Posted by gangsta gama View Post
1) When I have
  1. if (inventory.size() == MAX_ITEMS)
  2. {
  3. inventory.push_back("Rusty Armor");
  4. }
  5. else
  6. {
  7. deleteItem();
  8. }
uhmmm... If you have a full inventory of items, you get a free Rusty Armor, but if you don't you lose an item?
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
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 60
Reputation: gangsta gama is an unknown quantity at this point 
Solved Threads: 0
gangsta gama gangsta gama is offline Offline
Junior Poster in Training

Re: Text RPG Help

 
0
  #3
Apr 6th, 2009
Thank you for responding to my thread. What i was trying to do with the arrays was for example: I want to move everything down one to delete the item that they want to delete. Can you show me how to do this please? Thank you again.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,632
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1496
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Text RPG Help

 
0
  #4
Apr 6th, 2009
OMG! Why don't you simply use vector's erase() method to delete an inventory item instead of all those assignment statements
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 338
Reputation: cikara21 is an unknown quantity at this point 
Solved Threads: 66
cikara21's Avatar
cikara21 cikara21 is offline Offline
Posting Whiz

Re: Text RPG Help

 
0
  #5
Apr 7th, 2009
I see 5 armors only..Not 6..
.:-cikara21-:.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 60
Reputation: gangsta gama is an unknown quantity at this point 
Solved Threads: 0
gangsta gama gangsta gama is offline Offline
Junior Poster in Training

Re: Text RPG Help

 
0
  #6
Apr 7th, 2009
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:

  1. inventory.push_back("Rusty Armor1");
  2. inventory.push_back("Rusty Armor2");
  3. inventory.push_back("Rusty Armor3");
  4. inventory.push_back("Rusty Armor4");
  5. inventory.push_back("Rusty Armor5");
  6. inventory.push_back("Rusty Armor6");
Last edited by gangsta gama; Apr 7th, 2009 at 8:15 pm.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 977
Reputation: MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice 
Solved Threads: 92
MosaicFuneral's Avatar
MosaicFuneral MosaicFuneral is offline Offline
Posting Shark

Re: Text RPG Help

 
0
  #7
Apr 7th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,632
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1496
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Text RPG Help

 
0
  #8
Apr 7th, 2009
Originally Posted by gangsta gama View Post
Well first:
OMG!!! I dont know what you were trying to mean by OMG and
If you are not native English then maybe you will not know what OMG means. Here is a link

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.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 60
Reputation: gangsta gama is an unknown quantity at this point 
Solved Threads: 0
gangsta gama gangsta gama is offline Offline
Junior Poster in Training

Re: Text RPG Help

 
0
  #9
Apr 8th, 2009
I KNOW WHAT OMG MEANS. The last part is what i really want to hear not the first part. And thank you MosaicFuneral for the link.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 60
Reputation: gangsta gama is an unknown quantity at this point 
Solved Threads: 0
gangsta gama gangsta gama is offline Offline
Junior Poster in Training

Re: Text RPG Help

 
0
  #10
Apr 8th, 2009
Again thank you for the link but, I dont get what its saying. How would I vector.erase() a variable? Like:

  1. cout << "What would u like to delete?" << endl;
  2. cin >> anyvar;
  3. // would I put:
  4. vector.erase(anyvar);

Is that right?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC