Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // txtrpg1tst.cpp : Defines the entry point for the console application.
- //
- #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" << "\n";
- string load;
- cout << "Would you like to load (Y/N)?" << "\n" << "\n";
- //Loading of the varibles time
- bool debugmode;
- //defines if debug mode is enabled
- int bnm;
- //tells the system whether or not to go through with RME
- int dun;
- //Dungeon modifier
- int dun2;
- //Dungeon Identifier
- int gold;
- //Well, it's fucking gold
- int inv[30];
- //inv is for quest items, such as the golden guantlet which is inv[1]
- int wep;
- //defines weapons
- int hp;
- //Health
- int invret;
- //tells the system where to return after using the inventory
- int quest[10][100] = {0};
- //The fist int is the Town identifier, the second is the quest identifier
- int wepbonus;
- //wepon stat bonuses
- int pos[2];
- //current position
- int poso[2];
- //saving position outside of the Dungeon
- int expr;
- //expirence
- int mon;
- //Monster
- int health;
- int town;
- 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
- wep = 2;
- //wep 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;
- hp = 1;
- inv[2] = 0;
- 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());
- wep= 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" << "\n";
- hp = hp +1;
- }
- string dir;
- if (dun2==0 & pos[1]==5 & pos[2]==3) {
- goto townA;
- }
- //if statements for dungeons
- if (dun2==0 & pos[1]==4 & pos[2]==5) {
- dun=1;
- //dun1 is dungeon modifier
- }
- if (dun2==0 & pos[1]==20 & pos[2]==7) {
- dun=1;
- }
- else {
- dun=0;
- }
- while(dun==1) {
- //we need to check positions again to tell which cavern we are in
- if (dun2==0 & pos[1]==4 & pos[2]==5){
- cout << "You have entered the caverns!" << "\n" << "\n" << "It is a 30 x 30 plane" << "\n" << "\n";
- dun2=1;
- }
- if (dun2==0 & pos[1]==20 & pos[2]==7) {
- cout << "You have entered the dubsky caves!" << "\n" << "\n" << "It is a 25 x 25 plane" << "\n" << "\n";
- dun2=2;
- }
- 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" << "\n";
- inv[1]=1;
- goto move;
- }
- if (dun2==1 & pos[1]==3 & pos[2]==5 & wep < 3) {
- cout << "you have found a long sword!" << "\n" << "\n";
- wep=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" << "\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;}
- }
- if(dun2==2 & pos[2] >= 25 || dun2==1 & pos[1] >= 25 || dun2==1 & pos[2] < 0 || dun2==1 & pos[1] < 0){
- cout << "There's a wall there!" << "\n" << "\n";
- if(pos[1] >= 30)
- {pos[1]=24;}
- if(pos[2] >= 30)
- {pos[2]=24;}
- if(pos[1] < 0)
- {pos[1]=0;}
- if(pos[2] < 0)
- {pos[2]=0;}
- }
- cout << "Your current vertical position is: " << pos[1] << "\n" << "\n";
- cout << "Your current Horizontal position is: " << pos[2] << "\n" << "\n";
- cout << "Your current exprirence is: " << expr << "\n" << "\n";
- cout << "Your current level is: " << lvl << "\n" << "\n";
- cout << "Your current health is: " << health << "\n" << "\n";
- if(debugmode==true){
- cout << "Debug mode enabled!" << "\n" << "\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" << "\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";
- save.close();
- cout << "Saved succesfully" << "\n" << "\n";
- goto move;
- }
- if (dun2>=1 & dir=="leave" || dir=="leave")
- {
- dun2 = 0;
- cout << "You have left" << "\n" << "\n";
- pos[1]=poso[1];
- pos[2]=poso[2];
- goto move;
- }
- if(dir=="iamjesus") {
- cout << "You have entered debug mode!" << "\n" << "\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" << "\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" << "\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" << "\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);
- monatk = 5*sqrt(monlvl/sqrt(lvl)) * 2;
- monhealth = 2.33 * sqrt(monlvl) *100;
- goto battleseq;
- }
- if(randum[2]==2 & dun2==2){
- monster="Headless Mutant";
- cout << monster << "\n" << "\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);
- monatk = 5*sqrt(monlvl/sqrt(lvl)) * 2;
- monhealth = 1 * sqrt(monlvl) *100;
- goto battleseq;
- }
- else {
- monster = "Flying pig";
- cout << monster << "\n" << "\n";
- srand(time(0));
- tlvl = lvl + 3;
- monlvl = (rand() % tlvl);
- monatk = 5*sqrt(monlvl/sqrt(lvl))* 1;
- monhealth = 2.33 * sqrt(monlvl) *100;
- goto battleseq;
- }
- battleseq:
- if(health<=0){
- cout << "you died!" << "\n" << "\n";
- goto start;
- }
- if(monhealth<=0){
- cout << "The " << monster << " Has been defeated!" << "\n" << "\n";
- if(monster=="Headless Mutant" & quest[1][2] == 0){
- inv[2] = inv[2] + 1;
- }
- //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" << "\n";
- cout << "Its attack strength is: " << monatk << "\n" << "\n";
- //we must generate your attacking strength
- atk = 5*sqrt(lvl/sqrt(monlvl)) * wep;
- cout << "Your attack strength is: " << atk << "\n" << "\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" << "\n";
- cout << "Your defesive strength is: " << def << "\n" << "\n";
- cout << "Your health is: " << health << "\n" << "\n";
- cout << "Its health is: " << monhealth << "\n" << "\n";
- if(dun2==2 & quest[1][2]==0){
- cout << "You have killed " << inv[2] << " Headless mutants" << "\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" << "\n";
- monhealth = monhealth - dmg;
- mondmg = ((2* monlvl +2) * (monatk / def) /50 ) + 2 * ((rand() % 100 + 50)) /10;
- cout << "It attacked for: " << mondmg << " Damage" << "\n" << "\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" << "\n" ;
- health = health - mondmg;
- srand(time(0));
- randum[3] = (rand() % 6 + 1);
- if(randum[3]!=4){
- cout << "you succesfully escaped!" << "\n" << "\n";
- goto move;
- }
- if(randum[3]==4){
- cout << "You did not escape! :c" << "\n" << "\n";
- goto battleseq;
- }
- }
- if(battledir=="inv" || battledir=="Inv"){
- invret=2;
- goto inv;
- }
- else {
- cout << "Invalid command" << "\n" << "\n";
- goto battleseq;
- }
- }
- townA:
- town = 1;
- cout << "Welcome to stormdale, brother!" << "\n" << "\n";
- cout << "What would you like to do?" << "\n" << "\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 (town = 1){
- if(quest[1][1]==0){
- if(inv[1]==0){
- cout << "Alright rookie, this is your first quest!" << "\n" << "\n";
- cout << "I need you to go to the caverns and retrive the golden guantlets, alright?" << "\n" << "\n";
- goto townA;
- }
- if(inv[1]==1){
- cout << "Alright, good job!" << "\n" << "\n";
- cout << "Here's some gold and expirence!" << "\n" << "\n";
- quest[1][1] =1;
- gold = gold + 30;
- expr = expr +60;
- inv[1]=0;
- goto townA;
- }
- if (quest[1][1]==1 & quest[1][2]==0)
- {
- cout << "Alright, you have to go to dubsky caves and kill 10 headless mutants" << "\n" << "\n";
- goto townA;
- }
- }
- inv:
- cout << "You have: " << "\n" << "\n";
- cout << hp << "x Health potions" << "\n" << "\n";
- cout << gold << " Gold" << "\n" << "\n";
- if(inv[1]==1){
- cout << "Golden guantlets" << "\n" << "\n";
- }
- cout << "Your current weapon is: ";
- if(wep==2){
- cout << "Short sword" << "\n" << "\n";
- }
- if(wep==3){
- cout << "Long sword" << "\n" << "\n";
- }
- if(wep==4){
- cout << "Sword of Death!" << "\n" << "\n";
- }
- cout << "What would you like to do?" << "\n" << "\n";
- cin >> invdir;
- if(invdir=="Heal" || invdir=="heal"){
- if(hp>=1){
- hp = hp -1;
- health = health +50;
- cout << "You have recovered 50 health!" << "\n" << "\n";
- goto inv;
- }
- if(hp<=0){
- cout << "Sorry, you need a health potion" << "\n" << "\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" << "\n";
- goto inv;
- }
- }
- else {
- cout << "Invalid command" << "\n" << "\n";
- goto inv;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement