public static bool CheckForHostage(Player player, Hostage hostage) { if (player.playerRoomNumber == hostage.hostageRoomNumber) { Console.WriteLine("You found the hostage!\nCongratulations, you win!!"); player.alive = false; } return player.alive; }
public static bool CheckForTerrorists(Player player, Terrorist[] terrorists) { for (int i=0; i<terrorists.Length; i++) { if (terrorists[i].terroristRoomNumber == player.playerRoomNumber) { if (terrorists[i].flashbanged == false) { Console.WriteLine("Killed by a terrorist.\nBetter luck next time!"); player.alive = false; } } } return player.alive; }
public static void CheckAdjacentRooms(Player player, Terrorist[] terrorists, Hostage hostage, Dictionary<int, int[]> roomMap) { int[] adjacentRooms = roomMap[player.playerRoomNumber]; for (int i=0; i<adjacentRooms.Length; i++) { for (int j=0; j<terrorists.Length; j++) { if (adjacentRooms[i] == terrorists[j].terroristRoomNumber && terrorists[j].alive == true) { Console.WriteLine("Something doesn't feel right in here..."); } } if (adjacentRooms[i] == hostage.hostageRoomNumber) { Console.WriteLine("I think I hear someone shouting in the next room."); } } }
public static void ChooseAction(Player player1, Terrorist[] terrorists, Hostage hostage, Dictionary<int, int[]> roomMap) { //While the player has not been killed by the terrorist, //the player is prompted for another action. while (player1.IsPlayerAlive() == true && hostage.IsHostageAlive() == true) { //Get adjacent rooms. int[] adjacentRooms = roomMap[player1.playerRoomNumber]; //Ask the player what they want to do. Console.WriteLine("Shoot (S), throw a grenade (G), throw a flashbang (F), move (M), or quit (Q): "); string input = Console.ReadLine(); string playerChoice = input.Trim().ToUpper(); //If player wants to shoot, they lose a bullet. if (playerChoice == "S") { //Player shoots. player1.ShootBullets(); bool isTerroristDead = false; //Check to see if any of the terrorists are in the room the player is in. for (int i=0; i<terrorists.Length; i++) { //If there is a terrorist in the room, the terrorist gets killed. if (terrorists[i].terroristRoomNumber == player1.playerRoomNumber) { terrorists[i].alive = false; Console.WriteLine("\nTerrorist terminated."); isTerroristDead = true; } } //Otherwise the player just loses a bullet. if (isTerroristDead == false) { Console.WriteLine("\nNo terrorists in here. Wasted bullet..."); } //Lets the player know how many bullets they have left. Console.WriteLine("You have {0} bullets.", player1.GetPlayerBullets()); } else if (playerChoice == "G") { //Player has to choose which room to throw a grenade into. Console.WriteLine("Which room do you want to throw the grenade into?"); int grenadeIntoRoomNum = int.Parse(Console.ReadLine()); //Player throws grenade. player1.ThrowGrenades(); //If a hostage is in the room the player throws a grenade into, game is over. if (hostage.hostageRoomNumber == grenadeIntoRoomNum) { Console.WriteLine("Oh no! You killed the hostage.\nGAME OVER"); hostage.alive = false; break; } //If a terrorist is in the room the player throws a grenade into, it dies. for (int i=0; i<terrorists.Length; i++) { if (terrorists[i].terroristRoomNumber == grenadeIntoRoomNum) { terrorists[i].alive = false; Console.WriteLine("\nTerrorist terminated."); } } //Lets the player know how many grenades they have left after throwing one. Console.WriteLine("You have {0} grenades.", player1.GetPlayerGrenades()); } else if (playerChoice == "F") { //Player has to choose which room to throw a flashbang into. Console.WriteLine("Which room do you want to throw the flashbang into?"); int flashbangIntoRoomNum = int.Parse(Console.ReadLine()); bool isTerroristFlashbanged = false; //Player throws flashbang. player1.ThrowFlashbangs(); for (int i=0; i<terrorists.Length; i++) { if (terrorists[i].terroristRoomNumber == flashbangIntoRoomNum) { terrorists[i].flashbanged = true; isTerroristFlashbanged = true; Console.WriteLine("You blinded a terrorist. Move now before they regain their sight."); } } if (isTerroristFlashbanged == false) { Console.WriteLine("No one in that room."); } Console.WriteLine("You have {0} flashbangs.", player1.GetPlayerFlashbangs()); } //If player wants to move, they are prompted for which room and are moved there. else if (playerChoice == "M") { bool roomExists = false; while (!roomExists) { Console.Write("Choose room to move to: "); int roomNumber = int.Parse(Console.ReadLine()); for (int i=0; i<3; i++) { if (roomNumber == adjacentRooms[i]) { roomExists = true; player1.alive = EnterRoom(player1, roomNumber, terrorists, hostage, roomMap); if (player1.alive == true) { CheckAdjacentRooms(player1, terrorists, hostage, roomMap); } } } } } else if (playerChoice == "Q") { player1.alive = false; } else { Console.WriteLine("That's not an option."); } } }
public static bool EnterRoom(Player player, int roomNumber, Terrorist[] terrorists, Hostage hostage, Dictionary<int, int[]> roomMap) { player.playerRoomNumber = roomNumber; Console.WriteLine("--------------------------------------------------------------\nYou have now entered Room {0}.", player.GetPlayerRoomNumber()); player.alive = CheckForTerrorists(player, terrorists); if (player.alive == false) { return player.alive; } else { player.alive = CheckForHostage(player, hostage); if (player.alive == false) { return player.alive; } else { AnnounceAdjacentRooms(player.playerRoomNumber, roomMap); Console.WriteLine("You have {0} bullets, {1} flashbangs, and {2} grenades.\n", player.GetPlayerBullets(), player.GetPlayerFlashbangs(), player.GetPlayerGrenades()); } } return player.alive; }
//This puts the player in one of the outer rooms. public static Player DropPlayerinRoom(Dictionary<int, int[]> roomMap) { Player player = new Player(); //Player starts from any room from 1 - 5 (outermost rooms) Random p = new Random(); player.playerRoomNumber = p.Next(1,6); Console.WriteLine("You have been dropped into Room {0}.", player.playerRoomNumber); AnnounceAdjacentRooms(player.playerRoomNumber, roomMap); return player; }