Enhancing a Text based RPG

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

Join Date: May 2004
Posts: 217
Reputation: marceta is an unknown quantity at this point 
Solved Threads: 0
marceta marceta is offline Offline
Posting Whiz in Training

Enhancing a Text based RPG

 
1
  #1
May 5th, 2004
Hi guys, im workin on a little text based RPG using c++. It is a win32 comsole application and i am wondering what i could do to improve it! I have added my source code

  1. # include <iostream>
  2. #include<ctime>
  3. #include<cstdlib>
  4. #include<cctype>
  5. using namespace std;
  6. struct monster
  7. {
  8. int strength;
  9. int dexterity;
  10. int hp;
  11. char name[32];
  12. };
  13. struct player
  14. {
  15. char name[32];
  16. int strength;
  17. int dexterity;
  18. int hp;
  19. int exp;
  20. int weapon;
  21. int armour;
  22. int shield;
  23. };
  24. struct equipment
  25. {
  26. char type[16];
  27. char name[32];
  28. int bonus;
  29. };
  30. struct rooms
  31. {
  32. char description[500];
  33. char name[32];
  34. int north;
  35. int south;
  36. int east;
  37. int west;
  38. };
  39. void initializeMonsters();
  40. void initializeEquipment();
  41. void initializeRooms();
  42. void initializeBattle();
  43. void initializePlayer();
  44. void giveItem();
  45. int randomNumber(int);
  46. rooms roomsArray[11];
  47. equipment equipmentArray[9];
  48. player character;
  49. monster monsterArray[6];
  50. int main()
  51. {
  52. initializeMonsters();
  53. initializeEquipment();
  54. initializePlayer();
  55. initializeRooms();
  56. char move;
  57. int currentroom = 0;
  58. cout << "You emerge in the " <<roomsArray[currentroom].name;
  59. cout << roomsArray[currentroom].description;
  60. while (character.hp > 0)
  61. {
  62. if (roomsArray[currentroom].north != -1)
  63. {
  64. cout << "You may move north \n";
  65. }
  66. if (roomsArray[currentroom].south != -1)
  67. {
  68. cout << "You may move south \n";
  69. }
  70. if (roomsArray[currentroom].east != -1)
  71. {
  72. cout << "You may move east \n";
  73. }
  74. if (roomsArray[currentroom].west != -1)
  75. {
  76. cout << "You may move west \n";
  77. }
  78. cout << "please enter your move: " << endl;
  79. cin >> move;
  80. move = toupper(move);
  81. if (move == 'E')
  82. currentroom = roomsArray[currentroom].east;
  83. if (move == 'W')
  84. currentroom = roomsArray[currentroom].west;
  85. if (move == 'N')
  86. currentroom = roomsArray[currentroom].north;
  87. if (move == 'S')
  88. currentroom = roomsArray[currentroom].south;
  89. if (move == 'C')
  90. cout << "You have " << character.hp << " HP." << endl;
  91. cout << "You have " << character.strength << " strength." << endl;
  92. cout << "You have " << character.dexterity << " dexterity." << endl;
  93. if (move != 'E' && move != 'W' && move != 'S' && move!= 'N')
  94. cout << "Please insert either 'N', 'E', 'S' or 'W'! " << endl;
  95. cout << "You emerge in the " << roomsArray[currentroom].name << endl;
  96. cout << roomsArray[currentroom].description << endl;
  97. initializeBattle();
  98. giveItem();
  99. }
  100. cout << "You have failed to beat Hannibal and his minions. You have also "
  101. << "failed to avenge your Grandfather. What where you thinking going "
  102. << "into the castle so weak (*hint make stats higher)!" << endl;
  103. return 0;
  104. }
  105. void initializeMonsters()
  106. {
  107. monsterArray[0].strength = 40;
  108. monsterArray[0].dexterity = 10;
  109. monsterArray[0].hp = 30;
  110. strcpy(monsterArray[0].name, "Orc");
  111. monsterArray[1].strength = 10;
  112. monsterArray[1].dexterity = 40;
  113. monsterArray[1].hp = 30;
  114. strcpy(monsterArray[0].name, "Elven Archer");
  115. monsterArray[2].strength = 20;
  116. monsterArray[2].dexterity = 30;
  117. monsterArray[2].hp = 30;
  118. strcpy(monsterArray[0].name, "Undead Corpse");
  119. monsterArray[3].strength = 30;
  120. monsterArray[3].dexterity = 30;
  121. monsterArray[3].hp = 20;
  122. strcpy(monsterArray[0].name, "Marine");
  123.  
  124. monsterArray[4].strength = 30;
  125. monsterArray[4].dexterity = 30;
  126. monsterArray[4].hp = 30;
  127. strcpy(monsterArray[0].name, "Elite Marksman");
  128. monsterArray[5].strength = 70;
  129. monsterArray[5].dexterity = 50;
  130. monsterArray[5].hp = 10;
  131. strcpy(monsterArray[5].name, "Hannibal");
  132. }
  133. void initializePlayer()
  134. {
  135. char username[32];
  136.  
  137. char move;
  138. int currentroom = 0;
  139. cout << "What is your name??? \n" << endl;
  140. cin >> username;
  141. cout << "------------------------------------------ \n" << endl;
  142. strcpy(character.name, username);
  143. character.hp = 100;
  144. character.armour=0;
  145. character.shield=0;
  146. character.weapon=0;
  147. cout << endl << username << " Please insert your strength. This will determine the ammount of damage you will inflict. 30-40 is a good ammount. However you may make this number ludacrisly high! \n" <<endl;
  148. cin >> character.strength;
  149. cout << "------------------------------------------ \n" << endl;
  150. cout << endl << username << " Please insert your dexterity. This will determine the ammount of damage that you will have inflicted upon you. The more dexterity, the less total damage. 30 - 40 is a good ammount. Once again you can make this ludacrisly high! \n" << endl;
  151. cin >> character.dexterity;
  152. cout << "------------------------------------------ \n" << endl;
  153. cout << "==========================================" << endl;
  154. cout << "Brave " << username << " you have just returned from a recent holiday,"
  155. << "only to find that your village has been pillaged and destroyed."
  156. << "Upon returning to your hut you see your father, mother and sister"
  157. << " laying lifeless in pools of their own blood. Without hesitation"
  158. << " you start sprinting towards Sir Lucifer Hannible's castle."
  159. << "The castle rests upon a hill that overlooks your town. "
  160. << "You know that by the end of today you will kill "
  161. << " hannible and his minions and burn his csatle to cinders."
  162. << " It is your duty to yourslef and the many villages that surrround yours to"
  163. << " assasinate this threat. I wish you luck " << username << ". Who am I you ask?"
  164. << "I am your dead grandfather that died to the merciless hand of Hannible. "
  165. << "Now go grandson."
  166. << "At any time (except during battle) you may press 'c' to display your stats!"
  167. << "Simply use 'e','w','n' or 's' to navigate, where and as appropriate." << endl;
  168. cout << "========================================== \n" << endl;
  169. }
  170. void initializeEquipment()
  171. {
  172. strcpy(equipmentArray[0].type, "Gun");
  173. strcpy(equipmentArray[0].name, "Berreta");
  174. equipmentArray[0].bonus = 10;
  175. strcpy(equipmentArray[1].type, "Gun");
  176. strcpy(equipmentArray[1].name, "M4 Carbine Rifle");
  177. equipmentArray[1].bonus = 30;
  178. strcpy(equipmentArray[2].type, "Gun");
  179. strcpy(equipmentArray[2].name, "Flamethrower");
  180. equipmentArray[2].bonus = 50;
  181. strcpy(equipmentArray[3].type, "Shield");
  182. strcpy(equipmentArray[3].name, "Homemade wooden sheild");
  183. equipmentArray[3].bonus = 10;
  184. strcpy(equipmentArray[4].type, "Shield");
  185. strcpy(equipmentArray[4].name, "Roman sheild");
  186. equipmentArray[4].bonus = 30;
  187. strcpy(equipmentArray[5].type, "Shield");
  188. strcpy(equipmentArray[5].name, "Heavenly Protection");
  189. equipmentArray[5].bonus = 50;
  190. strcpy(equipmentArray[6].type, "Armour");
  191. strcpy(equipmentArray[6].name, "Flak Jacket");
  192. equipmentArray[6].bonus = 10;
  193. strcpy(equipmentArray[7].type, "Armour");
  194. strcpy(equipmentArray[7].name, "Kevlar SWAT vest");
  195. equipmentArray[7].bonus = 10;
  196. strcpy(equipmentArray[8].type, "Gun");
  197. strcpy(equipmentArray[8].name, "Possesed Armour");
  198. equipmentArray[8].bonus = 10;
  199. }
  200. void initializeRooms()
  201. {
  202. strcpy(roomsArray[0].description, "This room is extravagant. There are gold chandaliers on the roof, and a table with gold goblets and plates. There are no windows, and a fireplace to the north illuminates the room. There is a door at the eastern side of the room\n");
  203. strcpy(roomsArray[0].name, "Foyer Room\n");
  204. roomsArray[0].north = -1;
  205. roomsArray[0].south = -1;
  206. roomsArray[0].east = 1;
  207. roomsArray[0].west = -1;
  208. strcpy(roomsArray[1].description, "You emerge into a dark hallway with a single torch in the middle. There are no distinguishing features about this room, and there is a door in the eastern side of the room.\n");
  209. strcpy(roomsArray[1].name, "Dark Hallway\n");
  210. roomsArray[1].north = -1;
  211. roomsArray[1].south = -1;
  212. roomsArray[1].east = 2;
  213. roomsArray[1].west = 0;
  214. strcpy(roomsArray[2].description, "There is a massive fountain in the middle of the room. Its water glows some sort of a heavenly radiance. Upon drinking it you feel revitalised and like a new man. Your HP is restored to its maximum level. There are doors on the northern, eastern and southern sides of the room. \n");
  215. strcpy(roomsArray[2].name, "Foutain Room\n");
  216. roomsArray[2].north = 3;
  217. roomsArray[2].south = 4;
  218. roomsArray[2].east = 6;
  219. roomsArray[2].west = 1;
  220. strcpy(roomsArray[3].description, "Upon stumbling onto this room, you are drenched to your knees in water. As well as being wet, it is also dark and has no distincitive features or items. There are door in on the eastern and southern sides of the room.\n");
  221. strcpy(roomsArray[3].name, "Swamp\n");
  222. roomsArray[3].north = -1;
  223. roomsArray[3].south = 2;
  224. roomsArray[3].east = 5;
  225. roomsArray[3].west = -1;
  226. strcpy(roomsArray[4].description, "A bright lantern illuminates this beatiful room. There are exotic flowers on either sides of it and a treasure chest full of dublons in the top right hand corner. There are doors on the eastern, southern and western sides of the room.\n");
  227. strcpy(roomsArray[4].name, "Treasure Room\n");
  228. roomsArray[4].north = 2;
  229. roomsArray[4].south = -1;
  230. roomsArray[4].east = 7;
  231. roomsArray[4].west = -1;
  232. strcpy(roomsArray[5].description, "Another lusicious and overdone room. Crystals that are on the ground reflect the portraits on the walls. There are doors on the southern and western sides of this room. \n");
  233. strcpy(roomsArray[5].name, "Counting Room\n");
  234. roomsArray[5].north = -1;
  235. roomsArray[5].south = 6;
  236. roomsArray[5].east = 8;
  237. roomsArray[5].west = 3;
  238. strcpy(roomsArray[6].description, "The total opposite of the beatiful fountain room. It reeks of a peculiar smell and is bare with nothing interesting in it. There are doors on every corner of this room. \n");
  239. strcpy(roomsArray[6].name, "Barn \n");
  240. roomsArray[6].north = 5;
  241. roomsArray[6].south = 7;
  242. roomsArray[6].east = 2;
  243. roomsArray[6].west = 9;
  244. strcpy(roomsArray[7].description, "This majestic room has treasure scattered everywhere. In the middle is a large four post king sized bed. There are doors on every corner of this room.\n");
  245. strcpy(roomsArray[7].name, "Master Bedroom \n");
  246. roomsArray[7].north = 6;
  247. roomsArray[7].south = -1;
  248. roomsArray[7].east = -1;
  249. roomsArray[7].west = 4;
  250. strcpy(roomsArray[8].description, "This room is the workers quarters. There are many small uncomfortable beds in running on each wall. There are windows on the northern and eastern walls and doors on the southern and western walls. \n");
  251. strcpy(roomsArray[8].name, "Minions Quarters \n");
  252. roomsArray[8].north = -1;
  253. roomsArray[8].south = 9;
  254. roomsArray[8].east = -1;
  255. roomsArray[8].west = 5;
  256. strcpy(roomsArray[9].description, "What on earth is this. Could it be a mirage? You see luchsious palm tree circling a lagoon with many fish and aquatic lifeforms. There are doors the norhtern, eastern and western sides of the room. \n");
  257. strcpy(roomsArray[9].name, "Tropical Lagoon \n");
  258. roomsArray[9].north = 8;
  259. roomsArray[9].south = -1;
  260. roomsArray[9].east = 10;
  261. roomsArray[9].west = 6;
  262. strcpy(roomsArray[10].description, "The time is now. You see Hannible in his throne. Cigar in one hand, the finest wine in the other. With loud profanity you charge to avenge your grandfather! \n");
  263. strcpy(roomsArray[10].name, "Hannibles Smoking and Sitting Room \n");
  264. }
  265. void initializeBattle()
  266. {
  267. int attackstrength = 0;
  268. int defencestrength = 0;
  269. int monsterattack = 0;
  270. int monsterdefence = 0;
  271. int randommonster = 0;
  272. srand(static_cast<unsigned>(time(0)));
  273. randommonster = (rand()%6 + 1);
  274. cout << "A " << monsterArray[randommonster].name << "Appears. \n" << endl;
  275. cout << monsterArray[randommonster].name << "has" << monsterArray[randommonster].strength << "strength" << endl
  276. << monsterArray[randommonster].name << "has" << monsterArray[randommonster].dexterity << "dexterity" << endl
  277. << monsterArray[randommonster].name << "has" << monsterArray[randommonster].hp << "HP \n" << endl;
  278. do
  279. {
  280. attackstrength = (character.strength + character.weapon) * (rand()%10 + 1);
  281. cout << character.name << " deals " << attackstrength << " damage" << endl;
  282. monsterdefence = (monsterArray[randommonster].dexterity * (rand()%5+1));
  283. cout << monsterArray[randommonster].name << " defends " << monsterdefence << " Hit Points" << endl;
  284. if (attackstrength > monsterdefence)
  285. {
  286. monsterArray[randommonster].hp = monsterArray[randommonster].hp - (attackstrength - monsterdefence);
  287. cout << "The monster now has " << monsterArray[randommonster].hp << "Hit points!" << endl;
  288. }
  289. else
  290. {
  291. monsterArray[randommonster].hp = monsterArray[randommonster].hp;
  292. cout << "You have failed to harm the monster!\n" << endl;
  293. }
  294. monsterattack = (monsterArray[randommonster].strength * (rand()%5+1));
  295. cout << monsterArray[randommonster].name << " does " << monsterattack << "damage!" << endl;
  296. defencestrength = (character.dexterity + character.shield) * (rand()%5 + 1);
  297. cout << character.name << " defends " << defencestrength << "Hit Points!" << endl;
  298. if (monsterattack > defencestrength)
  299. {
  300. character.hp = character.hp - (monsterattack - defencestrength);
  301. cout << "You have been hit! You now have " << character.hp << "Hit Points! \n" << endl;
  302. }
  303. else
  304. {
  305. character.hp = character.hp;
  306. cout << "You have defended the monsters attack! \n ...And now have " << character.hp << "Hitpoints! \n" << endl;
  307. }
  308. }while (monsterArray[randommonster].hp > 0);
  309. }
  310. void giveItem()
  311. {
  312. int randomgenerator = 0;
  313. srand(static_cast<unsigned>(time(0)));
  314. randomgenerator = (rand()%9 + 1);
  315. char playerchoice;
  316. if (randomgenerator == 0 || randomgenerator == 1 || randomgenerator == 2)
  317. {
  318. cout << "Do you want to pick up the " << equipmentArray[randomgenerator].name << " ?" << endl;
  319. cout << "This will add " << equipmentArray[randomgenerator].bonus << "to your strength." << endl;
  320. cout << "(Y)es or (N)o." << endl;
  321. cin >> playerchoice;
  322. playerchoice = toupper(playerchoice);
  323. if (playerchoice == 'Y')
  324. character.weapon = equipmentArray[randomgenerator].bonus;
  325. else
  326. character.weapon = character.weapon;
  327. }
  328. else if (randomgenerator == 3 || randomgenerator == 4 || randomgenerator == 5)
  329. {
  330. cout << "Do you want to pick up the " << equipmentArray[randomgenerator].name << " ?" << endl;
  331. cout << "This will add " << equipmentArray[randomgenerator].bonus << "to your dexterity." << endl;
  332. cout << "(Y)es or (N)o." << endl;
  333. cin >> playerchoice;
  334. playerchoice = toupper(playerchoice);
  335. if (playerchoice == 'Y')
  336. character.shield = equipmentArray[randomgenerator].bonus;
  337. else
  338. character.shield = character.shield;
  339. }
  340. else if (randomgenerator == 6 || randomgenerator == 7 || randomgenerator == 8)
  341. {
  342. cout << "Do you want to pick up the " << equipmentArray[randomgenerator].name << " ?" << endl;
  343. cout << "This will add " << equipmentArray[randomgenerator].bonus << "to your dexterity." << endl;
  344. cout << "(Y)es or (N)o." << endl;
  345. cin >> playerchoice;
  346. playerchoice = toupper(playerchoice);
  347. if (playerchoice == 'Y')
  348. character.armour = equipmentArray[randomgenerator].bonus;
  349. else
  350. character.armour = character.shield;
  351. }
  352. }
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 1
Reputation: thimok is an unknown quantity at this point 
Solved Threads: 0
thimok thimok is offline Offline
Newbie Poster

Re: Enhancing a Text based RPG

 
1
  #2
May 9th, 2004
Grammar and spell-check....you spell Hannible(Hannibal??) a couple different ways.....I dont mean to nit-pick, but if the text the user sees is spelled correctly and makes sense, then it is that much more enjoyable.....Your game looks interesting enough....i would like to play it......(I don't have any suggestions for the code....i didn't feel like reading through it all, sorry)
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 5
Reputation: Caps is an unknown quantity at this point 
Solved Threads: 0
Caps Caps is offline Offline
Newbie Poster

Re: Enhancing a Text based RPG

 
1
  #3
May 10th, 2004
Perhaps, add menu capabilities and an option to load different adventures via file i/o. (Ability to download new adventures off your website or something, aka updates)
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 1
Reputation: JerkTASTIC is an unknown quantity at this point 
Solved Threads: 0
JerkTASTIC JerkTASTIC is offline Offline
Newbie Poster

Re: Enhancing a Text based RPG

 
0
  #4
Jun 9th, 2004
I would say that instead of useing the char command for string use apstring.h. All you have to do is google apstring.h and astring.cpp. Then to declare a sting just type "apstring name" without the "" things. Apstring give you a little more freedom when it comes to strings.
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 75
Reputation: gusano79 is on a distinguished road 
Solved Threads: 5
gusano79 gusano79 is offline Offline
Junior Poster in Training

Re: Enhancing a Text based RPG

 
0
  #5
Jun 10th, 2004
Originally Posted by marceta
Hi guys, im workin on a little text based RPG using c++. It is a win32 comsole application and i am wondering what i could do to improve it!
...
It's always great to see someone working on text-based games!

It looks like you have a decent start on a room-based game engine. You may want to take the time to use something besides fixed-size arrays for your room locations and inventory; those aren't very flexible. This kind of game is an excellent match for an object-oriented language, so it would make sense to use classes for just about anything you could describe as an "object" in your system. Inheritance is also good--for example, shields, breastplates, and (say) tight leather pants could all be considered armor, or maybe you'd like to make a distinction between objects that are carryable by the player and those that are not.

How familiar are you with text adventures in general? The genre is alive and well, and much wisdom is to be gained from exploring what's already out there. I'm not saying you should scrap your own engine and use a development system somebody else wrote--certainly not--but I think it would be very useful to familiarize yourself with at least one existing system to get an idea of some of the challenges involved.

http://www.wurb.com/if/ is a good place to find other games to play for inspiration
http://www.tads.org/ gets you my authoring system of choice
http://www.inform-fiction.org/ is another good authoring system

Keep at it.
Reply With Quote Quick reply to this message  
Reply

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



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC