piexil

Text-based rpg engine alpha .5

Apr 18th, 2012
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.62 KB | None | 0 0
  1.  
  2. #include "stdafx.h"
  3. #include <iostream>
  4. #include <string>
  5. #include <fstream>
  6. #include <vector>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <ctime>
  10. #include <math.h>
  11.  
  12.  
  13.  
  14. using namespace std;
  15.  
  16. int _tmain(int argc, _TCHAR* argv[])
  17. {
  18.     start:
  19.     cout << "Text-rpg Engine (c) 2012 piexil" << ".\n";
  20.     string load;
  21.     cout << "Would you like to load (Y/N)?" << ".\n";
  22.     //Loading of the varibles time
  23.     bool debugmode;
  24.     int bnm;
  25.     int dun;
  26.     int dun2;
  27.     int gold;
  28.     int inv[30];
  29.     //inv is for quest items, such as the golden guantlet which is inv[1]
  30.     int hp;
  31.     int invret;
  32.     int quest;
  33.     int wepbonus;
  34.     int pos[2];
  35.     int poso[2];
  36.     int expr;
  37.     int mon;
  38.     int health;
  39.     float lvl;
  40.     int randum[5];
  41.     float dmg;
  42.     float mondmg;
  43.     float monlvl;
  44.     int tlvl;
  45.     float monhealth;
  46.     float monatk;
  47.     float atk;
  48.     float def;
  49.     float mondef;
  50.     string debug;
  51.     string invdir;
  52.     string towndir;
  53.     string battledir;
  54.     string monster;
  55.     string l;
  56.     string lo;
  57.     string line;
  58.     vector <string> v ;
  59.     //setting the deafualts for the varibles
  60.     inv[2] = 2;
  61.     //inv[2] is your current weapon
  62.     bnm = 0;
  63.     debugmode = false;
  64.     dun=0;
  65.     dun2=0;
  66.     poso[1] = 0;
  67.     poso[2] = 0;
  68.     invret = 0;
  69.     gold = 0;
  70.     inv[1] = 0;
  71.     monlvl = 1;
  72.     expr = 0;
  73.     lvl = 1;
  74.     health = 2.33 * sqrt(lvl) *100 ;
  75.     mon = 0;
  76.     pos[1] = 0;
  77.     pos[2] = 0;
  78.     quest = 0;
  79.     hp = 1;
  80.     wepbonus = 1;
  81.     //pos[1] is the veritical position, pos [2] is the horizontal
  82.     cin >> load;
  83.     if(load=="Y" || load=="y"){
  84.          ifstream lo ("save.txt");
  85.   if (lo.is_open())
  86.   {
  87.     while ( lo.good() )
  88.     {
  89.       while (getline(lo, l))
  90.           {
  91.   v.push_back( l);
  92.    
  93.   }
  94.    
  95.     //this is strictly for debuging purposes  
  96.    cout << "line 1 = " << v[1] << endl;
  97.    //since the vector for loading the save file is a string, we must cionvert to integers
  98.    pos[1] = atoi(v[0].c_str());
  99.    pos[2] = atoi(v[1].c_str());
  100.     health = atoi(v[2].c_str());
  101.     expr = atoi(v[3].c_str());
  102.     lvl = atoi(v[4].c_str());
  103.     inv[1]= atoi(v[5].c_str());
  104.     inv[2]= atoi(v[6].c_str());
  105.     hp = atoi(v[7].c_str());
  106.     gold = atoi(v[8].c_str());
  107.     dun2 = atoi(v[9].c_str());
  108.     poso[1]= atoi(v[10].c_str());
  109.     poso[2]= atoi(v[11].c_str());
  110.     goto move;
  111.     }
  112.     lo.close();
  113.  
  114.    
  115.   }
  116.  
  117.   else cout << "Unable to open file";
  118.  
  119.     }
  120.     if(load=="N" || "n"){
  121.         goto move;
  122.     }
  123.    
  124.    
  125.  
  126.  
  127.    
  128.    
  129. move:
  130.     //here we see whether or not the next space the user goes to is a battle sequence, it has a 1/6 chance of being one
  131.    
  132.     srand(time(0));
  133.      if(dun2==1){randum[1] = (rand() % 3 + 1);
  134.     if(randum[1] == 3){
  135.         mon = 1;
  136.    
  137.     //this if statement is for the debug mode were you can disable monsters
  138.  
  139.     }
  140.      }
  141.  
  142.     randum[1] = (rand() % 6 + 1);
  143.     if(randum[1] == 3){
  144.         mon = 1;
  145.     }
  146.     else {
  147.         mon = 0;
  148.     }
  149.     //mon is the varible which tells us to either go back to the move sequence or to the battle sequence
  150.    
  151.     randum[5] = (rand() % 10 + 1);
  152.     //this is for random health potions, you have a 1/10th chance of getting one
  153.     if(randum[5]==2){
  154.         cout << "You have found a health potion!" << "\n";
  155.         hp = hp +1;
  156.            
  157.     }
  158.    
  159.     string dir;
  160.     if (dun2==0 & pos[1]==5 & pos[2]==3) {
  161.         goto townA;
  162.     }
  163.     if (dun2==0 & pos[1]==4 & pos[2]==5) {
  164.         dun=1;
  165.     }
  166.    
  167.     else {
  168.         dun=0;
  169.     }
  170.    
  171.    
  172.     while(dun==1) {
  173.         cout << "You have entered the caverns!" << "\n" << "It is a 30 x 30 plane" << "\n";
  174.         dun2=1;
  175.         poso[1]=pos[1];
  176.         poso[2]=pos[2];
  177.         pos[1]=0;
  178.         pos[2]=0;
  179.         dun=0;
  180.     }
  181.     if (dun2==1 & pos[1]==15 & pos[2]==15 & inv[1]==0) {
  182.         cout << "you have found the golden guantlets!" << "\n";
  183.         inv[1]==1;
  184.         goto move;
  185.     }
  186.     if (dun2==1 & pos[1]==3 & pos[2]==5 & inv[2] < 3) {
  187.         cout << "you have found a long sword!" << "\n";
  188.             inv[2]=3;
  189.     }
  190.  
  191.    
  192.     if(dun2==1 & pos[2] >= 30 || dun2==1 & pos[1] >= 30 || dun2==1 & pos[2] < 0 || dun2==1 & pos[1] < 0){
  193.         cout << "There's a wall there!" << "\n";
  194.         if(pos[1] >= 30)
  195.         {pos[1]=29;}
  196.         if(pos[2] >= 30)
  197.         {pos[2]=29;}
  198.         if(pos[1] < 0)
  199.         {pos[1]=0;}
  200.         if(pos[2] < 0)
  201.         {pos[2]=0;}
  202.     }
  203.  
  204.     cout << "Your current vertical position is: " << pos[1] << ".\n";
  205.     cout << "Your current Horizontal position is: " << pos[2] << ".\n";
  206.     cout << "Your current exprirence is: " << expr << ".\n";
  207.     cout << "Your current level is: " <<  lvl << ".\n";
  208.     cout << "Your current health is: " << health << ".\n";
  209.     if(debugmode==true){
  210.         cout << "Debug mode enabled!" << "\n";
  211.        
  212.     }
  213.     if(bnm==1){
  214.         mon=0;
  215.     }
  216.  
  217.     cout << "What would you like to do?";
  218.     cin >> dir;
  219.     if(dir=="N" || dir=="n") {
  220.         pos[1] = pos[1] + 1;
  221.         if(mon==1)
  222.             goto battle;
  223.         else if(mon==0)
  224.             goto move;
  225.     }
  226.     if(dir=="S" || dir=="s") {
  227.         pos[1] = pos[1] - 1;
  228.         if(mon==1)
  229.             goto battle;
  230.         else if(mon==0)
  231.             goto move;
  232.     }
  233.     if (dir=="E" || dir=="e") {
  234.         pos[2] = pos[2] + 1;
  235.         if(mon==1)
  236.             goto battle;
  237.         else if(mon==0)
  238.             goto move;
  239.     }
  240.        
  241.         if(dir=="W" || dir=="w") {
  242.         pos[2] = pos[2] - 1;
  243.         if(mon==1)
  244.             goto battle;
  245.         else if(mon==0)
  246.             goto move;
  247.     }
  248.         if(dir=="Save" || dir=="save") {
  249.         ofstream save;
  250.         save.open ("save.txt");
  251.          save << pos[1] << "\n" << pos[2] << "\n" << health << "\n" << expr << "\n" << lvl << "\n" << inv[1] << "\n" << inv[2] << "\n" << hp << "\n" << gold << "\n" << dun2 << "\n" << poso[1] << "\n" << poso[2] << "\n";
  252.          save.close();
  253.          cout << "Saved succesfully" << ".\n";
  254.          goto move;
  255.     }
  256.        
  257.         if (dun2>=1 & dir=="leave" || dir=="leave")
  258.            
  259.             {
  260.                 dun2 = 0;
  261.                     cout << "You have left" << "\n";
  262.                 pos[1]=poso[1];
  263.                 pos[2]=poso[2];
  264.                 goto move;
  265.             }
  266.            
  267.             if(dir=="iamjesus") {
  268.                 cout << "You have entered debug mode!" << "\n";
  269.                 debugmode=true;
  270.                 goto move;
  271.  
  272.             }
  273.             if(dir=="inv" || dir=="Inv"){
  274.             invret = 1;
  275.                 goto inv;
  276.         }
  277.             if(debugmode==true & dir=="health"){
  278.                 cout << "You are changing your health, what would you like it to be?" << "\n";
  279.                 cin >> debug;
  280.                 hp = atoi(debug.c_str());
  281.                 goto move;
  282.             }
  283.             if(debugmode==true & dir=="vpos"){
  284.                 cout << "Set your new vertical position: ";
  285.             cin >> debug;
  286.             pos[1] = atoi(debug.c_str());
  287.                 goto move;
  288.             }
  289.             if(debugmode==true & dir=="hpos"){
  290.                 cout << "Set your new Horizontl position: ";
  291.                 cin >> debug;
  292.                 pos[2] = atoi(debug.c_str());
  293.                     goto move;
  294.             }
  295.             if(debugmode==true & dir=="bnm"){
  296.                 bnm = 1;
  297.                 cout << "Monsters have been disabled!";
  298.                
  299.                 goto move;
  300.             }
  301.  
  302.  
  303.         else {
  304.             cout << "That is not a valid command" << ".\n";
  305.             goto move;
  306.         }
  307.    
  308.  
  309.        
  310.    
  311.    
  312. battle:
  313.         //This is the battle sequence if the position has mon=1
  314.         //next we roll to see which monster it is
  315.         srand(time(0));
  316.     randum[2] = (rand() % 6 + 1);
  317.     cout << "You have encourted a wild: ";
  318.         if(randum[2]==1){
  319.             monster="Imp";
  320.             cout << monster << "\n";
  321.             //next we roll for its level, but it's max is actually 1 level above your level
  322.             srand(time(0));
  323.             tlvl = lvl + 1;
  324.              monlvl = (rand() % tlvl + 1);
  325.             monatk = 5*sqrt(monlvl/sqrt(lvl)) * 2;
  326.             monhealth = 2.33 * sqrt(monlvl) *100;
  327.             goto battleseq;
  328.            
  329.  
  330.  
  331.        
  332.         }
  333.         else {
  334.             monster = "Flying pig";
  335.             cout << monster << "\n";
  336.         srand(time(0));
  337.             tlvl = lvl + 3;
  338.             monlvl = (rand() % tlvl + 1);
  339.             monatk = 5*sqrt(monlvl/sqrt(lvl))* 1;
  340.             monhealth = 2.33 * sqrt(monlvl) *100;
  341.             goto battleseq;
  342.         }
  343. battleseq:
  344.         if(health<=0){
  345.             cout << "you died!" << "\n";
  346.                 goto start;
  347.         }
  348.  
  349.             if(monhealth<=0){
  350.                 cout << "The " << monster << " Has been defeated!" << "\n";
  351.                     //next we award expirence
  352.                 expr = expr + (monlvl + monatk) / (sqrt(lvl) + sqrt(atk));
  353.                 if(expr >= 100){
  354.                     lvl = 2;
  355.                         goto move;
  356.                 }
  357.                 if(expr >= 300){
  358.                     lvl = 3;
  359.                         goto move;
  360.                 }
  361.                 if(expr >= 500){
  362.                     lvl = 4;
  363.                         goto move;
  364.                 }
  365.                 if(expr >= 700){
  366.                     lvl = 5;
  367.                         goto move;
  368.                 }
  369.                 if(expr >= 1000){
  370.                     lvl = 6;
  371.                         goto move;
  372.                 }
  373.                 else{
  374.                     lvl = 1;
  375.                     goto move;
  376.             }
  377.             }
  378.             else {
  379.     cout << "Its level is " << monlvl << "\n";
  380.     cout << "Its attack strength is: " << monatk << "\n";
  381.     //we must generate your attacking strength
  382.     atk = 5*sqrt(lvl/sqrt(monlvl)) * inv[2];
  383.     cout << "Your attack strength is: " << atk << "\n";
  384.     //now we have to generate the defencive strength
  385.     def = 4*sqrt(lvl)+sqrt(atk);
  386.     mondef = 4*sqrt(monlvl)+sqrt(monatk);
  387.     cout << "Its defnsive strength is: " << mondef << "\n";
  388.     cout << "Your defesive strength is: " << def << "\n";
  389.     cout << "Your health is: " << health << "\n";
  390.     cout << "Its health is: " << monhealth << "\n";
  391.     cout << "What will you do? ";
  392.     cin >> battledir;
  393.     if(battledir=="A" || battledir=="a") {
  394.         cout << "You attacked for: ";
  395.         //now we need to do the damage calculations
  396.         dmg = ((2* lvl  +2) * (atk / mondef) /50 ) + 2 * ((rand() % 100 + 50) ) /10;
  397.         cout << dmg << "Damage" << "\n";
  398.         monhealth = monhealth - dmg;
  399.         mondmg = ((2* monlvl  +2) * (monatk / def) /50 ) + 2 * ((rand() % 100 + 50)) /10;
  400.         cout << "It attacked for: " << mondmg << " Damage" << "\n";
  401.         health = health - mondmg;
  402.         goto battleseq;
  403.     }
  404.  
  405.     if(battledir=="Run" || battledir=="run"){
  406.         //this is what pussies do
  407.         //instead of attacking, you get a 5/6th chance of escaping back to move phase, but the monster will still do damage
  408.         mondmg = ((2* monlvl  +2) * (monatk / def) /50 ) + 2 * ((rand() % 100 + 50) ) /10;
  409.         cout << "It attacked for: " << mondmg << " Damage"<< "\n" ;
  410.         health = health - mondmg;
  411.         srand(time(0));
  412.     randum[3] = (rand() % 6 + 1);
  413.     if(randum[3]!=4){
  414.         cout << "you succesfully escaped!" << "\n";
  415.         goto move;
  416.     }
  417.     if(randum[3]==4){
  418.         cout << "You did not escape! :c" << "\n";
  419.         goto battleseq;
  420.     }
  421.     }
  422.     if(battledir=="inv" || battledir=="Inv"){
  423.         invret=2;
  424.             goto inv;
  425.     }
  426.    
  427.  
  428.     else {
  429.         cout << "Invalid command" << "\n";
  430.         goto battleseq;
  431.     }
  432.  
  433.    
  434.    
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.             }
  442. townA:
  443.             cout << "Welcome to stormdale, brother!" << "\n";
  444.             cout << "What would you like to do?" << "\n";
  445.             cin >> towndir;
  446.             if(towndir=="leave" || towndir=="Leave"){
  447.                 pos[1]=pos[1]+1;
  448.                 pos[2]=pos[2]+1;
  449.                 goto move;
  450.             }
  451.             if(towndir=="quest" || towndir=="Quest"){
  452.                 goto questlog;
  453.             }
  454.             if(towndir=="inv" || towndir=="Inv"){
  455.                 invret=3;
  456.                 goto inv;
  457.             }
  458.            
  459.            
  460.            
  461. questlog:
  462.             if(quest==0){
  463.                 if(inv[1]==0){
  464.                 cout << "Alright rookie, this is your first quest!" << "\n";
  465.                 cout << "I need you to go to the caverns and retrive the golden guantlets, alright?" << "\n";
  466.                     goto townA;
  467.                 }
  468.                 if(inv[1]==1){
  469.                     cout << "Alright, good job!" << "\n";
  470.                     cout << "Here's some gold and expirence!" << "\n";
  471.                         quest =1;
  472.                     gold = gold + 30;
  473.                         expr = expr +60;
  474.                             goto townA;
  475.                 }
  476. inv:
  477.                 cout << "You have: " << "\n";
  478.                 cout << hp << "x Health potions" << "\n";
  479.                 cout << gold << " Gold" << "\n";
  480.  
  481.                 if(inv[1]==1){
  482.                     cout << "Golden guantlets" << "\n";
  483.                 }
  484.                 cout << "Your current weapon is: ";
  485.                 if(inv[2]==2){
  486.                     cout << "Short sword" << "\n";
  487.                 }
  488.                 if(inv[2]==3){
  489.                     cout << "Long sword" << "\n";
  490.                 }
  491.                 if(inv[2]==4){
  492.                     cout << "Sword of Death!" << "\n";
  493.                 }
  494.  
  495.  
  496.                 cout << "What would you like to do?" << "\n";
  497.                 cin >> invdir;
  498.                 if(invdir=="Heal" || invdir=="heal"){
  499.                     if(hp>=1){
  500.                         hp = hp -1;
  501.                             health = health +50;
  502.                             cout << "You have recovered 50 health!" << "\n";
  503.                             goto inv;
  504.                     }
  505.                     if(hp<=0){
  506.                         cout << "Sorry, you need a health potion" << "\n";
  507.                         goto inv;
  508.  
  509.                     }
  510.                 }
  511.                 if(invdir=="exit" || invdir=="Exit"){
  512.                     if(invret==1){
  513.                         invret=0;
  514.                         goto move;
  515.                     }
  516.                     if(invret==2){
  517.                         invret=0;
  518.                         goto battleseq;
  519.                        
  520.                     }
  521.                     if(invret==3){
  522.                         invret=0;
  523.                         goto townA;
  524.  
  525.                     }
  526.                     else {
  527.                         cout << "An error has occured, somone herped in the derp" << "\n";
  528.                     goto inv;
  529.                     }
  530.                 }
  531.                     else {
  532.                         cout << "Invalid command" << "\n";
  533.                         goto inv;
  534.                     }
Advertisement
Add Comment
Please, Sign In to add comment