Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

A RPG I wrote in 2002 to learn C++. I was 15 years old.

By: a guest on Jan 27th, 2013  |  syntax: C++  |  size: 16.50 KB  |  views: 1,693  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /*Copyright 2002 */
  2. #include <iostream.h>
  3. #include <iomanip.h>
  4. #include <string.h>
  5. #include <windows.h>
  6. #include <conio.h>
  7.  
  8. #include <time.h>
  9.  
  10. //defined functions
  11. void fightagain();
  12. void map1();
  13. void map2();
  14. void map3();
  15. void fork();
  16. void fight1();
  17. void fight2();
  18. void keepgoing();
  19. void goback();
  20. //defined variables
  21. int east=0; //keeps track if you have gone east
  22. int west=0; //keeps track if you have gone east
  23. int race;       //character race
  24. int gender;     //character gender
  25. int playerclass;  //character class
  26. int life=3;     //lives
  27. int choice1;//first choice you make
  28. int dir2;   //second choice (which direction)
  29. int dir3;   //third choice (which direction)
  30. int choice4;   //fourth choice (fight again or run away)
  31. int hp=100; //character health
  32. int trollhp=75;  //troll's health
  33. int youdamage;   //damage you do
  34. int theirdamage; //damage monster does
  35. int training=0;  //if you have trained or not
  36. //strings
  37. char lost1;  //holds y or n to go back or not
  38. char name[20]; //holds character name
  39.  
  40.  
  41.  
  42. int main()  {
  43.  
  44.        
  45.                        
  46.  
  47. cout<<"       **************************************************"<<endl;
  48. cout<<"                            WILL'S RPG                   "<<endl;
  49. cout<<"       **************************************************"<<endl;
  50.                 cout<<" "<<endl;
  51.                 cout<<" "<<endl;
  52.                 cout<<" "<<endl;
  53.                 cout<<" "<<endl;
  54. cout<<"Welcome to Will's RPG.  You have been bestowed a powerful gift from a friendly"<<endl;
  55. cout<<"sorceror named Granthar that was in hiding.  This gift is a very evil ring."<<endl;
  56. cout<<"He told you that this ring must be destroyed.  The only way to do that is to"<<endl;
  57. cout<<"find a powerful wizard named Azgor.  He is the only one that can destroy the"<<endl;
  58. cout<<"ring so it can be saved from evil forces that would abuse its power.  Getting"<<endl;
  59. cout<<"to Azgor will be a very hard challenge because he lives on the other side of a"<<endl;
  60. cout<<"very deadly forest that you must pass through.  Granthar has grown very weak so"<<endl;
  61. cout<<"he must trust in you with the ring.  You have only 3 lives to make it through"<<endl;
  62. cout<<"the forest. "<<endl;
  63. cout<<" "<<endl;
  64. cout<<"Press any key to continue . . ."<<endl;
  65. getch();
  66. system("cls"); //clears screen
  67.  
  68.        
  69. cout<<"What is the gender of your character?"<<endl;
  70. cout<<"1. Male\n";
  71. cout<<"2. Female\n";
  72. cin>>gender;
  73. system("cls");
  74.        
  75. cout<<"What race would you like to be?"<<endl;
  76. cout<<"1. Human"<<endl;
  77. cout<<"2. Goblin"<<endl;
  78. cout<<"3. Dwarf"<<endl;
  79. cout<<"4. Orc "<<endl;
  80. cin>>race;
  81. system("cls");
  82.  
  83. cout<<"What class would you like to be?"<<endl;
  84. cout<<"1. A stealthy assassin armed with your trusty dagger"<<endl;
  85. cout<<"2. A holy paladin armed with a sword and shield"<<endl;
  86. cout<<"3. A strong barbarian armed with your long sword"<<endl;
  87. cout<<"4. A wise spellcaster armed with your magical staff"<<endl;
  88. cin>>playerclass;
  89. system("cls");
  90.  
  91.  
  92.  
  93.  
  94. cout<<"Enter your character's name: ";
  95. cin>>name;
  96. system("cls");
  97.  
  98. while (life>0)  {
  99.  
  100.  
  101.         if(life==3) {
  102.  
  103. system("cls");
  104. cout<<"You have 3 lives left."<<endl;
  105. cout<<"You are in your small house with the ring in your pocket and your"<<endl;
  106. if (playerclass==1)
  107. {
  108. cout<<"dagger in your hand."<<endl;
  109.         }
  110. if (playerclass==2)
  111. {
  112. cout<<"sword in one hand and shield in the other."<<endl;
  113.         }
  114. if (playerclass==3)
  115. {
  116. cout<<"long sword in your hands."<<endl;
  117.         }
  118. if (playerclass==4)
  119. {
  120. cout<<"magical staff in your hands."<<endl;
  121.         }
  122. cout<<"You know your quest and you must make it to the other side of the"<<endl;
  123. cout<<"woods as quickly as possible."<<endl;
  124. cout<<"Press any key to continue . . ."<<endl;
  125. getch();
  126. system("cls");
  127.  
  128. cout<<"You enter the woods with an eerie sense that there is much danger in"<<endl;
  129. cout<<"here.  You had better be careful.  You start on the path working your way"<<endl;
  130. cout<<"north."<<endl;
  131. cout<<"Press any key to continue . . ."<<endl;
  132. getch();
  133. system("cls");
  134.  
  135. cout<<"These woods are very dark and seem odd.  You look at your map and can't"<<endl;
  136. cout<<"tell if this is where you are supposed to be.  It might just be because you"<<endl;
  137. cout<<"have never been this far in before."<<endl;
  138. cout<<"Would you like to keep on going? (Y or N)"<<endl;
  139. cin>>lost1;
  140.  
  141. switch(lost1)
  142.  
  143.  
  144.                 {
  145.         case 'y':
  146.                 case 'Y': keepgoing();
  147.                          break;
  148.                 case 'n':
  149.         case 'N': goback();
  150.                          break;
  151.                 default:
  152. cout<<"I said to enter Y or N, not "<<lost1<<"."<<endl;
  153. life=0;
  154.                 }//end switch
  155.                
  156.         }//end if
  157.  
  158.                 if(life==2) {
  159.  
  160. system("cls");
  161. cout<<"You have 2 lives left."<<endl;
  162. cout<<"You awake in your small house with the ring in your pocket and your"<<endl;
  163. if (playerclass==1)
  164. {
  165. cout<<"dagger in your hand."<<endl;
  166.         }
  167. if (playerclass==2)
  168. {
  169. cout<<"sword in one hand and shield in the other."<<endl;
  170.         }
  171. if (playerclass==3)
  172. {
  173. cout<<"long sword in your hands."<<endl;
  174.         }
  175. if (playerclass==4)
  176. {
  177. cout<<"magical staff in your hands."<<endl;
  178.         }
  179. cout<<"You know your quest and you must make it to the other side of the"<<endl;
  180. cout<<"woods as quickly as possible."<<endl;
  181. cout<<"Press any key to continue . . ."<<endl;
  182. getch();
  183. system("cls");
  184.  
  185. cout<<"You enter the woods with an eerie sense that there is much danger in"<<endl;
  186. cout<<"here.  You had better be careful.  You start on the path working your way"<<endl;
  187. cout<<"north."<<endl;
  188. cout<<"Press any key to continue . . ."<<endl;
  189. getch();
  190. system("cls");
  191.  
  192. cout<<"These woods are very dark and seem odd.  You look at your map and can't"<<endl;
  193. cout<<"tell if this is where you are supposed to be.  It might just be because you"<<endl;
  194. cout<<"have never been this far in before."<<endl;
  195. cout<<"Would you like to keep on going? (Y or N)"<<endl;
  196. cin>>lost1;
  197.  
  198. switch(lost1)
  199.  
  200.  
  201.                 {
  202.         case 'y':
  203.                 case 'Y': keepgoing();
  204.                          break;
  205.                 case 'n':
  206.         case 'N': goback();
  207.                          break;
  208.                 default:
  209. cout<<"I said to enter Y or N, not "<<lost1<<"."<<endl;
  210. life=0;
  211.                 }//end switch
  212.                
  213.         }//end if
  214.  
  215.                
  216.                 if(life==1) {
  217.  
  218. system("cls");
  219. cout<<"You have 1 life left."<<endl;
  220. cout<<"You awake in your small house with the ring in your pocket and your"<<endl;
  221. if (playerclass==1)
  222. {
  223. cout<<"dagger in your hand."<<endl;
  224.         }
  225. if (playerclass==2)
  226. {
  227. cout<<"sword in one hand and shield in the other."<<endl;
  228.         }
  229. if (playerclass==3)
  230. {
  231. cout<<"long sword in your hands."<<endl;
  232.         }
  233. if (playerclass==4)
  234. {
  235. cout<<"magical staff in your hands."<<endl;
  236.         }
  237. cout<<"You know your quest and you must make it to the other side of the"<<endl;
  238. cout<<"woods as quickly as possible."<<endl;
  239. cout<<"Press any key to continue . . ."<<endl;
  240. getch();
  241. system("cls");
  242.  
  243. cout<<"You enter the woods with an eerie sense that there is much danger in"<<endl;
  244. cout<<"here.  You had better be careful.  You start on the path working your way"<<endl;
  245. cout<<"north."<<endl;
  246. cout<<"Press any key to continue . . ."<<endl;
  247. getch();
  248. system("cls");
  249.  
  250. cout<<"These woods are very dark and seem odd.  You look at your map and can't"<<endl;
  251. cout<<"tell if this is where you are supposed to be.  It might just be because you"<<endl;
  252. cout<<"have never been this far in before."<<endl;
  253. cout<<"Would you like to keep on going? (Y or N)"<<endl;
  254. cin>>lost1;
  255.  
  256. switch(lost1)
  257.  
  258.  
  259.                 {
  260.         case 'y':
  261.                 case 'Y': keepgoing();
  262.                          break;
  263.                 case 'n':
  264.         case 'N': goback();
  265.                          break;
  266.                 default:
  267. cout<<"I said to enter Y or N, not "<<lost1<<"."<<endl;
  268. life=0;
  269.                 }//end switch
  270.                
  271.         }//end if
  272.  
  273.  
  274.  
  275.  
  276.        
  277.  
  278. }//end while
  279.  
  280.  
  281.  
  282. cout<<"You have run out of lives.  GAME OVER."<<endl;
  283. cout<<"Please try again."<<endl;
  284. getch();
  285. return 0;
  286.  
  287.  
  288. }//end program
  289.  
  290.  
  291.  
  292. //\\\\\\\\\\\\\\\\\\
  293. //        FUNCTIONS       >>
  294. ////////////////////
  295. //==================================================================
  296.  
  297.  
  298. //\\\\\\\\\\\\\\\\\\
  299. //        CHOICE 1        >>
  300. ////////////////////
  301. //one of these 2 functions are called when you press y or n at the first choice
  302. //*******************************************************************
  303. void keepgoing()  {
  304. system("cls");
  305. cout<<"You decide to keep on moving forward.  Suddenly you feel a snake twist around"<<endl;
  306. cout<<"you.  It is a huge snake and its thick body has rendered you motionless."<<endl;
  307. cout<<"It wraps tighter and tighter as your breath lessens.  Everything goes black."<<endl;
  308. cout<<"You have lost a life."<<endl;
  309. cout<<"Press any key to continue . . ."<<endl;
  310.         getch();
  311.         system("cls");
  312.         life = life - 1;
  313.               }
  314.  
  315. void goback()  {
  316. system("cls");
  317. cout<<"You decide to go back and retrace your steps.  You journey back and can see"<<endl;
  318. cout<<"your home in the distance.  As you turn and face the woods again you realize"<<endl;
  319. cout<<"you had taken the wrong path.  You start on the correct path wondering where"<<endl;
  320. cout<<"the other trail would have led."<<endl;
  321. cout<<"Press any key to continue . . ."<<endl;
  322. getch();
  323. system("cls");
  324. fork();
  325. }
  326. //*******************************************************************
  327.  
  328.  
  329.  
  330.  
  331. //\\\\\\\\\\\\\\\\\\
  332. //              FIGHT     >>
  333. ////////////////////
  334. //this is the intro to the fight, only called once
  335. //*******************************************************************
  336. void fight1()  {
  337.  
  338. cout<<"As you turn around you are met with a 10 foot tall, green skinned troll.  He"<<endl;
  339. cout<<"towers above you holding a huge wooden club in his hand and looks ready to"<<endl;
  340. cout<<"fight with you.  You draw your weapon but have a decision to make."<<endl<<endl;
  341. cout<<"You have "<<hp<<" health left."<<endl;
  342. cout<<"The troll has "<<trollhp<<" health left."<<endl<<endl;
  343. cout<<"What do you do?"<<endl;
  344. cout<<"1. Attack the troll"<<endl;
  345. cout<<"2. Run away"<<endl;
  346. cin>>dir3;
  347.  
  348.  
  349. if (dir3==1)
  350. {
  351. system("cls");
  352. srand( (unsigned)time( NULL ) );
  353. if (training==1)
  354. {
  355.         youdamage = rand() % 35;
  356.         cout << "You attack the troll for " << youdamage << " points of damage"<<endl;
  357.         trollhp = trollhp - youdamage;
  358. }
  359. if (training==0)
  360. {
  361.         youdamage = rand() % 20;
  362.         cout << "You attack the troll for " << youdamage << " points of damage"<<endl;
  363.         trollhp = trollhp - youdamage;
  364. }
  365.  
  366.  
  367.  
  368. theirdamage = rand() % 15;
  369. cout << "The troll attacks you for " << theirdamage << " points of damage"<<endl;
  370. hp = hp - theirdamage;
  371. cout<<" "<<endl;
  372. cout<<"You have "<<hp<<" health left."<<endl;
  373. cout<<"The troll has "<<trollhp<<" health left."<<endl<<endl;
  374. getch();
  375. fightagain();
  376. }
  377.  
  378.  
  379. if (dir3==2)  {
  380. system("cls");
  381. cout<<"You turn around and begin to run but are too slow.  The troll catches up to you"<<endl;
  382. cout<<"and you feel an enormous pain in your torso as his club smacks against you."<<endl;
  383. cout<<"Your body crumples to the ground."<<endl;
  384. cout<<"Press any key to continue . . ."<<endl;
  385.         getch();
  386.         system("cls");
  387.         life = life-1; //subtracts 1 life
  388.        
  389.        
  390.               }
  391.  
  392. }//end of function
  393. //this is the end of first attack
  394. //*******************************************************************
  395.  
  396.  
  397.  
  398.  
  399. //\\\\\\\\\\\\\\\\\\
  400. //      FIGHTAGAIN        >>
  401. ////////////////////
  402. //this function is for the 2nd time and beyond for fighting the troll
  403. //*******************************************************************
  404. void fightagain()  {
  405.  
  406.         if (hp<=0)
  407. {
  408. hp=0;
  409. system("cls");
  410. cout <<"The troll hits you and everything goes black as your body falls to the ground."<<endl;
  411. cout <<"Press any key to continue . . ."<<endl;
  412. getch();
  413. system("cls");
  414. life=life-1;
  415. main();
  416. }
  417.         if (trollhp<=0)
  418. {
  419. trollhp=0;
  420. system("cls");
  421. cout << "The troll falls to the ground dead and you claim your first victory."<<endl;
  422. cout <<"You head back to the fork with new pride."<<endl;
  423. cout <<"Press any key . . ."<<endl;
  424. west=1;
  425. getch();
  426. system("cls");
  427. fork();
  428. }
  429.  
  430.  
  431. cout<<"What do you do?"<<endl;
  432. cout<<"1. Attack the troll"<<endl;
  433. cout<<"2. Run away"<<endl;
  434. cin>>choice4;
  435.  
  436. if (choice4==1)
  437. {
  438. system("cls");
  439. srand( (unsigned)time( NULL ) );
  440. if (training==1)
  441. {
  442.         youdamage = rand() % 30;
  443.         cout << "You attack the troll for " << youdamage << " points of damage"<<endl;
  444.         trollhp = trollhp - youdamage;
  445. }
  446. if (training==0)
  447. {
  448.         youdamage = rand() % 20;
  449.         cout << "You attack the troll for " << youdamage << " points of damage"<<endl;
  450.         trollhp = trollhp - youdamage;
  451. }
  452. if (trollhp<=0)
  453. {
  454.         trollhp=0;
  455. }
  456.  
  457. theirdamage = rand() % 15;
  458. cout << "The troll attacks you for " << theirdamage << " points of damage"<<endl;
  459. hp = hp - theirdamage;
  460. cout<<" "<<endl;
  461. cout<<"You have "<<hp<<" health left."<<endl;
  462. cout<<"The troll has "<<trollhp<<" health left."<<endl<<endl;
  463. getch();
  464. fightagain();
  465. }
  466.  
  467.  
  468. //this is the function if you run away from fightagain
  469. if (choice4==2)  {
  470. system("cls");
  471. cout<<"You turn around and begin to run but are too slow.  The troll catches up to you"<<endl;
  472. cout<<"and you feel an enormous pain in your torso as his club smacks against you."<<endl;
  473. cout<<"Your body crumples to the ground."<<endl;
  474. cout<<"Press any key to continue . . ."<<endl;
  475.         getch();
  476.         system("cls");
  477.         life = life-1; //subtracts 1 life
  478. }
  479.  
  480.  
  481.  
  482. } //end function
  483. //*******************************************************************
  484.  
  485.  
  486.  
  487.  
  488.  
  489. //\\\\\\\\\\\\\\\\\\
  490. //              FORK      >>
  491. ////////////////////
  492. //*******************************************************************
  493. void fork()  {
  494.        
  495.         //if character hasn't been east and west yet
  496.         if(east + west < 2) {
  497. cout<<"At a fork, the path splits into 2 ways."<<endl;
  498. cout<<"Which direction will you go?"<<endl;
  499. cout<<"1. East"<<endl;
  500. cout<<"2. West"<<endl;
  501. cin>>choice1;
  502.         }
  503.         //if the character has been east and west
  504.         if(east + west ==2) {
  505. cout<<"At the fork you find a new path that you didn't notice before.  It leads north."<<endl;
  506. cout<<"Which direction will you go?"<<endl;
  507. cout<<"1. East"<<endl;
  508. cout<<"2. West"<<endl;
  509. cout<<"3. North"<<endl;
  510. cin>>choice1;
  511.         }
  512.                         if(choice1==1) {
  513.                                
  514.                                 system("cls");
  515.                                 map1();
  516.                         }
  517.  
  518.                         if(choice1==2) {
  519.                                
  520.                                 system("cls");
  521.                                 map2();
  522.                         }
  523.  
  524.                         if(choice1==3) {
  525.  
  526.                                 system("cls");
  527.                                 map3();
  528.                         }
  529.  
  530. }
  531. //*******************************************************************
  532.  
  533.  
  534.  
  535.  
  536. //\\\\\\\\\\\\\\\\\\
  537. //              MAP1      >>
  538. ////////////////////
  539. //go to map1(east)
  540. //*******************************************************************
  541. void map1()  {
  542.  
  543.         if (east==1)  {
  544.         cout<<"You have already been here.  You head back to the fork."<<endl;
  545.         cout<<"Press any key to continue . . ."<<endl;
  546.         getch();
  547.         system("cls");
  548.         fork();
  549.         }
  550.        
  551.         if (east==0)  {
  552. cout<<"There is the back of a small hut in the clearing of the woods.  You wonder"<<endl;
  553. cout<<"who lives there and have to decide if you want to go see.  The woods are"<<endl;
  554. cout<<"unpredictable."<<endl;
  555. east=1;
  556. cout<<"What do you do?"<<endl;
  557. cout<<"1. Go see who lives there"<<endl;
  558. cout<<"2. Go back to the fork"<<endl;
  559. cin>>dir2;
  560.  
  561. if (dir2==1)  {
  562. system("cls");
  563. cout<<"You go investigate and when you come to the front you realize that it is a"<<endl;
  564. cout<<"a training school.  The master welcomes you and you recieve training.  You"<<endl;
  565. cout<<"now are a better fighter.  You decide to head back to the fork."<<endl;
  566. cout<<"Press any key to continue . . ."<<endl;
  567.         training=1;
  568.         getch();
  569.         system("cls");
  570.         fork();
  571.               }
  572.  
  573. if (dir2==2)  {
  574. cout<<"You turn around and head back to the fork"<<endl;
  575. cout<<"Press any key to continue . . ."<<endl;
  576.         getch();
  577.         system("cls");
  578.         fork();
  579.               }
  580.  
  581.         }//ends if function
  582. }//ends map1
  583. //*******************************************************************
  584.  
  585.  
  586.  
  587. //\\\\\\\\\\\\\\\\\\
  588. //              MAP2      >>
  589. ////////////////////
  590. //go to map2(west)
  591. //*******************************************************************
  592. void map2()  {
  593.  
  594.         if (west==1)  {
  595.         cout<<"You have already been here.  You head back to the fork."<<endl;
  596.         cout<<"Press any key to continue . . ."<<endl;
  597.         getch();
  598.         system("cls");
  599.         fork();
  600.                       }
  601.        
  602.         if (west==0)  {
  603. cout<<"You look around and see absolutely nothing but thick trees.  You turn around"<<endl;
  604. cout<<"to go back to the fork."<<endl;
  605. cout<<"Press any key to continue . . ."<<endl;
  606.         getch();
  607.         system("cls");
  608.         fight1();
  609.                       }
  610.              
  611. }//end map2
  612. //*******************************************************************
  613.  
  614.  
  615.  
  616. //\\\\\\\\\\\\\\\\\\
  617. //              MAP3      >>
  618. ////////////////////
  619. //go to map3(north)
  620. //*******************************************************************
  621. void map3()  {
  622.  
  623.        
  624. cout<<"As you march on the trail north you see the end of the trail and the fields"<<endl;
  625. cout<<"beyond.  You rush towards the exit of the forest."<<endl;
  626. cout<<"Press any key to continue . . . "<<endl;
  627.         getch();
  628.         system("cls");
  629.         fight2(); //go to fight 2
  630.         }
  631.  
  632.  
  633. //havent completed
  634. void fight2()  {
  635. cout<<"You win because I'm to lazy to put in another fight."<<endl;
  636. getch();
  637. system("cls");
  638. main();
  639. }
  640. //*******************************************************************