//Apply Rules() //checks for conditions being met. //adds items/doors/rooms and checks. public static void ApplyRules() { //if the 4 items are in your office. //end game if (Level.Room[0, 0].GetItem("Black Pen") != null && Level.Room[0, 0].GetItem("Manilla Envelope") != null && Level.Room[0, 0].GetItem("Stapler") != null) { EndGame("Congratulations, you have aquired all of items and can complete your work in time!"); } //if the player has the red pen if (Player.GetInventoryItem("red pen") != null) { // add an exit to Georges office. Level.Room[0, 1].AddExit(Direction.East); //add east direction to 0,1 to enter georges office Level.Room[0, 2].AddExit(Direction.West); // add west direction to return to original location [0,1] Level.Room[0, 2].RoomDescription = "George spots the RED PEN in your hand, and asks if he can have it in exchange for a STAPLER."; //if player puts pen in x 0, y 2 if (Player.PosX == 0 && Player.PosY == 2) { Player.DropItem("red pen"); Level.Room[0, 2].RoomDescription = "Having given George the RED PEN he is now scribbling desperately on spreadsheets./nHe doesnt even look up when you enter the room."; } } //if player has the basement key or paper clip if (Player.GetInventoryItem("Basement Key") != null || Player.GetInventoryItem("Paper Clip") != null) { //add an exit to the south so player can now enter the basement Level.Room[4, 1].AddExit(Direction.South); //change the description to show something has changed/access the castle Level.Room[5, 1].RoomDescription = "You have entered the basement. The smell of damp permiates the air."; } if (Player.Moves > 25) { EndGame("You have run out of moves. Morning breaks and your Boss has arrived. \nHaving not completed your work he mercilessly fires you."); } }
public void CheckText() { userInput = Console.ReadLine().ToUpper().Split(' '); Console.WriteLine(); if (userInput[0].Equals("GO") || userInput[0].Equals("G")) { if (userInput.Length > 1) { if (userInput[1].Equals("NORTH") || userInput[1].Equals("WEST") || userInput[1].Equals("EAST") || userInput[1].Equals("SOUTH")) { Move(userInput[1]); } else { Console.WriteLine("You can't go there..."); Console.WriteLine(); } } else { Console.WriteLine("Deciding where to go makes things much easier."); Console.WriteLine(); } } else if (userInput[0].Equals("USE") || userInput[0].Equals("U")) { if (userInput.Length > 1) { if (player.playerInventory.ContainsKey(userInput[1])) { if (userInput.Length == 2) { player.Use(userInput[1]); } else if (userInput.Length == 3) { Console.WriteLine("Please be a little more precise... USE <ITEM> ON <ITEM>.."); Console.WriteLine(); } else if (player.currentLocation.roomInventory.ContainsKey(userInput[3]) && userInput[2].Equals("ON")) { player.UseOnRoomItem(userInput[1], userInput[3]); } else if (player.playerInventory.ContainsKey(userInput[3]) && userInput[2].Equals("ON")) { player.UseOnInvItem(userInput[1], userInput[3]); } else { Console.WriteLine("Do you speak the english language? USE <ITEM> ON <ITEM>!"); Console.WriteLine(); } } if (player.currentLocation.roomInventory.ContainsKey(userInput[1])) { player.UseSomethingInRoom(userInput[1]); } } else { Console.WriteLine("Using nothing seems kinda useless"); Console.WriteLine(); } } else if (userInput[0].Equals("TAKE") || userInput[0].Equals("T")) { if (userInput.Length > 1) { if (player.currentLocation.roomInventory.ContainsKey(userInput[1])) { player.PickItem(userInput[1]); } else { Console.WriteLine("What are you on about? " + userInput[1] + " doesn't even exist!"); Console.WriteLine(); } } else { Console.WriteLine("What do you want to pick up stupid???"); Console.WriteLine(); } } else if (userInput[0].Equals("DROP") || userInput[0].Equals("D")) { if (userInput.Length > 1) { if (player.playerInventory.ContainsKey(userInput[1])) { player.DropItem(userInput[1]); } else { Console.WriteLine("Are you high? " + userInput[1] + " doesn't exist in your inventory!?"); Console.WriteLine(); } } else { Console.WriteLine("Good on you " + player.playerName + " for not littering."); Console.WriteLine(); } } else if (userInput[0].Equals("INSPECT") || userInput[0].Equals("I")) { if (userInput.Length > 1) { if (player.currentLocation.roomInventory.ContainsKey(userInput[1])) { player.currentLocation.InspectItem(userInput[1]); } else if (player.playerInventory.ContainsKey(userInput[1])) { player.InspectItem(userInput[1]); } } else { Console.WriteLine("Inspect what? " + player.playerName + ", INSPECT WHAT?!"); Console.WriteLine(); } } else if (userInput[0].Equals("LOOK") || userInput[0].Equals("L")) { player.currentLocation.Look(); } else if (userInput[0].Equals("INVENTORY") || userInput[0].Equals("INV")) { player.ShowInventory(); } else if (userInput[0].Equals("EXIT") || userInput[0].Equals("QUIT")) { Environment.Exit(0); } else { Console.WriteLine("Stop speaking in words that I do not understand!"); Console.WriteLine(); } }
//ProccessPlayerCommand() //Take line of text from player //break into two sections: //Command: Which command is it? Is it valid? Do something e.g Move //Arguments e.g. North public static void ProcessPlayerCommand(string line) { //text from player, store into variables. string command = TextUtilities.ExtractCommand(line.Trim()).Trim().ToLower(); //trims string to avoid command confusion with upper case/spaces string arguements = TextUtilities.ExtractArguments(line.Trim()).Trim().ToLower(); //what command is it? switch (command) { case "exit": Program.quitGame = true; return; case "quit": Program.quitGame = true; return; case "q": Program.quitGame = true; return; case "help": ShowHelp(); break; //break out of switch before checking for other cases case "move": Player.Move(arguements); break; case "go": Player.Move(arguements); break; case "walk": Player.Move(arguements); break; case "look": Player.GetCurrentRoom().DescribeRoom(); break; case "examine": Player.GetCurrentRoom().DescribeRoom(); break; case "pickup": Player.PickUpItem(arguements); break; case "take": Player.PickUpItem(arguements); break; case "grab": Player.PickUpItem(arguements); break; case "drop": Player.DropItem(arguements); break; case "use": Player.DropItem(arguements); break; case "inventory": Player.DisplayInventory(); break; case "whereami": Player.GetCurrentRoom().ShowTitle(); break; case "location": Player.GetCurrentRoom().ShowTitle(); break; case "coffee": Level.AmendKitchen(); Player.GetCurrentRoom().DescribeRoom(); break; default: TextBuffer.Add("I don't understand what you mean, type 'help' for some help"); break; } //apply game rules, has win condition been met? Has the game state changed? GameController.ApplyRules(); //take text buffer and display info TextBuffer.DisplayText(); }