#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" << ".

" ;

string load ;

cout << "Would you like to load (Y/N)?" << ".

" ;

//Loading of the varibles time

int pos [ 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 battledir ;

string monster ;

string l ;

string lo ;

string line ;

vector < string > v ;

//setting the deafualts for the varibles

monlvl = 1 ;

expr = 0 ;

lvl = 1 ;

health = 100 ;

mon = 0 ;

pos [ 1 ] = 0 ;

pos [ 2 ] = 0 ;

//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 ) ;

}

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 ( ) ) ;

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 ) ) ;

randum [ 1 ] = ( rand ( ) % 10 + 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

string dir ;

cout << "Your current vertical position is: " << pos [ 1 ] << ".

" ;

cout << "Your current Horizontal position is: " << pos [ 2 ] << ".

" ;

cout << "Your current exprirence is: " << expr << ".

" ;

cout << "Your current level is: " << lvl << ".

" ;

cout << "Your current health is: " << health << ".

" ;

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 ] << "

" << pos [ 2 ] << "

" << health << "

" << expr << "

" << lvl << "

" ;

save. close ( ) ;

cout << "Saved succesfully" << ".

" ;

goto move ;

}

else {

cout << "That is not a valid command" << ".

" ;

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 << "

" ;

//next we roll for its level, but it's max is actually 3 levels above your level

srand ( time ( 0 ) ) ;

tlvl = lvl + 3 ;

monlvl = ( rand ( ) % tlvl + 1 ) ;

monatk = 5 * sqrt ( monlvl ) ;

monhealth = 100 ;

goto battleseq ;

}

else {

monster = "Flying Cock" ;

cout << monster << "

" ;

srand ( time ( 0 ) ) ;

tlvl = lvl + 3 ;

monlvl = ( rand ( ) % tlvl + 1 ) ;

monatk = 5 * sqrt ( monlvl ) ;

monhealth = 100 ;

goto battleseq ;

}

battleseq :

if ( health <= 0 ) {

cout << "you died!" << "

" ;

goto start ;

}

if ( monhealth <= 0 ) {

cout << "The " << monster << " Has been defeated!" << "

" ;

//next we award expirence

expr = expr + sqrt ( monlvl ) + monatk / sqrt ( lvl ) + 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 = 7 ;

goto move ;

}

}

else {

cout << "Its level is " << monlvl << "

" ;

cout << "Its attack strength is: " << monatk << "

" ;

//we must generate your attacking strength

atk = 5 * sqrt ( lvl ) ;

cout << "Your attack strength is: " << atk << "

" ;

//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 << "

" ;

cout << "Your defesive strength is: " << def << "

" ;

cout << "Your health is: " << health << "

" ;

cout << "Its health is: " << monhealth << "

" ;

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 / 5 + 2 ) * ( atk / mondef ) / 50 ) + 2 * ( ( rand ( ) % 100 + 85 ) / 10 ) ;

cout << dmg << "Damage" << "

" ;

monhealth = monhealth - dmg ;

mondmg = ( ( 2 * monlvl / 5 + 2 ) * ( monatk / def ) / 50 ) + 2 * ( ( rand ( ) % 100 + 85 ) / 10 ) ;

cout << "It attacked for: " << mondmg << " Damage" << "

" ;

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 / 5 + 2 ) * ( monatk / def ) / 50 ) + 2 * ( ( rand ( ) % 100 + 85 ) / 10 ) ;

cout << "It attacked for: " << mondmg << " Damage" << "

" ;

health = health - mondmg ;

srand ( time ( 0 ) ) ;

randum [ 3 ] = ( rand ( ) % 6 + 1 ) ;

if ( randum [ 3 ] ! = 4 ) {

cout << "you succesfully escaped!" << "

" ;

goto move ;

}

if ( randum [ 3 ] == 4 ) {

cout << "You did not escape! :c" << "

" ;

goto battleseq ;

}

}

}