online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
#include <cstdlib> // For several general-purpose functions #include <fstream> // For file handling #include <iomanip> // For formatted output #include <iostream> // For cin, cout, and system #include <string> // For string data type #include <vector> using namespace std; // So "std::cout" may be abbreviated to "cout" class Character { protected: int hp; int attackPower; public: virtual void setHP(int temp) = 0; virtual int getHP() const = 0; virtual void setAttackPower(int temp) = 0; virtual int getAttackPower() const = 0; }; class Item { private: int type; int value; public: const bool isHP(); const bool isDefense(); const int getValue(); Item(int a, int b); }; const bool Item::isHP() { if (type == 0) { return true; } return false; } const bool Item::isDefense() { if (type == 1) { return true; } return false; } const int Item::getValue() { return value; } Item::Item(int a, int b) { type = a; value = b; } class Monster : public Character { friend ostream& operator<<(ostream& osAObject, Monster mon); public: void decreaseAttackPower(); Monster(int a, int b); void setHP(int a); int getHP()const; void setAttackPower(int ap); int getAttackPower()const; Monster operator+(Monster m); }; void Monster::decreaseAttackPower() { if (attackPower > 1) { attackPower--; } } Monster::Monster(int a, int b) { setHP(a); setAttackPower(b); } void Monster::setHP(int a) { if (a > 1) { hp = a; } else { hp = 0; } } int Monster::getHP() const { return hp; } void Monster::setAttackPower(int ap) { if (ap > 1) { attackPower = ap; } else { attackPower = 1; } } int Monster::getAttackPower() const { return attackPower; } Monster Monster::operator+(Monster m) { Monster* temp = new Monster(1, 1); temp->setHP(this->getHP() + m.getHP()); temp->setAttackPower(this->getAttackPower() + m.getAttackPower()); return *temp; } ostream& operator<<(ostream& osAObject, Monster mon) { osAObject << "HP: " << mon.getHP() << "Attackpower: " << mon.getAttackPower(); return osAObject; } class Room { private: string name; Room* east; Room* west; Room* north; Room* south; Monster* roomMonster; Item* roomItem; bool exit; public: void setName(string alpha); string getName() const; void setEastRoom(Room* x); void setWestRoom(Room* x); void setNorthRoom(Room* x); void setSouthRoom(Room* x); Room* getEastRoom() const; Room* getWestRoom() const; Room* getNorthRoom() const; Room* getSouthRoom() const; void setRoomMonster(Monster* m); Monster* getRoomMonster(); void setRoomItem(Item* n); Item* getRoomItem(); bool isExit(); Room(string alpha, Room* e, Room* w, Room* s, Room* n, Monster* mon, Item* itm); Room(string alpha, Room* e, Room* w, Room* s, Room* n, Monster* mon); Room(string alpha, Room* e, Room* w, Room* s, Room* n, Item* itm); Room(string alpha, Room* e, Room* w, Room* s, Room* n, bool ex); }; void Room::setName(string alpha) { name = alpha; } string Room::getName() const { return name; } void Room::setEastRoom(Room* x) { east = x; } void Room::setWestRoom(Room* x) { west = x; } void Room::setNorthRoom(Room* x) { north = x; } void Room::setSouthRoom(Room* x) { south = x; } Room* Room::getEastRoom() const { return east;; } Room* Room::getWestRoom() const { return west; } Room* Room::getNorthRoom() const { return north; } Room* Room::getSouthRoom() const { return south; } void Room::setRoomMonster(Monster* m) { roomMonster = m; } Monster* Room::getRoomMonster() { return roomMonster; } void Room::setRoomItem(Item* n) { roomItem = n; } Item* Room::getRoomItem() { return roomItem; } bool Room::isExit() { return exit; } Room::Room(string alpha, Room* e, Room* w, Room* s, Room* n, Monster* mon, Item* itm) : Room(alpha, e, w, s, n, false) { roomMonster = mon; roomItem = itm; } Room::Room(string alpha, Room* e, Room* w, Room* s, Room* n, Monster* mon) : Room(alpha, e, w, s, n, false) { roomMonster = mon; roomItem = nullptr; } Room::Room(string alpha, Room* e, Room* w, Room* s, Room* n, Item* itm) : Room(alpha, e, w, s, n, false) { roomMonster = nullptr; roomItem = itm; } Room::Room(string alpha, Room* e, Room* w, Room* s, Room* n, bool ex) { name = alpha; exit = ex; east = e; west = w; north = n; south = s; } class RoomInfo { public: string direction; // n e s w string roomName; Room* roomAdress; // memory address of room }; class Hero : public Character { private: int defensePower; int retreatCount; public: Item* bag[3]; const int getDefensePower(); void decreaseDefensePower(); void setDefensePower(int p); const int getRetreatCount(); void decreaseRetreatCount(); const bool anyItems(); const bool isAlive(); int operator*(Monster& m); Hero(int hp, int ap, int dp, int rc); void setHP(int a); int getHP()const; void setAttackPower(int ap); int getAttackPower()const; }; const int Hero::getDefensePower() { return defensePower; } void Hero::decreaseDefensePower() { if (defensePower > 1) { defensePower--; } } void Hero::setDefensePower(int p) { if (p >= 1) { defensePower = p; } else { defensePower = 1; } } const int Hero::getRetreatCount() { return retreatCount; } void Hero::decreaseRetreatCount() { if (retreatCount > 0) { retreatCount--; } } const bool Hero::anyItems() { for (int i = 0; i < 3; i++) { if (bag[i] != nullptr) { return true; } } return false; } const bool Hero::isAlive() { if (this->hp > 0) { return true; } return false; } int Hero::operator*(Monster& m) { m.setHP(m.getHP() - this->getAttackPower() < 0 ? 0 : m.getHP() - this->getAttackPower()); this->setHP(this->getHP() - m.getAttackPower() / this->getDefensePower()); m.decreaseAttackPower(); this->decreaseDefensePower(); if (this->isAlive() == false) // hero died return -1; else if (m.getHP() <= 0) // monster died return 1; else // no character died return 0; } void Hero::setHP(int a) { if (a > 1) { hp = a; } else hp = 0; } int Hero::getHP() const { return hp; } void Hero::setAttackPower(int ap) { if (ap > 1) { attackPower = ap; } else attackPower = 1; } int Hero::getAttackPower() const { return attackPower; } Hero::Hero(int hp, int ap, int dp, int rc) { setHP(hp); setAttackPower(ap); setDefensePower(dp); if (rc >= 0) { retreatCount = rc; } else { retreatCount = 0; } bag[0] = nullptr; bag[1] = nullptr; bag[2] = nullptr; } class Game { public: Hero HeroName; void run(); Game(); private: void createMap(); Room* currentRoom; Room* previousRoom; }; void Game::createMap() { // Map // n // ^ // | // w <--ROOM--> e // | // ; // s // // [B0 Kitchen] [D0 Backyard][Exit] // | | // [Start] [A1 Entrance] <==> [B1 Living Room] <==> [C1 Dining Room] <==> [D1 Great Room]<==>[E1 Garage] // | | // [B2 Bathroom] [C2 Pantry] // // Monster* Mahnoor = new Monster(50, 5); // creating first monster Monster* Dora = new Monster(15, 4); // creating second monster Monster* Azra = new Monster(65,6); // creating 3rd monster Item* HalalBurger = new Item(0, 15); // creating item to increase hp Item* TrashCan = new Item(1, 1); // creating item to increase defense Item* PepperSpray = new Item(1, 2); // creating item to increase defense // Creating a map with 9 rooms, each connected without a cycle and one exit room and entrance. Room* A1 = new Room("Start Room", nullptr, nullptr, nullptr, nullptr, false); Room* B1 = new Room("Living Room", nullptr, A1, nullptr, nullptr, false); A1->setEastRoom(B1); Room* B0 = new Room("Kitchen", nullptr, nullptr, B1, nullptr, TrashCan); B1->setNorthRoom(B0); Room* B2 = new Room("Bathroom", nullptr, nullptr, nullptr, B1, Dora, PepperSpray); B1->setSouthRoom(B2); Room* C1 = new Room("Dining Room", B1, nullptr, nullptr, nullptr, Mahnoor); B1->setEastRoom(C1); C1->setWestRoom(B1); Room* C2 = new Room("Pantry", nullptr, nullptr, nullptr, C1, HalalBurger); C1->setSouthRoom(C2); Room* D1 = new Room("Great Room", C1, nullptr, nullptr, nullptr, false); C1->setEastRoom(D1); D1->setWestRoom(C1); Room* D0 = new Room("Backyard", nullptr, nullptr, nullptr, D1, true); D1->setNorthRoom(D0); Room* E1 = new Room("Garage", nullptr, D1, nullptr, nullptr, Azra); D1->setEastRoom(E1); currentRoom = A1; previousRoom = nullptr; } void Game::run() { int userInput; string heroNameInput; cout << "Welcome to Hero Escape!" // Application header w game guide << "\n-----------------------" << endl << "\nMap Name: Azra's Haunted House" << endl << "\nGame's Guide: Move your hero through multiple rooms of the map in order to" << "\nreach the MYSTERY exit room. Be AWARE, the rooms throughout the map contain DANGEROUS monsters" << "\nsuch as Azra and her SCARY friends, Mahnoor and Dora, who will HURT you at all costs! Look out" << "\nfor items to aid in your battle and use your ability to retreat from a room wisely!" << endl; cout << "\nWhat is your Hero's Name? "; cin >> heroNameInput; while (!currentRoom->isExit()) { /* LAYOUT of WHILE LOOP // Show room infos // if Retreating options // Move to previous room while(p-> next != null) { previous = p; p = ->next; } //Decrease retreat count // if Hero has items options // use an item process // if Hero is alive // does current room have items if // picking up items // execute move process // if current room is an exit // display congrats // else // game is over */ // Show room infos cout << "\n\nRoom Information" << endl << "----------------" << endl; //Output of map if (currentRoom->getName() == "Start Room") { cout << "\t\t\t [ Kitchen]\t\t\t\t [ Backyard]" << "\n\t\t\t\t|\t\t \t\t\t|\n" << "[ *HERE* Entrance] <==> [ Living Room] <==> [ Dining Room] <==> [ Great Room]<==>[ Garage]" << "\n\t\t\t\t|\t\t |\n" << "\t\t\t [ Bathroom]\t\t[ Pantry]\n\n"; } else if (currentRoom->getName() == "Living Room") { cout << "\t\t\t [ Kitchen]\t\t\t\t [ Backyard]" << "\n\t\t\t\t|\t\t \t\t\t|\n" << "[ Entrance] <==> [ *HERE* Living Room] <==> [ Dining Room] <==> [ Great Room]<==>[ Garage]" << "\n\t\t\t\t|\t\t |\n" << "\t\t\t [ Bathroom]\t\t[ Pantry]\n\n"; } else if (currentRoom->getName() == "Kitchen") { cout << "\t\t [ *HERE* Kitchen]\t\t\t [ Backyard]" << "\n\t\t\t|\t\t \t\t\t|\n" << "[ Entrance] <==> [ Living Room] <==> [ Dining Room] <==> [ Great Room]<==>[ Garage]" << "\n\t\t\t|\t\t |\n" << "\t\t [ Bathroom]\t\t[ Pantry]\n\n"; } else if (currentRoom->getName() == "Bathroom") { cout << "\t\t [ Kitchen]\t\t\t\t [ Backyard]" << "\n\t\t\t|\t\t \t\t\t|\n" << "[ Entrance] <==> [ Living Room] <==> [ Dining Room] <==> [ Great Room]<==>[ Garage]" << "\n\t\t\t|\t\t |\n" << "\t\t [ *HERE* Bathroom]\t [ Pantry]\n\n"; } else if (currentRoom->getName() == "Dining Room") { cout << "\t\t [ Kitchen]\t\t\t\t\t [ Backyard]" << "\n\t\t\t|\t\t \t\t\t\t|\n" << "[ Entrance] <==> [ Living Room] <==> [ *HERE* Dining Room] <==> [ Great Room]<==>[ Garage]" << "\n\t\t\t|\t\t |\n" << "\t\t [ Bathroom]\t\t [ Pantry]\n\n"; } else if (currentRoom->getName() == "Pantry") { cout << "\t\t [ Kitchen]\t\t\t\t [ Backyard]" << "\n\t\t\t|\t\t \t\t\t|\n" << "[ Entrance] <==> [ Living Room] <==> [ Dining Room] <==> [ Great Room]<==>[ Garage]" << "\n\t\t\t|\t\t |\n" << "\t\t [ Bathroom]\t\t[ *HERE* Pantry]\n\n"; } else if (currentRoom->getName() == "Great Room") { cout << "\t\t [ Kitchen]\t\t\t\t [ Backyard]" << "\n\t\t\t|\t\t \t\t\t|\n" << "[ Entrance] <==> [ Living Room] <==> [ Dining Room] <==> [ *HERE* Great Room]<==>[ Garage]" << "\n\t\t\t|\t\t |\n" << "\t\t [ Bathroom]\t\t[ Pantry]\n\n"; } else if (currentRoom->getName() == "Garage") { cout << "\t\t [ Kitchen]\t\t\t\t [ Backyard]" << "\n\t\t\t|\t\t \t\t\t|\n" << "[ Entrance] <==> [ Living Room] <==> [ Dining Room] <==> [ Great Room]<==>[ *HERE* Garage]" << "\n\t\t\t|\t\t |\n" << "\t\t [ Bathroom]\t\t[ Pantry]\n\n"; } else { continue; } // Display items, monster, and hero characteristics cout << "Name: " << currentRoom->getName() << endl << "Monster: "; if (currentRoom->getRoomMonster() == nullptr) { cout << "None\n"; } else { if (currentRoom->getRoomMonster()->getHP() > 20 && currentRoom->getRoomMonster()->getHP() < 55) { cout << "Mahnoor ~ "; } else if (currentRoom->getRoomMonster()->getHP() < 20) { cout << "Dora ~ "; } else { cout << "Azra ~ "; } cout << "HP " << currentRoom->getRoomMonster()->getHP() << " Attack Power: " << currentRoom->getRoomMonster()->getAttackPower() << endl; } cout << "Item: "; if (!currentRoom->getRoomItem()) { cout << "None\n"; } else { if (currentRoom->getRoomItem()->isHP()) { if (currentRoom->getRoomItem()->getValue() == 15) { cout << "Halal Burger" << " HP: " << currentRoom->getRoomItem()->getValue() << endl; } } else { if (currentRoom->getRoomItem()->getValue() == 1) { cout << "Trash Can" << " Defense Power: " << currentRoom->getRoomItem()->getValue() << endl; } else { cout << "Pepper Spray " << "Defense Power: " << currentRoom->getRoomItem()->getValue() << endl; } } } cout << "----------------" << endl; cout << "\n" << heroNameInput <<": HP: " << HeroName.getHP() << " Attack Power: " << HeroName.getAttackPower() << " Defense Power: " << HeroName.getDefensePower() << " Retreat Count: " << HeroName.getRetreatCount() << endl; // if Retreating options if (previousRoom != nullptr) { if (HeroName.getRetreatCount() > 0) { cout << "\nWould you like to retreat? [yes/no]: "; string optionChoice = ""; cin >> optionChoice; if (optionChoice == "yes" || optionChoice == "YES" || optionChoice == "Yes" || optionChoice == "YeS" || optionChoice == "yEs" || optionChoice == "yeS" || optionChoice == "YEs" || optionChoice == "yES" || optionChoice == "y" || optionChoice == "Y") { //Move to previous room using swap Room* temp; temp = currentRoom; currentRoom = previousRoom; previousRoom = temp; //decrease retreat count HeroName.decreaseRetreatCount(); continue; } } } // if Hero has items options if (HeroName.anyItems()) { cout << "\nWould you like to use an item? [yes/no] "; string itemChoice = ""; cin >> itemChoice; if (itemChoice == "yes" || itemChoice == "YES" || itemChoice == "Yes" || itemChoice == "YeS" || itemChoice == "yEs" || itemChoice == "yeS" || itemChoice == "YEs" || itemChoice == "yES" || itemChoice == "y" || itemChoice == "Y") { // use an item process /* display dynamically, not hardcoded 1. Create the menu based on the information of the bag 2. NULL values can be shown as empty spaces. 3. If user select an empty SPACE, just let the user know that that cannot be used, and continue the game. 4. If use selects a non-empty SPACE: 4a. Apply the item on the hero 4b. Remove the item from memory. */ for (int i = 0; i < 3; i++) { if (HeroName.bag[i] == nullptr) { cout << i + 1 << ". Empty" << endl; } else { if (HeroName.bag[i]->isHP()) { if (HeroName.bag[i]->getValue() == 15) { cout << i + 1 << ". Halal Burger" << endl; } } else { if (HeroName.bag[i]->getValue() == 1) { cout << i + 1 << ". Trash Can" << endl; } else { cout << i + 1 << ". Pepper Spray" << endl; } } } } int choice; std::cout << "choice: "; std::cin >> choice; std::cout << "\n"; while (HeroName.bag[choice - 1] == nullptr) { cout << "There is no item in " << choice << endl; std::cout << "choice: "; std::cin >> choice; std::cout << "\n"; } switch (choice) { case 1: if (HeroName.bag[choice - 1]->isHP()) { if (HeroName.bag[choice - 1]->getValue() == 15) { cout << "You ate Halal Burger! HP increased by 15" << endl; HeroName.setHP(HeroName.getHP() + 15); HeroName.bag[choice - 1] = nullptr; break; } } else { if (HeroName.bag[choice - 1]->getValue() == 1) { cout << "You equipped Trash Can! Defense increased by 1" << endl; HeroName.setDefensePower(HeroName.getDefensePower() + 1); HeroName.bag[choice - 1] = nullptr; break; } else { cout << "You equipped Pepper Spray! Defense increased by 2" << endl; HeroName.setDefensePower(HeroName.getDefensePower() + 2); HeroName.bag[choice - 1] = nullptr; break; } } case 2: if (currentRoom->getRoomItem()->isHP()) { if (currentRoom->getRoomItem()->getValue() == 15) { cout << "You ate Halal Burger! HP increased by 15"; HeroName.setHP(HeroName.getHP() + 15); HeroName.bag[choice - 1] = nullptr; break; } } else { if (currentRoom->getRoomItem()->getValue() == 1) { cout << "You equipped Trash Can! Defense increased by 1"; HeroName.setDefensePower(HeroName.getDefensePower() + 1); HeroName.bag[choice - 1] = nullptr; break; } else { cout << "You equipped Pepper Spray! Defense increased by 2"; HeroName.setDefensePower(HeroName.getDefensePower() + 2); HeroName.bag[choice - 1] = nullptr; break; } } case 3: if (HeroName.bag[choice - 1]->isHP()) { if (HeroName.bag[choice - 1]->getValue() == 15) { cout << "You ate Halal Burger! HP increased by 15" << endl; HeroName.setHP(HeroName.getHP() + 15); HeroName.bag[choice - 1] = nullptr; break; } } else { if (HeroName.bag[choice - 1]->getValue() == 1) { cout << "You equipped Trash Can! Defense increased by 1" << endl; HeroName.setDefensePower(HeroName.getDefensePower() + 1); HeroName.bag[choice - 1] = nullptr; break; } else { cout << "You equipped Pepper Spray! Defense increased by 2" << endl; HeroName.setDefensePower(HeroName.getDefensePower() + 2); HeroName.bag[choice - 1] = nullptr; break; } } } } } // Hero vs Monster battle if (currentRoom->getRoomMonster() != nullptr) { int status = 0; if (currentRoom->getRoomMonster()->getHP() > 20 && currentRoom->getRoomMonster()->getHP() < 55) { cout << "\nMonster Mahnoor"; } if (currentRoom->getRoomMonster()->getHP() < 20 && currentRoom->getRoomMonster()->getHP() > 0) { cout << "\nMonster Dora"; } if (currentRoom->getRoomMonster()->getHP() > 50) { cout << "\nMonster Azra"; } cout << " Approached, Battle Begins!\n" << endl; while (status == 0) { status = HeroName * (*(currentRoom->getRoomMonster())); // Hero and Monster battle cout << "Pow!!" << "\tBam!" << endl << "\t\tBoom!" << "\t\tKaboom!!!" << endl; // battle action words // output of hero hp and dp & Monster hp and ap cout << "\n" << heroNameInput << ": HP: " << HeroName.getHP() << " Defense Power: " << HeroName.getDefensePower() << endl; cout << "Monster: HP " << currentRoom->getRoomMonster()->getHP() << " Attack Power: " << currentRoom->getRoomMonster()->getAttackPower() << endl << endl; cout << "Wham!" << "\t\tBang!!!" << endl << "\tWow!" << "\t\t\tCrash!!" << endl; //battle action words } if (status == 1) { cout << "\nThe Monster has been defeated!" << endl; currentRoom->setRoomMonster(nullptr); } if (status == -1) { cout << "\nThe Monster has won the battle!" << endl; currentRoom->setRoomMonster(nullptr); break; } } // if Hero is alive if (HeroName.isAlive()) { // does current room have any items if (currentRoom->getRoomItem() != nullptr) { // want to pick it up cout << "\nWould you like to pick up "; if (currentRoom->getRoomItem()->isHP()) { if (currentRoom->getRoomItem()->getValue() == 15) { cout << "Halal Burger"; } } else { if (currentRoom->getRoomItem()->getValue() == 1) { cout << "Trash Can"; } else { cout << "Pepper Spray"; } } // execute pick up item cout << " [yes/no]: "; string pickUpChoice; cin >> pickUpChoice; if (pickUpChoice == "yes" || pickUpChoice == "YES" || pickUpChoice == "Yes" || pickUpChoice == "YeS" || pickUpChoice == "yEs" || pickUpChoice == "yeS" || pickUpChoice == "YEs" || pickUpChoice == "yES" || pickUpChoice == "y" || pickUpChoice == "Y") { cout << "\nBag: " << endl; for (int i = 0; i < 3; i++) { if (HeroName.bag[i] == nullptr) { cout << i + 1 << ". Empty" << endl; } else { if (HeroName.bag[i]->isHP()) { if (HeroName.bag[i]->getValue() == 15) { cout << i + 1 << ". Halal Burger" << endl; } } else { if (HeroName.bag[i]->getValue() == 1) { cout << i + 1 << ". Trash Can" << endl; } else { cout << i + 1 << ". Pepper Spray" << endl; } } } } cout << "\nWhich position would you like to store the item? "; int position; std::cin >> position; switch (position) { /* assume valid input User selects option X if bag[X] is null bag[X] = currentRoom.getItem(); currentRoom.setItem(nullptr); else bag[X] is not null delete bag[X]; bag[X] = currentRoom.getItem(); currentRoom.setItem(nullptr); */ case 1: if (HeroName.bag[0] == nullptr) { HeroName.bag[0] = currentRoom->getRoomItem(); currentRoom->setRoomItem(nullptr); } else { delete HeroName.bag[0]; HeroName.bag[0] = currentRoom->getRoomItem(); currentRoom->setRoomItem(nullptr); } break; case 2: if (HeroName.bag[1] == nullptr) { HeroName.bag[1] = currentRoom->getRoomItem(); currentRoom->setRoomItem(nullptr); } else { delete HeroName.bag[1]; HeroName.bag[1] = currentRoom->getRoomItem(); currentRoom->setRoomItem(nullptr); } break; case 3: if (HeroName.bag[2] == nullptr) { HeroName.bag[2] = currentRoom->getRoomItem(); currentRoom->setRoomItem(nullptr); } else { delete HeroName.bag[2]; HeroName.bag[2] = currentRoom->getRoomItem(); currentRoom->setRoomItem(nullptr); } break; } } } } // execute move process //For each option: include direction, name of room, and memory address vector<RoomInfo> menuObj; RoomInfo Ntemp, Stemp, Etemp, Wtemp; // To store in vector int countTemp = 0; // Creating a menu cout << "\nRoom: " << currentRoom->getName() << endl; if (currentRoom->getNorthRoom() != nullptr) { Ntemp.direction = "North"; Ntemp.roomName = currentRoom->getNorthRoom()->getName(); Ntemp.roomAdress = currentRoom->getNorthRoom(); menuObj.push_back(Ntemp); countTemp++; } if (currentRoom->getSouthRoom() != nullptr) { Stemp.direction = "South"; Stemp.roomName = currentRoom->getSouthRoom()->getName(); Stemp.roomAdress = currentRoom->getSouthRoom(); menuObj.push_back(Stemp); countTemp++; } if (currentRoom->getEastRoom() != nullptr) { Etemp.direction = "East"; Etemp.roomName = currentRoom->getEastRoom()->getName(); Etemp.roomAdress = currentRoom->getEastRoom(); menuObj.push_back(Etemp); countTemp++; } if (currentRoom->getWestRoom() != nullptr) { Wtemp.direction = "West"; Wtemp.roomName = currentRoom->getWestRoom()->getName(); Wtemp.roomAdress = currentRoom->getWestRoom(); menuObj.push_back(Wtemp); countTemp++; } // Displaying a menu for (int i = 0; i < menuObj.size(); i++) { cout << i + 1 << ") "; //option num cout << menuObj.at(i).direction << ": "; // direction cout << menuObj.at(i).roomName << endl; // room name } if (countTemp == 1) { cout << "Select a direction [Enter 1 only]: "; cin >> userInput; } else { cout << "Select a direction [Enter between 1-" << countTemp << "]: "; cin >> userInput; } previousRoom = currentRoom; // store current room in prev room before update currentRoom = menuObj.at(userInput - 1).roomAdress; // Assume a valid option is entered } // if current room is an exit if (currentRoom->isExit()) { //display congrats std::cout << "\nCongratulations you found the mystery exit room of Backyard!\n"; } // else //game is over else { std::cout << "\nGame over ~ You Lost!\n"; } }; Game::Game() : HeroName(49, 5, 2, 1) { createMap(); } int main() { Game HeroEscape; HeroEscape.run(); }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue