Advertisement
piexil

RPG engine .59

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