bool callFunction(vector<Room> roomStorage,vector<Item> itemStorage, 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;
	
	
	while (ss >> com)
	{
		commands.push_back(com);
	}

	com1 = commands[0];
	//Basically, if input is not "QUIT", it should be a 2 word command
	if (filter != 9999)
	{
		com2 = commands[1];
	}
			
	switch (filter)
	{
	case -1: 
		gameOver = false;
		break;
	case 1:
		if (com2 == "NORTH")
		{
			id = room.getNorth();
			if (id == -1)
			{
				cout << "You can't " << com1 << " north. Try another command" << endl;
				gameOver = false;
				break;
			}
			else
			{
				displayRoom(roomStorage, room, id);
				gameOver = false;
				break;
			}
		}
		else if (com2 == "SOUTH")
		{
			id = room.getSouth();
			if (id == -1)
			{
				cout << "You can't " << com1 << " south. Try another command" << endl;
				gameOver = false;
				break;
			}
			else
			{
				displayRoom(roomStorage, room, id);
				gameOver = false;
				break;
			}
		}
		else if (com2 == "EAST")
		{
			id = room.getEast();
			if (id == -1)
			{
				cout << "You can't " << com1 << " east. Try another command" << endl;
				gameOver = false;
				break;
			}
			else
			{
				displayRoom(roomStorage, room, id);
				gameOver = false;
				break;
			}
		}
		else if (com2 == "WEST")
		{
			id = room.getWest();
			if (id == -1)
			{
				cout << "You can't " << com1 << " west. Try another command" << endl;
				gameOver = false;
				break;
			}
			else
			{
				displayRoom(roomStorage, room, id);
				gameOver = false;
				break;
			}
		}
		else
		{
			cout << "I don't understand where you want to " << com1 << "." << endl;
			gameOver = false;
			break;
		}
	case 2:
		if (com2 == "INVENTORY")
		{
			player.displayInventory(itemStorage);
			gameOver = false;
			break;
		}
		else
		{
			vector<string> items;
			room.getItems(itemStorage, items);

			for (int i = 0; i < items.size(); i++)
			{
				if (com2 == toUpperStr(items[i]))
				{
					itemPresent = true;
				}
			}

			if (itemPresent)
			{
				id = getItemId(itemStorage, com2);
				player.addInventory(itemStorage, id);
				room.removeItem(id);
				gameOver = false;
				break;
			}
			else
			{
				cout << "I don't know what you what to " << com1 << endl;
				gameOver = false;
				break;
			}	
			
		}
	case 3:
		if (com2 == "ROOM")
		{
			room.displayDesc();
			room.displayRoomItems(itemStorage);
			gameOver = false;
			break;
		}
		else
		{
			cout << "I don't know what you want to " << com1 << " at. Please try again." << endl;
			gameOver = false;
			break;
		}
	case 4:
		
		player.getItems(itemStorage, items);

		for (int i = 0; i < items.size(); i++)
		{
			if (com2 == toUpperStr(items[i]))
			{
				itemPresent = true;
			}
		}

		if (itemPresent)
		{
			id = getItemId(itemStorage, com2);
			player.removeInventory(id);
			room.addItem(id);
			cout << "You dropped" << getItemName(itemStorage, id) << " from your inventory." << endl;
			gameOver = false;
			break;
		}
		else
		{
			cout << "I don't know what you what to " << com1 << endl;
			gameOver = false;
			break;
		}
	case 9999:
		gameOver = quit();
		break;
	default:
		gameOver = false;
		break;
	}
	return gameOver;
}
示例#2
0
RoomHandler::RoomHandler() {
	// ----- ROOM INITIATIONS BEGIN -----

	Room* startRoom = new Room(string(
		"You are in a dark, twisted forest."
		));
	Room* cliff = new Room(string(
		"You are at the edge of a steep cliff, overlooking a warp-infested valley."
		));
	Room* cross = new Room(string("You are at a crossroads in the forest.\n")
		 + string("To the north, there is a warp-infested village.\n")
		 + string("To the west, there is a series of steep cliffs, overlooking the valley.\n")
		 + string("To the east you can see the mouth of a cave.\n")
		 + string("To the south there is a crashed ship. Possibly the one you came in.")
		);
	Room* cave = new Room(string("You are in a pitch-black cave. Something is lurking in the darkness..."));
	Room* abyss = new Room(string("The darkness creeps ever closer. Beware."));
	Room* crash = new Room(string("You are next to a huge cruiser wreckage.\n")
		+ string("Debris is is scattered everywhere."));
	Room* village = new Room(string("You are in a village plagued by warp storms."));
	Room* church = new Room(string("You are inside a huge cathedral.\n")
		+ string("A huge warp rift is humming at the end of the hall."));
	Room* warp = new Room(string(
		"You are in the middle of the warp itself, not even the emperor can save you."
		));

	Item* knife = new Item(string("A blade, simple but functional."),
		string("Knife"),
		5);
	Item* chainSword = new Item(string("A furiously deadly chain sword."),
		string("Chain-Sword"),
		20);
	Item* bolter = new Item(string("A standard issue heavy bolter."),
		string("Bolter"),
		15);
	Item* caffeine = new Item(string("A sealed jar of caffeine."),
		string("Caffeine"),
		1);

	cross->addItem(caffeine);
	abyss->addItem(bolter);
	cross->addItem(knife);
	crash->addItem(chainSword);

	startRoom->exits[EAST] = cliff;

	cliff->exits[WEST] = startRoom;
	cliff->exits[EAST] = cross;

	cross->exits[WEST] = cliff;
	cross->exits[SOUTH] = crash;
	cross->exits[EAST] = cave;
	cross->exits[NORTH] = village;

	crash->exits[NORTH] = cross;

	cave->exits[WEST] = cross;
	cave->exits[DOWN] = abyss;

	abyss->exits[UP] = cave;

	village->exits[SOUTH] = cross;
	village->exits[NORTH] = church;

	church->exits[SOUTH] = village;
	church->exits[NORTH] = warp;

	warp->exits[SOUTH] = church;

	this->gameMap.push_back(startRoom);
	this->gameMap.push_back(cliff);
	this->gameMap.push_back(cross);
	this->gameMap.push_back(crash);
	this->gameMap.push_back(cave);
	this->gameMap.push_back(abyss);
	this->gameMap.push_back(village);
	this->gameMap.push_back(church);
	this->gameMap.push_back(warp);

	// ----- ROOM INITIATIONS END -----

	// ----- ACTOR INITIATIONS BEGIN -----

	Cultist* cultist1 = new Cultist(string("Mal-Ek"),
		string("A cursed cultist, influenced by warp energies.")
		);

	Cultist* cultist2 = new Cultist(string("El-Rok"),
		string("A twisted cultist, consumed by chaos.")
		);

	Cultist* cultist3 = new Cultist(string("Malgor"),
		string("A psyker cultist, thirsting for blood.")
		);

	Snilsson* snilsson = new Snilsson(string("Sneel-Zon"),
		string("The chaos god himself.")
		);

	Daemon* demon = new Daemon(string("Daemon"),
		string("An abomination from the depths of the warp.")
		);

	cross->addChar(cultist1);
	cross->addChar(cultist2);
	cross->addChar(cultist3);
	warp->addChar(snilsson);
	abyss->addChar(demon);

	this->npcMap.push_back(cultist1);
	this->npcMap.push_back(cultist2);
	this->npcMap.push_back(cultist3);
	this->npcMap.push_back(snilsson);
	this->npcMap.push_back(demon);
	// ----- ACTOR INITIATIONS END -----
}
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;
}