void displayRoom(vector<Room> &roomStorage, vector<Item> &itemStorage, vector<Critter> &critterStorage, Player &player, Room &room, int id) { for (int i = 0; i < roomStorage.size(); i++) { if (roomStorage[i].getRoomId() == id) { room = roomStorage[i]; roomStorage[i].setVisited(true); } } room.displayName(); cout << endl; if (!room.getDark() || player.getHasLight()) { room.displayDesc(); cout << endl; room.displayRoomItems(itemStorage); room.displayCritter(critterStorage); cout << endl; room.displayDirections(); cout << endl; } else { cout << "It's dark and you can't see anything!" << endl; } }
bool callFunction(vector<Room> &roomStorage,vector<Item> &itemStorage, vector<Critter> &critterStorage, Room &room, Player &player, int filter,string command) { int id; vector<string> commands; vector<string> items; string com; string com1; string com2; stringstream ss(command); bool gameOver; bool itemPresent = false; bool accuseCondition = false; while (ss >> com) { commands.push_back(com); } com1 = commands[0]; //Basically, if input is not "QUIT", it should be a 2 word command and safe to assign com2 to the second element of commands if (filter != 9999) { com2 = commands[1]; } switch (filter) { case -1: //invalid command gameOver = false; break; case 1: //go or move if (com2 == "NORTH" || com2 == "SOUTH" || com2 == "EAST" || com2 == "WEST" || com2 == "UP" || com2 == "DOWN") { if (com2 == "NORTH") { id = room.getNorth(); } else if (com2 == "SOUTH") { id = room.getSouth(); } else if (com2 == "EAST") { id = room.getEast(); } else if (com2 == "WEST") { id = room.getWest(); } else if (com2 == "UP") { id = room.getUp(); } else if (com2 == "DOWN") { id = room.getDown(); } if (id == -1) { cout << "You can't " << com1 << " "<< com2 << ". Try another command" << endl; gameOver = false; break; } else if (checkLock(roomStorage, id)) { cout << "I'm sorry. That room is locked." << endl; gameOver = false; break; } else { if (room.getDark() && !player.getHasLight()) { cout << "You can't see to go anywhere!" << endl; gameOver = false; break; } else { if (id == 43) { setCritters(roomStorage); } displayRoom(roomStorage, itemStorage, critterStorage, player, room, id); gameOver = false; break; } } } else { cout << "I don't understand where you want to " << com1 << "." << endl; gameOver = false; break; } case 2: //get if (com2 == "INVENTORY") { player.displayInventory(itemStorage); gameOver = false; break; } else { id = getIdGet(itemStorage, room, com2); if (id == -1) { cout << "I don't know what you want to " << com1 << endl; gameOver = false; break; } else { if (canCarry(itemStorage, id)) { player.addInventory(itemStorage, id); room.removeItem(roomStorage, id); gameOver = false; break; } else { cout << "And just how do you think you are going to carry that?" << endl; gameOver = false; break; } } } case 3: //look if (com2 == "ROOM") { id = room.getRoomId(); displayRoom(roomStorage, itemStorage, critterStorage, player, room, id); gameOver = false; break; } else { id = getIdGet(itemStorage, room, com2); if (id == -1) { id = getIdDrop(itemStorage, player, com2); if (id == -1) { cout << "I don't know what you want to " << com1 << " (at)" << endl; gameOver = false; break; } else { cout << getItemDescription(itemStorage, id) << endl; gameOver = false; break; } } else { if (getIdDrop(itemStorage, player, com2) != -1) { cout << "Please use a descriptive word with the noun, typed as one word. For example: ritualkey" << endl; } else { cout << getItemDescription(itemStorage, id) << endl; gameOver = false; break; } } } case 4: //drop id = getIdDrop(itemStorage, player, com2); if (id == -1) { cout << "I don't know what you want to " << com1 << endl; gameOver = false; break; } else { player.removeInventory(id); room.addItem(roomStorage, id); cout << "You dropped " << getItemName(itemStorage, id) << " from your inventory." << endl; gameOver = false; break; } case 5: //equip id = getIdDrop(itemStorage, player, com2); if (id == -1) { cout << "I don't know what you want to " << com1 << endl; gameOver = false; break; } else { if (id == 3 || id == 9 || id == 85) { player.setEquippedItem(id); cout << "You equipped " << getItemName(itemStorage, id) << endl; gameOver = false; break; } else { cout << "You can only equip weapons." << endl; gameOver = false; break; } } case 6: //eat id = getIdDrop(itemStorage, player, com2 ); if (id == -1) { cout << "I don't understand what you want to " << com1 << "." << endl; gameOver = false; break; } else if (isEdible(itemStorage, id)) { srand(time(NULL)); int randomTaunt = rand() % 6 + 1; switch (randomTaunt) { case 1: cout << "That really hit the spot!" << endl; break; case 2: cout << "Could have used some ketchup!" << endl; break; case 3: cout << "That was delicious. Do you have any beer?" << endl; break; case 4: cout << "Wow, that was surprisingly good!" << endl; break; case 5: cout << "Just like Momma used to make!" << endl; break; case 6: cout << "Please sir, may I have another?" << endl; break; default: cout << "My writer got bored and forgot to include a taunt here... " << endl; break; } cout << endl; cout << "You gained 10 points of health" << endl; int health = player.getHealth(); health = health + 10; if (health > 100) { health = 100; } player.setHealth(health); cout << "Your health is " << health << "/100" << endl; cout << "You gained 5 points of sanity" << endl; int sanity = player.getSanity(); sanity = sanity + 5; if (sanity > 25) { sanity = 25; } player.setSanity(sanity); cout << "Your sanity is " << sanity << "/25" << endl; player.removeInventory(id); gameOver = false; break; } else { srand(time(NULL)); int randomTaunt = rand() % 6 + 1; switch (randomTaunt) { case 1: cout << "I wouldn't eat that if I were you!" << endl; break; case 2: cout << "I don't think that's on your diet!" << endl; break; case 3: cout << "You're kidding, right?" << endl; ; break; case 4: cout << "I don't think that would taste very good!" << endl; break; case 5: cout << "Ha ha. Very funny!" << endl; break; case 6: cout << "I would never thought of trying to eat that!" << endl; break; default: cout << "My writer got bored and forgot to include a taunt here... " << endl; gameOver = false; break; } gameOver = false; break; } case 7: //use id = getIdDrop(itemStorage, player, com2); if (id == -1) { cout << "I don't understand what you want to " << com1 << "." << endl; gameOver = false; break; } else { if (id == 5) { if (player.hasItem(5)) //flashlight { cout << "You can see a lot better now!" << endl; room.displayDesc(); room.displayRoomItems(itemStorage); player.setHasLight(true); gameOver = false; break; } } else if (id == 209 || id == 210 || id == 214 || id == 217) //These are the 3 game keys + 210 is signet ring { int lockedRoom = checkLock(roomStorage, room); if (lockedRoom != -1) { bool match = keyMatch(lockedRoom, id); if (match) { unLock(roomStorage, lockedRoom); cout << "The door is unlocked!" << endl; gameOver = false; break; } else { cout << "That key(unlocking device) doesn't work. Please try another key(unlocking device)." << endl; gameOver = false; break; } } else { cout << "You don't need a key. All the doors are unlocked!" << endl; gameOver = false; break; } } else if (id == 213) { if (player.hasItem(205) || player.hasItem(211) || roomStorage[9].getVisited()) { if (player.hasItem(205)) { cout << "You use the note to decode the leather bound book from Mr. Brown's room. You learn..." << endl; } if (player.hasItem(211)) { cout << "You use the note to decode the strange book from the hidden room. You learn..." << endl; } if (roomStorage[9].getVisited()) { cout << "You use the note to decode the writing on the wall of that creepy bathroom. It loosely translates, THE ONE WHO SLEEPS COMETH" << endl; } } else { cout << "It looks like a cypher used for decoding. If only you had a book with strange writing in it!" << endl; } gameOver = false; break; } else if (id == 32) { cout << "You gained 25 health." << endl; int health = player.getHealth(); health = health + 25; if (health > 100) { health = 100; } player.setHealth(health); cout << "Your health is " << health << "/100" << endl; player.removeInventory(id); gameOver = false; break; } else { cout << "You can't use " << com2 << endl; gameOver = false; break; } } case 8: //talk, question, interrogate, interogate, grill if (room.getCritter() == -1 || (room.getCritter() != 100 && room.getCritter() != 101 && room.getCritter() != 102)) { cout << "I don't understand with whom you wish to " << com1 << endl; gameOver = false; break; } else { for (int i = 0; i < critterStorage.size(); i++) { if (critterStorage[i].getId() == room.getCritter()) { critterStorage[i].displayTalk(); } } gameOver = false; break; } case 9: if (room.getCritter() == -1 || (room.getCritter() != 100 && room.getCritter() != 101 && room.getCritter() != 102)) { cout << "I don't understand with whom you wish to " << com1 << endl; gameOver = false; break; } else { if (room.getCritter() == 100) { } else if (room.getCritter() == 101) { for (int i = 0; i < critterStorage.size(); i++) { if (critterStorage[i].getId() == 102) { if (critterStorage[i].getHealth() <= 0) { accuseCondition = true; } } } if (accuseCondition) { if (!player.hasItem(207) || !player.hasItem(216) || !player.hasItem(215)) { accuseCondition = false; } } } else if (room.getCritter() == 102) { if (room.getRoomId() == 33) { accuseCondition = true; } } for (int i = 0; i < critterStorage.size(); i++) { if (critterStorage[i].getId() == room.getCritter()) { if (!accuseCondition) { critterStorage[i].displayAccuse1(); } else { critterStorage[i].displayAccuse2(); } } } gameOver = false; break; } case 9999: //quit gameOver = quit(); break; default: gameOver = false; break; } return gameOver; }