#include #include #include #include using namespace std; class Game { public: int menu(); int newGame(); int save(); int load(); int changePlace(); int town(); int house(); int gym(); int battle(); int attack(); int flee(); int lift(); int weap(); int beat(); int choice, place; string name, mname; int mclass; int exp; int m[3]; double hp; int atk; int str; int def; int mon; double mhp; int matk; int mstr; int mdef; int temp; }; int Game::menu() { system("cls"); choice = 0; place = 0; cout <<"\n\n WELCOME TO SIMPLE TEXT RPG 1.0\n\n"; cout <<" 1 - NEW GAME\n"; cout <<" 2 - LOAD GAME\n"; cout <<"> "; cin >>choice; cin.ignore(); switch (choice) { case 1: newGame(); break; case 2: load(); break; default: menu(); } return 0; } int Game::newGame() { system("cls"); place = 2; hp = 100; atk = 5; str = 5; def = 1; mon = 50; exp = 0; cout <<"\n\nYou have decided to start a new game! What is your name?\n"; cout <<"> "; cin >>name; cin.ignore(); ofstream data("save"); data <>hp; data >>atk; data >>str; data >>def; data >>name; data >>place; data >>mon; data >>exp; } else { cout <<"Error loading data!\n"; cin.get(); changePlace(); } data.close(); cout <<"Data loaded! successfully!\n"; cin.get(); changePlace(); return 0; } int Game::changePlace() { switch (place) { case 0: menu(); break; case 1: house(); break; case 2: town(); break; default: changePlace(); } return 0; } int Game::town() { system("cls"); choice = 0; mclass = m[rand() % 3]; if (mclass == 1) { mname = "Ghost"; mhp = 30; matk = 1; mstr = 1; mdef = 10; } else if (mclass == 2) { mname = "Goblin"; mhp = 25; matk = 3; mstr = 5; mdef = 1; } else if (mclass == 3) { mname = "Ghoul"; mhp = 40; matk = 5; mstr = 9; mdef = 3; } else if (mclass == 0) { mname = "Pixie"; mhp = 10; matk = 2; mstr = 5; mdef = 1; } cout <<"HP " < "; cin >>choice; cin.ignore(); switch (choice) { case 1: house(); break; case 2: gym(); break; case 3: battle(); break; default: town(); } return 0; } int Game::house() { system("cls"); choice = 0; place = 1; hp = 100; cout <<"HP " < "; cin >>choice; cin.ignore(); switch (choice) { case 1: save(); break; case 2: menu(); break; case 3: town(); break; default: house(); break; } return 0; } int Game::gym() { system("cls"); choice = 0; cout <<"HP " < "; cin >>choice; cin.ignore(); switch (choice) { case 1: lift(); break; case 2: weap(); break; case 3: beat(); break; case 4: town(); break; default: gym(); } return 0; } int Game::lift() { system("cls"); if (mon >= 50) { temp = rand() % 5 + 1; mon -= 50; cout <<"You pay fifty dollars and lift weights! (+ " <= 75) { temp = rand() % 5 + 1; mon -= 75; cout <<"You pay seventy-five dollars and practice weaponary! (+ " <= 40) { temp = rand() % 3 + 1; mon -= 40; cout <<"You pay fourty dollars and endure a beating! (+ " < "; cin >>choice; cin.get(); goto choose; idle: system("cls"); cout <<"HP " < "; cin >>choice; cin.get(); choose: switch (choice) { case 1: attack(); break; case 2: flee(); break; default: goto idle; break; } return 0; } int Game::attack() { system("cls"); int chance = rand() % 200 + 50; if (chance >= 100) { cout <<"MHP " <