rendered paste body#include <iostream>#include <fstream>#include <string>#include <math.h>#include <cstdlib>#include <ctime>using namespace std;class Game {public: int menu(); int newGame(); int save(); int load(); int town(); int house(); int gym(); int battle(); int attack(); int flee(); int lift(); int weap(); int beat(); int changePlace(); string mname, name; int choice; int place; int exp; int mon; int temp; string talk; int hp; int mhp; int mclass; int m[7]; int atk; int matk; int str; double mstr; double def; double mdef;};int Game::menu() { system("cls"); choice = 0; place = 0; cout <<"\n\n Welcome to Kingdom of Losers\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 = 1; hp = 100; atk = 5; str = 5; def = 1; exp = 5; mon = 200; cout <<"You started a new game!\n"; cin.get(); system("cls"); cout <<"What will you be known as?\n"; cout <<"> "; cin >>name; cin.ignore(); system("cls"); ofstream data("save"); data <<hp <<endl; data <<atk <<endl; data <<str <<endl; data <<def <<endl; data <<exp <<endl; data <<mon <<endl; data <<name <<endl; data <<place; data.close(); cout <<"Data saved successfully!\n"; cin.get(); changePlace(); return 0;}int Game::load() { system("cls"); place = 0; ifstream data("save"); if (data.is_open()) { data >>hp; data >>atk; data >>str; data >>def; data >>exp; data >>mon; data >>name; data >>place; } else { cout <<"Error loading data! Either you not saved or the file is corrupted!\n"; cin.get(); changePlace(); } cout <<"Data loaded successfully!\n"; cin.get(); changePlace(); return 0;}int Game::save() { system("cls"); place = 2; ofstream data("save"); data <<hp <<endl; data <<atk <<endl; data <<str <<endl; data <<def <<endl; data <<exp <<endl; data <<mon <<endl; data <<name <<endl; data <<place; data.close(); cout <<"Data saved successfully!\n"; cin.get(); changePlace(); return 0;}int Game::changePlace() { switch (place) { case 1: town(); break; case 2: house(); break; case 0: menu(); break; default: changePlace(); } return 0;}int Game::town() { system("cls"); choice = 0; mclass = m[rand() % 7 + 1]; if (mclass == 1) { mname = "Flame Troll"; mhp = 45; mstr = 3; matk = 4; mdef = 5; } else if (mclass == 2) { mname = "Bean Bat"; mhp = 20; mstr = 1; matk = 2; mdef = 1; } else if (mclass == 3) { mname = "Ocelot"; mhp = 50; mstr = 4; matk = 5; mdef = 3; } else if (mclass == 4) { mname = "Anti-anti anti-don't-dote Monster"; mhp = 40; mstr = 2; matk = 2; mdef = 2; } else if (mclass == 5) { mname = "Zmobie"; mhp = 10; mstr = 5; matk = 5; mdef = 1; } else if (mclass == 6) { mname = "Jackalope"; mhp = 30; mstr = 3; matk = 4; mdef = 2; } else if (mclass == 7) { mname = "Council of Losers"; mhp = 50; mstr = 5; matk = 5; mdef = 5; } cout <<"HP "<<hp<<" STR "<<str<<" ATK "<<atk<<" DEF "<<def <<" EXP "<<exp<<"\n";; cout <<"MONEY "<<mon<<"\n\n\n\n"; cout <<"You enter the deserted place. A few shacks surround where you stand.\n\n"; cout <<" 1 - Your House\n"; cout <<" 2 - Gym\n"; cout <<" 3 - Battle\n"; cout <<"> "; 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 = 2; cout <<"HP "<<hp<<" STR "<<str<<" ATK "<<atk<<" DEF "<<def <<" EXP "<<exp<<"\n"; cout <<"MONEY "<<mon<<"\n\n\n\n"; cout <<"You step inside the homey, shack, glacing around in awe at the antiques you decoratively placed up on the walls.\n\n"; cout <<" 1 - Save\n"; cout <<" 2 - Menu\n"; cout <<" 3 - Rest\n"; cout <<" 4 - Leave\n"; cout <<"> "; cin >>choice; cin.ignore(); switch (choice) { case 1: save(); break; case 2: menu(); break; case 3: system("cls"); cout <<"You slip under the silk covers and fall asleep.\n"; cin.get(); system("cls"); cout <<"You wake up, and stretch. You're refreshed. (HP fully restored)"; cin.get(); hp = 100; house(); break; case 4: town(); break; default: house(); break; } return 0;}int Game::gym() { system("cls"); choice = 0; cout <<"HP "<<hp<<" STR "<<str<<" ATK "<<atk<<" DEF "<<def <<" EXP "<<exp<<"\n"; cout <<"MONEY "<<mon<<"\n\n\n\n"; cout <<"The breezy air condition slaps your face. You gaze at all the equipment scattered across the place.\n\n"; cout <<" 1 - Lift Weights (str)\n"; cout <<" 2 - Practice Swordplay (atk)\n"; cout <<" 3 - Endure beating (def)\n"; cout <<" 4 - Leave\n"; cout <<"> "; 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 >= 40) { mon -= 40; srand(time(NULL)); cout <<"You lift a "<<str * rand() % str + 1<<" lb weight and start doing some bi-ceps.\n"; cin.get(); temp = rand() % exp + 1; cout <<"You gain "<<temp<<" str!"; cin.get(); str += temp; gym(); } else { cout <<"You cannot pay for the weights!\n"; cin.get(); gym(); } return 0;}int Game::weap() { system("cls"); if (mon >= 75) { mon -= 75; srand(time(NULL)); cout <<"You pay for a sword and start lunging it around. You feel as if you learned a new technique.\n"; cin.get(); temp = rand() % exp - 2 + 1; cout <<"You gain "<<temp<<" atk!"; cin.get(); atk += temp; gym(); } else { cout <<"You cannot pay for a sword!\n"; cin.get(); gym(); } return 0;}int Game::beat() { system("cls"); if (mon >= 20) { mon -= 20; srand(time(NULL)); cout <<"You pay this tough-looking guy twenty bucks to punch you in the stomach. You grimace.\n"; cin.get(); temp = rand() % exp - 1 + 1; cout <<"You gain "<<def<<" def!"; cin.get(); def += temp; gym(); } else { cout <<"You find anyone suitable to give you a beating!\n"; cin.get(); gym(); } return 0;}int Game::battle() { system("cls"); choice = 0; cout <<"You're fighting a "<<mname<<"!\n\n"; cout <<" 1 - Attack\n"; cout <<" 2 - Flee\n"; cout <<"> "; cin >>choice; cin.ignore(); switch (choice) { case 1: attack(); break; case 2: flee(); break; default: battle(); } return 0;}int Game::attack() { system("cls"); srand(time(NULL)); int chance = rand() % 200 + 50; if (chance >= 100) { cout <<mname <<" - HP "<<mhp<<" STR "<<mstr<<" ATK "<<matk<<" DEF "<<mdef<<"\n\n\n\n"; cout <<"You strike for "<<atk + str - mdef<<" damage!\n"; cin.get(); mhp -= atk + str - mdef; } else if (chance < 100) { cout <<"HP "<<hp<<" STR "<<str<<" ATK "<<atk<<" DEF "<<def <<" EXP "<<exp<<"\n"; cout <<"MONEY "<<mon<<"\n\n\n\n"; cout <<mname<<" strikes for "<<mstr + matk - def<<" damage!\n"; cin.get(); hp -= matk + mstr - def; } if (hp <= 0) { cout <<"You died.\n"; cin.get(); load(); } else if (mhp <= 0) { cout <<"You won the battle!\n"; cin.get(); temp = rand() % 40 - 10 + 1; cout <<"+ "<<temp<<" money.\n"; cin.get(); mon += temp; temp = rand() % mhp/2 + 25; cout <<"+ "<<temp<<" exp.\n"; cin.get(); exp += temp; town(); } battle(); return 0;}int Game::flee() { cout <<"You fled like a sissy.\n"; cin.get(); town(); return 0;} int main(void) { Game game; game.menu(); game.m[1] = 1; game.m[2] = 2; game.m[3] = 3; game.m[4] = 4; game.m[5] = 5; game.m[6] = 6; game.m[7] = 7; return 0;}