Advertisement
mikenter

Super Simple C++ Game

Feb 25th, 2012
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.32 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <cstdlib>
  4. using namespace std;
  5. int random(int, int);
  6. int main()
  7. {
  8.     srand((unsigned)time(0));
  9.     string input; string area = "forest";
  10.     int dlow = 1; int d6high = 6; int d8high = 8; int d12 = 12; int d20high = 20;
  11.     int hp = 15 + random(dlow, d20high); int hpmax = hp; int mp = 10 + random(dlow, d20high);
  12.         int mpmax = mp; int exp = 0; int gold = 5 + random(dlow, d12);
  13.  
  14.     begin:
  15.     cout << "You arrive in town\n";
  16.     begin1:
  17.     cout << ">";
  18.     cin >> input;
  19.  
  20.     if (input == "help"){
  21.         cout << "Commands are:\n";
  22.         cout << "'battle' - start a battle\n";
  23.         cout << "'inn' - takes you to the inn, where you can heal\n";
  24.         cout << "'shop - takes you to the shop\n";
  25.         cout << "'hp', 'mp', 'exp', 'gold', or 'info' - view your current exp, gold, hp, and mp.\n";
  26.         cout << "'quit - quit the game\n\n";
  27.         goto begin;
  28.     }
  29.     else if (input == "inn"){
  30.         cout << "Welcome to the inn lad, would you like to stay a night? Only a mere 5 gold coins.\n";
  31.         inn:
  32.         cout << ">";
  33.         cin >> input;
  34.         if ((input == "yes" && gold >= 5) || (input == "y" && gold >= 5)){
  35.             hp = hpmax; mp = mpmax; gold = gold -5;
  36.             cout << "You slept the night and feel refreshed.\n\n";
  37.             goto begin;
  38.         }
  39.         else if (input == "help"){
  40.             cout << "'yes' or 'y' to sleep at the inn. 'no', 'n', or 'back' to exit the inn.";
  41.             goto inn;
  42.         }
  43.         else if (input == "no" || input == "n" || input == "back"){
  44.             cout << "No? too bad, come back some other time!";
  45.             goto begin;
  46.         }
  47.         else if( gold < 5){
  48.             cout << "You don't seem to have any gold, go fight some and get a bit, be sure to come back.\n\n";
  49.             goto begin;
  50.         }
  51.         else {
  52.             cout << "What kind of gibberish are you speaking, come back when you have your head on right.\n\n";
  53.             goto begin;}
  54.     }
  55.     else if (input == "shop"){
  56.         cout << "\nWelcome to my humble shop, I have a little bit of everything. Have a 'look' around.\n";
  57.         cout << ">";
  58.         cin >> input;
  59.         if (input == "look"){ cout << "There's nothing around, you decide to leave.\n\n"; goto begin;}
  60.         else {cout << "You decline his offer and leave the store.\n\n"; goto begin;}
  61.     }
  62.     else if (input == "hp" || input == "mp" || input == "exp" || input == "gold" || input == "info"){
  63.         cout << "You have " << exp << " exp, " << gold << " gold, " << hp << " hp, " << mp << " mp.\n\n";
  64.         goto begin1;
  65.     }
  66.     else if (input == "quit") return 0;
  67.     else if (input == "battle"){
  68.         cout << endl;
  69.         goto battle;
  70.     }
  71.     else{ cout << "That's not a valid command, type help to see the commands\n\n"; goto begin;}
  72.  
  73.     battle:
  74.     int mon = random(dlow, d6high);
  75.     int enemyattack;
  76.     int enemyhp;
  77.     int goldget;
  78.     if(area == "forest"){
  79.         switch(mon){
  80.         case 1:
  81.         case 2:
  82.             cout << "You encounter a Giant Rat!\n";
  83.             enemyattack = random(dlow, d6high);
  84.             enemyhp = 25;
  85.             goldget = random(dlow, d6high);
  86.             break;
  87.         case 3:
  88.             cout << "You encounter test 3.\n";
  89.             enemyattack = random(dlow, d6high);
  90.             enemyhp = 25;
  91.             goldget = random(dlow, d6high);
  92.             break;
  93.         case 4:
  94.             cout << "You encounter test 4.\n";
  95.             enemyattack = random(dlow, d6high);
  96.             enemyhp = 25;
  97.             goldget = random(dlow, d6high);
  98.             break;
  99.         case 5:
  100.             cout << "You encounter test 5.\n";
  101.             enemyattack = random(dlow, d6high);
  102.             enemyhp = 25;
  103.             goldget = random(dlow, d6high);
  104.             break;
  105.         case 6:
  106.             cout << "You encounter test 6.\n";
  107.             enemyattack = random(dlow, d6high);
  108.             enemyhp = 25;
  109.             goldget = random(dlow, d6high);
  110.             break;
  111.         }
  112.     }
  113.  
  114.     do {
  115.         int attack= random(dlow, d8high);
  116.         int heal = random(dlow, d6high);
  117.         int magicmissile = random(dlow, d6high) + 2;
  118.         int attackroll = random(dlow, d20high);
  119.         int enemyattackroll = random(dlow, d20high);
  120.  
  121.         cout << ">";
  122.         cin >> input;
  123.  
  124.         if (input == "help"){
  125.             cout << "Commands are:\n";
  126.             cout << "'attack' or 'atk' - attack the enemy.\n";
  127.             cout << "'heal' - heal yourself.\n";
  128.             cout << "'magicmissile' or 'mm' - cast magic missile on the enemy.\n";
  129.             cout << "'hp', 'mp', 'exp', gold, or 'info' - view your current exp, gold, hp, and mp.\n\n";
  130.         }
  131.         else if (input == "attack" || input == "atk") {
  132.             if (attackroll >= 10){
  133.                 cout << "You attacked the enemy for " << attack << "hp.\n";
  134.                 enemyhp = enemyhp - attack;
  135.             }
  136.                 else {
  137.                     cout <<"You missed the enemy!\n";
  138.                 }
  139.             if (enemyattackroll >= 10){
  140.                 cout << "You got hit for " << enemyattack << "hp.\n\n";
  141.                 hp = hp - enemyattack;
  142.             }
  143.                 else {
  144.                     cout << "The enemy missed you.\n\n";
  145.                 }
  146.         }
  147.         else if (input == "heal"){
  148.             if (mp > 3){
  149.                 cout << "You healed yourself for " << heal << " hp.\n";
  150.                 hp = hp + heal;
  151.                 mp = mp - 4;
  152.             }
  153.                 else {
  154.                     cout << "You do not have enough mana for that spell, try a different command.\n\n";
  155.                 }
  156.             if (enemyattackroll >= 10){
  157.                 cout << "You got hit for " << enemyattack << "hp.\n\n";
  158.                 hp = hp - enemyattack;
  159.             }
  160.                 else {
  161.                     cout << "The enemy missed you.\n\n";
  162.                 }
  163.         }
  164.  
  165.         else if (input == "magicmissile" || input == "mm"){
  166.             if (mp > 7){
  167.                 cout << "You blast the enemy for " << magicmissile << "hp with magic missile!\n";
  168.                 enemyhp = enemyhp - magicmissile;
  169.                 mp = mp - 8;
  170.             }
  171.                 else {
  172.                     cout << "You do not have enough mana for that spell, try a different command.\n";
  173.                 }
  174.             if (enemyattackroll >= 10){
  175.                 cout << "You got hit for " << enemyattack << "hp.\n\n";
  176.                 hp = hp - enemyattack;
  177.             }
  178.                 else {
  179.                     cout << "The enemy missed you.\n\n";
  180.                 }
  181.         }
  182.  
  183.         else if (input == "hp" || input == "mp" || input == "exp" || input == "gold" || input == "info")
  184.             cout << "You have " << exp << " exp, " << gold << " gold, " << hp << " hp, " << mp << " mp.\n\n";
  185.         else
  186.             cout << "That's not an input silly." << endl << endl;
  187.     } while (hp > 0 && enemyhp > 0);
  188.  
  189.     if(hp <= 0 && enemyhp <= 0)
  190.         cout << "You have each fallen at the same time." << endl;
  191.     else if(hp <= 0){
  192.         cout << "You have been defeated!" << endl;
  193.         exp = 0;
  194.     }
  195.     else if(enemyhp <= 0){
  196.         cout << "You have won the battle!" << endl;
  197.         exp = exp + 25;
  198.         gold = gold + goldget;
  199.     }
  200.  
  201.     loop2:
  202.  
  203.     cout << ">";
  204.     cin >> input;
  205.  
  206.     if (input == "back") {
  207.         cout << endl;
  208.         goto begin;
  209.     }
  210.     else if (input == "help"){
  211.         cout << "Type 'back' to go back to town. Type 'quit' to quit the game.\n";
  212.         goto loop2;
  213.     }
  214.     else if (input == "quit") return 0;
  215.     else goto loop2;
  216. }
  217.  
  218. int random(int low, int high)
  219. {
  220.     return (rand() % (high - low + 1)) + low;
  221. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement