public static bool ChooseAction(Player player1, Terrorist[] terrorists, Hostage hostage, Dictionary<int, int[]> roomMap, StreamWriter writer, StreamReader reader) { bool done = false; //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. writer.WriteLine("Shoot (S), throw a grenade (G), throw a flashbang (F), move (M), or quit (Q): "); string input = reader.ReadLine(); string playerChoice = input.Trim().ToUpper(); //If player wants to shoot, they lose a bullet. if (playerChoice == "S") { Shoot(player1, terrorists, writer); } else if (playerChoice == "G") { hostage.alive = ThrowGrenade(player1, terrorists, hostage, roomMap, writer, reader); } else if (playerChoice == "F") { ThrowFlashbang(player1, terrorists, roomMap, writer, reader); } //If player wants to move, they are prompted for which room and are moved there. else if (playerChoice == "M") { player1.alive = Move(player1, terrorists, hostage, roomMap, writer, reader); } else if (playerChoice == "Q") { player1.alive = false; } else { writer.WriteLine("That's not an option."); } } writer.WriteLine("GAME OVER"); done = true; return done; }
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 creates a set of terrorists and defines which rooms they are in. public static Terrorist[] DropTerroristsInRooms() { Terrorist terrorist1 = new Terrorist(); Terrorist terrorist2 = new Terrorist(); Terrorist terrorist3 = new Terrorist(); Terrorist terrorist4 = new Terrorist(); Terrorist terrorist5 = new Terrorist(); Random terroristRoomNumGen = new Random(); terrorist1.terroristRoomNumber = terroristRoomNumGen.Next(6,9); terrorist2.terroristRoomNumber = terroristRoomNumGen.Next(9,12); terrorist3.terroristRoomNumber = terroristRoomNumGen.Next(12,15); terrorist4.terroristRoomNumber = terroristRoomNumGen.Next(15,18); terrorist5.terroristRoomNumber = terroristRoomNumGen.Next(18,21); Terrorist[] terrorists = {terrorist1, terrorist2, terrorist3, terrorist4, terrorist5}; return terrorists; }
public static Hostage DropHostageInRoom(Terrorist[] terrorists) { Hostage hostage = new Hostage(); Random hostageRoomOptionsGen = new Random(); hostage.hostageRoomNumber = terrorists[hostageRoomOptionsGen.Next(1,5)].terroristRoomNumber; return hostage; }
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; }
public static void ThrowFlashbang(Player player, Terrorist[] terrorists, Dictionary<int, int[]> roomMap, StreamWriter writer, StreamReader reader) { bool roomExists = false; while (!roomExists) { //Player has to choose which room to throw a flashbang into. writer.WriteLine("Choose which room you want to throw the flashbang into: "); int flashbangIntoRoomNum = int.Parse(reader.ReadLine()); roomExists = IsAdjacentRoom(player, flashbangIntoRoomNum, roomMap); bool isTerroristFlashbanged = false; if (roomExists == true) { //Player throws flashbang. player.ThrowFlashbangs(); for (int i=0; i<terrorists.Length; i++) { if (terrorists[i].terroristRoomNumber == flashbangIntoRoomNum) { terrorists[i].flashbanged = true; isTerroristFlashbanged = true; writer.WriteLine("You blinded a terrorist. Move now before they regain their sight."); } } if (isTerroristFlashbanged == false) { writer.WriteLine("No one in that room."); } } else { writer.WriteLine("That is not an adjacent room."); } } writer.WriteLine("You have {0} flashbangs.", player.GetPlayerFlashbangs()); }
public static void Shoot(Player player, Terrorist[] terrorists, StreamWriter writer) { //Player shoots. player.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 == player.playerRoomNumber) { terrorists[i].alive = false; writer.WriteLine("\nTerrorist terminated."); isTerroristDead = true; } } //Otherwise the player just loses a bullet. if (isTerroristDead == false) { writer.WriteLine("\nNo terrorists in here. Wasted bullet..."); } //Lets the player know how many bullets they have left. writer.WriteLine("You have {0} bullets.", player.GetPlayerBullets()); }
public static bool Move(Player player, Terrorist[] terrorists, Hostage hostage, Dictionary<int, int[]> roomMap, StreamWriter writer, StreamReader reader) { bool roomExists = false; while (!roomExists) { writer.WriteLine("Choose room to move to: "); int roomNumber = int.Parse(reader.ReadLine()); roomExists = IsAdjacentRoom(player, roomNumber, roomMap); if (roomExists == true) { player.alive = EnterRoom(player, roomNumber, terrorists, hostage, roomMap, writer); if (player.alive == true) { CheckAdjacentRooms(player, terrorists, hostage, roomMap, writer); } } } return player.alive; }