private void UnlockDoor() { bool trying = true; KeyPadLock kpl = _rooms.CurrentRoom.FindItem(KeyPadLock.KeyPadName) as KeyPadLock; string msg = ""; while (trying) { // Print Title // Print Rooms // Print KeyPad Console.Clear(); Log log = new Log(); PrintInstructions calcPrintInstructions = null; // Print Title Program.TitleController.DrawHeader(); // Print Rooms _rooms.PrintInstructions("").Lines.ForEach(line => { line.Instructions.ForEach(instruction => { log.Add(instruction.Text, instruction.Foreground, instruction.Background); }); log.Print(); }); Calculator calc = _game.CurrentPlayer.Inventory.Find(item => { return(item is Calculator); }) as Calculator; if (calc != null) { if (calc.On) { calcPrintInstructions = calc.Display; } } PrintInstructions unlockInstructions = new PrintInstructions().AddInstructions(kpl.Display); if (calcPrintInstructions != null) { unlockInstructions.RightJoin(calcPrintInstructions); } unlockInstructions.NewLine(msg, ConsoleColor.DarkRed); unlockInstructions.Lines.ForEach(line => { line.Instructions.ForEach(instruction => { log.Add(instruction.Text, instruction.Foreground, instruction.Background); }); log.Print(); }); log.NewLine(); log.Add("Enter the "); log.Add("code", ConsoleColor.DarkRed); log.Add(" to unlock the door (type 'quit' to stop trying)"); log.Print(); string userInput = Console.ReadLine(); if (userInput.ToLower().Trim() == "quit") { SetPrintInstructions(new PrintInstructions("You couldn't unlock the door", ConsoleColor.DarkRed)); return; } if (userInput == "use calculator") { SetCalculator(true); continue; } try { int numVal = Int32.Parse(userInput.Substring(0, 5)); bool unlocked = kpl.Unlock(numVal); if (unlocked) { Classes.Lock lk = _rooms.Lock; calcPrintInstructions = new PrintInstructions(); calcPrintInstructions.NewLine("You Unlocked the ") .Add($"{lk.KeyPadDoorDirection}", _rooms.GetDoorColor(lk.KeyPadRoomPosition, lk.KeyPadDoorDirection)) .Add(" DOOR!!!"); calcPrintInstructions.NewLine("NICE JOB!!!", ConsoleColor.Green); lk.Unlock(); return; } else { msg = $" '{userInput}' does not unlock the door. Good try though."; } } catch (FormatException e) { msg = $" '{userInput}' does not unlock the door"; } } }
public Rooms() { _setup(); Lock = new Classes.Lock(this); }