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; }
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 ThrowGrenade(Player player, Terrorist[] terrorists, Hostage hostage, Dictionary<int, int[]> roomMap, StreamWriter writer, StreamReader reader) { bool roomExists = false; while (!roomExists) { //Player has to choose which room to throw a grenade into. writer.WriteLine("Choose which room you want to throw the grenade into: "); int grenadeIntoRoomNum = int.Parse(reader.ReadLine()); roomExists = IsAdjacentRoom(player, grenadeIntoRoomNum, roomMap); if (roomExists == true) { //Player throws grenade. player.ThrowGrenades(); //If a hostage is in the room the player throws a grenade into, game is over. if (hostage.hostageRoomNumber == grenadeIntoRoomNum) { writer.WriteLine("Oh no! You killed the hostage."); 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; writer.WriteLine("\nTerrorist terminated."); } } } else { writer.WriteLine("That is not an adjacent room."); } } //Lets the player know how many grenades they have left after throwing one. writer.WriteLine("You have {0} grenades.", player.GetPlayerGrenades()); return hostage.alive; }