Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <vector>
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctime>
- #include <math.h>
- using namespace std;
- int _tmain(int argc, _TCHAR* argv[])
- {
- start:
- cout << "Text-rpg Engine (c) 2012 piexil" << ".\n";
- string load;
- cout << "Would you like to load (Y/N)?" << ".\n";
- //Loading of the varibles time
- bool debugmode;
- int bnm;
- int dun;
- int dun2;
- int gold;
- int inv[30];
- //inv is for quest items, such as the golden guantlet which is inv[1]
- int hp;
- int invret;
- int quest;
- int wepbonus;
- int pos[2];
- int poso[2];
- int expr;
- int mon;
- int health;
- float lvl;
- int randum[5];
- float dmg;
- float mondmg;
- float monlvl;
- int tlvl;
- float monhealth;
- float monatk;
- float atk;
- float def;
- float mondef;
- string debug;
- string invdir;
- string towndir;
- string battledir;
- string monster;
- string l;
- string lo;
- string line;
- vector <string> v ;
- //setting the deafualts for the varibles
- inv[2] = 2;
- //inv[2] is your current weapon
- bnm = 0;
- debugmode = false;
- dun=0;
- dun2=0;
- poso[1] = 0;
- poso[2] = 0;
- invret = 0;
- gold = 0;
- inv[1] = 0;
- monlvl = 1;
- expr = 0;
- lvl = 1;
- health = 2.33 * sqrt(lvl) *100 ;
- mon = 0;
- pos[1] = 0;
- pos[2] = 0;
- quest = 0;
- hp = 1;
- wepbonus = 1;
- //pos[1] is the veritical position, pos [2] is the horizontal
- cin >> load;
- if(load=="Y" || load=="y"){
- ifstream lo ("save.txt");
- if (lo.is_open())
- {
- while ( lo.good() )
- {
- while (getline(lo, l))
- {
- v.push_back( l);
- }
- //this is strictly for debuging purposes
- cout << "line 1 = " << v[1] << endl;
- //since the vector for loading the save file is a string, we must cionvert to integers
- pos[1] = atoi(v[0].c_str());
- pos[2] = atoi(v[1].c_str());
- health = atoi(v[2].c_str());
- expr = atoi(v[3].c_str());
- lvl = atoi(v[4].c_str());
- inv[1]= atoi(v[5].c_str());
- inv[2]= atoi(v[6].c_str());
- hp = atoi(v[7].c_str());
- gold = atoi(v[8].c_str());
- dun2 = atoi(v[9].c_str());
- poso[1]= atoi(v[10].c_str());
- poso[2]= atoi(v[11].c_str());
- goto move;
- }
- lo.close();
- }
- else cout << "Unable to open file";
- }
- if(load=="N" || "n"){
- goto move;
- }
- move:
- //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
- srand(time(0));
- if(dun2==1){randum[1] = (rand() % 3 + 1);
- if(randum[1] == 3){
- mon = 1;
- //this if statement is for the debug mode were you can disable monsters
- }
- }
- randum[1] = (rand() % 6 + 1);
- if(randum[1] == 3){
- mon = 1;
- }
- else {
- mon = 0;
- }
- //mon is the varible which tells us to either go back to the move sequence or to the battle sequence
- randum[5] = (rand() % 10 + 1);
- //this is for random health potions, you have a 1/10th chance of getting one
- if(randum[5]==2){
- cout << "You have found a health potion!" << "\n";
- hp = hp +1;
- }
- string dir;
- if (dun2==0 & pos[1]==5 & pos[2]==3) {
- goto townA;
- }
- if (dun2==0 & pos[1]==4 & pos[2]==5) {
- dun=1;
- }
- else {
- dun=0;
- }
- while(dun==1) {
- cout << "You have entered the caverns!" << "\n" << "It is a 30 x 30 plane" << "\n";
- dun2=1;
- poso[1]=pos[1];
- poso[2]=pos[2];
- pos[1]=0;
- pos[2]=0;
- dun=0;
- }
- if (dun2==1 & pos[1]==15 & pos[2]==15 & inv[1]==0) {
- cout << "you have found the golden guantlets!" << "\n";
- inv[1]==1;
- goto move;
- }
- if (dun2==1 & pos[1]==3 & pos[2]==5 & inv[2] < 3) {
- cout << "you have found a long sword!" << "\n";
- inv[2]=3;
- }
- if(dun2==1 & pos[2] >= 30 || dun2==1 & pos[1] >= 30 || dun2==1 & pos[2] < 0 || dun2==1 & pos[1] < 0){
- cout << "There's a wall there!" << "\n";
- if(pos[1] >= 30)
- {pos[1]=29;}
- if(pos[2] >= 30)
- {pos[2]=29;}
- if(pos[1] < 0)
- {pos[1]=0;}
- if(pos[2] < 0)
- {pos[2]=0;}
- }
- cout << "Your current vertical position is: " << pos[1] << ".\n";
- cout << "Your current Horizontal position is: " << pos[2] << ".\n";
- cout << "Your current exprirence is: " << expr << ".\n";
- cout << "Your current level is: " << lvl << ".\n";
- cout << "Your current health is: " << health << ".\n";
- if(debugmode==true){
- cout << "Debug mode enabled!" << "\n";
- }
- if(bnm==1){
- mon=0;
- }
- cout << "What would you like to do?";
- cin >> dir;
- if(dir=="N" || dir=="n") {
- pos[1] = pos[1] + 1;
- if(mon==1)
- goto battle;
- else if(mon==0)
- goto move;
- }
- if(dir=="S" || dir=="s") {
- pos[1] = pos[1] - 1;
- if(mon==1)
- goto battle;
- else if(mon==0)
- goto move;
- }
- if (dir=="E" || dir=="e") {
- pos[2] = pos[2] + 1;
- if(mon==1)
- goto battle;
- else if(mon==0)
- goto move;
- }
- if(dir=="W" || dir=="w") {
- pos[2] = pos[2] - 1;
- if(mon==1)
- goto battle;
- else if(mon==0)
- goto move;
- }
- if(dir=="Save" || dir=="save") {
- ofstream save;
- save.open ("save.txt");
- 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";
- save.close();
- cout << "Saved succesfully" << ".\n";
- goto move;
- }
- if (dun2>=1 & dir=="leave" || dir=="leave")
- {
- dun2 = 0;
- cout << "You have left" << "\n";
- pos[1]=poso[1];
- pos[2]=poso[2];
- goto move;
- }
- if(dir=="iamjesus") {
- cout << "You have entered debug mode!" << "\n";
- debugmode=true;
- goto move;
- }
- if(dir=="inv" || dir=="Inv"){
- invret = 1;
- goto inv;
- }
- if(debugmode==true & dir=="health"){
- cout << "You are changing your health, what would you like it to be?" << "\n";
- cin >> debug;
- hp = atoi(debug.c_str());
- goto move;
- }
- if(debugmode==true & dir=="vpos"){
- cout << "Set your new vertical position: ";
- cin >> debug;
- pos[1] = atoi(debug.c_str());
- goto move;
- }
- if(debugmode==true & dir=="hpos"){
- cout << "Set your new Horizontl position: ";
- cin >> debug;
- pos[2] = atoi(debug.c_str());
- goto move;
- }
- if(debugmode==true & dir=="bnm"){
- bnm = 1;
- cout << "Monsters have been disabled!";
- goto move;
- }
- else {
- cout << "That is not a valid command" << ".\n";
- goto move;
- }
- battle:
- //This is the battle sequence if the position has mon=1
- //next we roll to see which monster it is
- srand(time(0));
- randum[2] = (rand() % 6 + 1);
- cout << "You have encourted a wild: ";
- if(randum[2]==1){
- monster="Imp";
- cout << monster << "\n";
- //next we roll for its level, but it's max is actually 1 level above your level
- srand(time(0));
- tlvl = lvl + 1;
- monlvl = (rand() % tlvl + 1);
- monatk = 5*sqrt(monlvl/sqrt(lvl)) * 2;
- monhealth = 2.33 * sqrt(monlvl) *100;
- goto battleseq;
- }
- else {
- monster = "Flying pig";
- cout << monster << "\n";
- srand(time(0));
- tlvl = lvl + 3;
- monlvl = (rand() % tlvl + 1);
- monatk = 5*sqrt(monlvl/sqrt(lvl))* 1;
- monhealth = 2.33 * sqrt(monlvl) *100;
- goto battleseq;
- }
- battleseq:
- if(health<=0){
- cout << "you died!" << "\n";
- goto start;
- }
- if(monhealth<=0){
- cout << "The " << monster << " Has been defeated!" << "\n";
- //next we award expirence
- expr = expr + (monlvl + monatk) / (sqrt(lvl) + sqrt(atk));
- if(expr >= 100){
- lvl = 2;
- goto move;
- }
- if(expr >= 300){
- lvl = 3;
- goto move;
- }
- if(expr >= 500){
- lvl = 4;
- goto move;
- }
- if(expr >= 700){
- lvl = 5;
- goto move;
- }
- if(expr >= 1000){
- lvl = 6;
- goto move;
- }
- else{
- lvl = 1;
- goto move;
- }
- }
- else {
- cout << "Its level is " << monlvl << "\n";
- cout << "Its attack strength is: " << monatk << "\n";
- //we must generate your attacking strength
- atk = 5*sqrt(lvl/sqrt(monlvl)) * inv[2];
- cout << "Your attack strength is: " << atk << "\n";
- //now we have to generate the defencive strength
- def = 4*sqrt(lvl)+sqrt(atk);
- mondef = 4*sqrt(monlvl)+sqrt(monatk);
- cout << "Its defnsive strength is: " << mondef << "\n";
- cout << "Your defesive strength is: " << def << "\n";
- cout << "Your health is: " << health << "\n";
- cout << "Its health is: " << monhealth << "\n";
- cout << "What will you do? ";
- cin >> battledir;
- if(battledir=="A" || battledir=="a") {
- cout << "You attacked for: ";
- //now we need to do the damage calculations
- dmg = ((2* lvl +2) * (atk / mondef) /50 ) + 2 * ((rand() % 100 + 50) ) /10;
- cout << dmg << "Damage" << "\n";
- monhealth = monhealth - dmg;
- mondmg = ((2* monlvl +2) * (monatk / def) /50 ) + 2 * ((rand() % 100 + 50)) /10;
- cout << "It attacked for: " << mondmg << " Damage" << "\n";
- health = health - mondmg;
- goto battleseq;
- }
- if(battledir=="Run" || battledir=="run"){
- //this is what pussies do
- //instead of attacking, you get a 5/6th chance of escaping back to move phase, but the monster will still do damage
- mondmg = ((2* monlvl +2) * (monatk / def) /50 ) + 2 * ((rand() % 100 + 50) ) /10;
- cout << "It attacked for: " << mondmg << " Damage"<< "\n" ;
- health = health - mondmg;
- srand(time(0));
- randum[3] = (rand() % 6 + 1);
- if(randum[3]!=4){
- cout << "you succesfully escaped!" << "\n";
- goto move;
- }
- if(randum[3]==4){
- cout << "You did not escape! :c" << "\n";
- goto battleseq;
- }
- }
- if(battledir=="inv" || battledir=="Inv"){
- invret=2;
- goto inv;
- }
- else {
- cout << "Invalid command" << "\n";
- goto battleseq;
- }
- }
- townA:
- cout << "Welcome to stormdale, brother!" << "\n";
- cout << "What would you like to do?" << "\n";
- cin >> towndir;
- if(towndir=="leave" || towndir=="Leave"){
- pos[1]=pos[1]+1;
- pos[2]=pos[2]+1;
- goto move;
- }
- if(towndir=="quest" || towndir=="Quest"){
- goto questlog;
- }
- if(towndir=="inv" || towndir=="Inv"){
- invret=3;
- goto inv;
- }
- questlog:
- if(quest==0){
- if(inv[1]==0){
- cout << "Alright rookie, this is your first quest!" << "\n";
- cout << "I need you to go to the caverns and retrive the golden guantlets, alright?" << "\n";
- goto townA;
- }
- if(inv[1]==1){
- cout << "Alright, good job!" << "\n";
- cout << "Here's some gold and expirence!" << "\n";
- quest =1;
- gold = gold + 30;
- expr = expr +60;
- goto townA;
- }
- inv:
- cout << "You have: " << "\n";
- cout << hp << "x Health potions" << "\n";
- cout << gold << " Gold" << "\n";
- if(inv[1]==1){
- cout << "Golden guantlets" << "\n";
- }
- cout << "Your current weapon is: ";
- if(inv[2]==2){
- cout << "Short sword" << "\n";
- }
- if(inv[2]==3){
- cout << "Long sword" << "\n";
- }
- if(inv[2]==4){
- cout << "Sword of Death!" << "\n";
- }
- cout << "What would you like to do?" << "\n";
- cin >> invdir;
- if(invdir=="Heal" || invdir=="heal"){
- if(hp>=1){
- hp = hp -1;
- health = health +50;
- cout << "You have recovered 50 health!" << "\n";
- goto inv;
- }
- if(hp<=0){
- cout << "Sorry, you need a health potion" << "\n";
- goto inv;
- }
- }
- if(invdir=="exit" || invdir=="Exit"){
- if(invret==1){
- invret=0;
- goto move;
- }
- if(invret==2){
- invret=0;
- goto battleseq;
- }
- if(invret==3){
- invret=0;
- goto townA;
- }
- else {
- cout << "An error has occured, somone herped in the derp" << "\n";
- goto inv;
- }
- }
- else {
- cout << "Invalid command" << "\n";
- goto inv;
- }
Advertisement
Add Comment
Please, Sign In to add comment