Advertisement
piexil

Txt RPG engine A.55

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