public override bool HandleInput() { var originalColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Black; var exitInputLoop = false; do { var input = GetPlayerInput(); if (input == Inputs.cancel) { var dialog = new ConfirmDialog("Are you sure you want to exit the game?"); dialog.Process(); var result = dialog.DialogResult; Draw(); if (result == ConfirmDialogResult.Yes) { Debug("Exit Game = [Y]"); ScreenResult = new ScreenTransitionResult { FromScreen = ScreenType.MainMenu, ToScreen = ScreenType.None }; return(false); } return(true); } } while (exitInputLoop == false); Console.ForegroundColor = originalColor; return(false); }
/// <summary> /// The return is to exit the Game /// </summary> /// <returns></returns> public override bool HandleInput() { var originalColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Black; var inputs = Inputs.Instance; var lastInput = GetPlayerInput(); Console.ForegroundColor = originalColor; var exitGameLoop = false; Action action = null; //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // Player Actions. //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- if (lastInput == inputs.forfeit) { var dialog = new ForfeitDialog(_gameState.Game); dialog.Process(); var result = dialog.DialogResult; if (result == ForfeitDialogResult.Yes) { ScreenResult = new ScreenTransitionResult { FromScreen = ScreenType.InGame, ToScreen = ScreenType.MainMenu, Result = null }; Storage.Heroes.RemoveAll(x => x.Name == _gameState.Game.Hero.Name); Storage.Save(); exitGameLoop = true; } } // Input.forfeit, else if (lastInput == inputs.quit) { var dialog = new ConfirmDialog("Are you sure you want to quit the game?"); dialog.Process(); var result = dialog.DialogResult; if (result == ConfirmDialogResult.Yes) { ScreenResult = new ScreenTransitionResult { FromScreen = ScreenType.InGame, ToScreen = ScreenType.MainMenu, Result = null }; Storage.Update(_gameState); Storage.Save(); exitGameLoop = true; } } // Input.quit, else if (lastInput == inputs.closeDoor) { // See how many adjacent open doors there are. var doors = new List <VectorBase>(); foreach (var direction in Direction.All) { var pos = _gameState.Game.Hero.Position + direction; if (_gameState.Game.CurrentStage[pos].Type.ClosesTo != null) { doors.Add(pos); } } if (doors.Count == 0) { _gameState.Game.Log.Error("You are not next to an open door."); } else if (doors.Count == 1) { _gameState.Game.Hero.SetNextAction(new CloseDoorAction(doors[0])); } else { var closeDoorDialog = new CloseDoorDialog(_gameState.Game); closeDoorDialog.Process(); } } // Input.closeDoor, else if (lastInput == inputs.drop) { ShowItemDialog(ItemDialogUsage.Drop); } // Input.drop, else if (lastInput == inputs.use) { ShowItemDialog(ItemDialogUsage.Use); } // Input.use, else if (lastInput == inputs.pickUp) { var items = _gameState.Game.CurrentStage.itemsAt(_gameState.Game.Hero.Position); if (items.Count > 1) { // Show item dialog if there are multiple things to pick up. ShowItemDialog(ItemDialogUsage.PickUp); } else { // Otherwise attempt to pick up any available item. _gameState.Game.Hero.SetNextAction(new PickUpAction(items.Count - 1)); } } // Input.pickUp, else if (lastInput == inputs.swap) { if (_gameState.Game.Hero.Inventory.lastUnequipped == -1) { _gameState.Game.Log.Error("You aren't holding an unequipped item to swap."); } else { action = new EquipAction(ItemLocations.Inventory, _gameState.Game.Hero.Inventory.lastUnequipped); } } // Input.swap, else if (lastInput == inputs.toss) { ShowItemDialog(ItemDialogUsage.Toss); } // Input.toss, else if (lastInput == inputs.selectCommand) { var commands = _gameState.Game.Hero.HeroClass.Commands.Where(cmd => cmd.CanUse(_gameState.Game)); if (!commands.Any()) { _gameState.Game.Log.Error("You don't have any commands you can perform."); } else { Command commandToProcess = null; if (commands.Count() > 1) { var dialog = new SelectCommandDialog(_gameState.Game); dialog.Process(); commandToProcess = dialog.DialogResult; } else { commandToProcess = commands.First(); } if (commandToProcess is TargetCommand) { var targetCommand = commandToProcess as TargetCommand; // If we still have a visible target, use it. if (_gameState.Game.Target != null && _gameState.Game.Target.IsAlive && _gameState.Game.CurrentStage[_gameState.Game.Target.Position].Visible) { _gameState.Game.Hero.SetNextAction(targetCommand.GetTargetAction(_gameState.Game, _gameState.Game.Target.Position)); } else { // No current target, so ask for one. var targetDialog = new TargetDialog(targetCommand.GetRange(_gameState.Game), (target) => _gameState.Game.Hero.SetNextAction(targetCommand.GetTargetAction(_gameState.Game, target)), _gameState.Game); targetDialog.Process(); } } else if (commandToProcess is DirectionCommand) { var directionCommand = commandToProcess as DirectionCommand; var directionDialog = new DirectionDialog(directionCommand, _gameState.Game); directionDialog.Process(); } else { throw new NotImplementedException(); } } } // Input.selectCommand, else if (lastInput == inputs.stats) { ShowHeroStatisticsDialog(); } // Input.HeroStatistics, else if (lastInput.Key == ConsoleKey.Z) { ShowStorageDialog(); } // Storage else if (lastInput.Key == ConsoleKey.Oem3) { ShowConsoleDialog(); } // Storage //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // Running Options //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- else if (lastInput == inputs.runNW) { _gameState.Game.Hero.Run(Direction.NorthWest); } // Input.runNW, else if (lastInput == inputs.runN) { _gameState.Game.Hero.Run(Direction.North); } // Input.runN, else if (lastInput == inputs.runNE) { _gameState.Game.Hero.Run(Direction.NorthEast); } // Input.runNE, else if (lastInput == inputs.runW) { _gameState.Game.Hero.Run(Direction.West); } // Input.runW, else if (lastInput == inputs.runE) { _gameState.Game.Hero.Run(Direction.East); } // Input.runE, SemiColon else if (lastInput == inputs.runSW) { _gameState.Game.Hero.Run(Direction.SouthWest); } // Input.runSW, else if (lastInput == inputs.runS) { _gameState.Game.Hero.Run(Direction.South); } // Input.runS, else if (lastInput == inputs.runSE) { _gameState.Game.Hero.Run(Direction.SouthEast); } // Input.runSE, Slash (FWD) //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // Firing Options //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- else if (lastInput == inputs.fireNW) { FireTowards(Direction.NorthWest); } // Input.fireNW, else if (lastInput == inputs.fireN) { FireTowards(Direction.North); } // Input.fireN, else if (lastInput == inputs.fireNE) { FireTowards(Direction.NorthEast); } // Input.fireNE, else if (lastInput == inputs.fireW) { FireTowards(Direction.West); } // Input.fireW, else if (lastInput == inputs.fireE) { FireTowards(Direction.East); } // Input.fireE, else if (lastInput == inputs.fireSW) { FireTowards(Direction.SouthWest); } // Input.fireSW, else if (lastInput == inputs.fireS) { FireTowards(Direction.South); } // Input.fireS, else if (lastInput == inputs.fireSE) { FireTowards(Direction.SouthEast); } // Input.fireSE, //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // directions. //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- else if (lastInput == inputs.nw) { action = new WalkAction(Direction.NorthWest); } // Input.nw, else if (lastInput == inputs.n) { action = new WalkAction(Direction.North); } // Input.n, else if (lastInput == inputs.ne) { action = new WalkAction(Direction.NorthEast); } // Input.ne, else if (lastInput == inputs.w) { action = new WalkAction(Direction.West); } // Input.w, else if (lastInput == inputs.rest) { action = new RestAction(); } // Input.l, else if (lastInput == inputs.e) { action = new WalkAction(Direction.East); } // Input.e, else if (lastInput == inputs.sw) { action = new WalkAction(Direction.SouthWest); } // Input.sw, else if (lastInput == inputs.s) { action = new WalkAction(Direction.South); } // Input.s, else if (lastInput == inputs.se) { action = new WalkAction(Direction.SouthEast); } // Input.se, //Check if we have a non-zero value for horizontal or vertical if (action != null) { //UnityEngine.Debugger.Log("Adding action for Hero"); GameState.Instance.Game.Hero.SetNextAction(action); } return(exitGameLoop); }
public override bool HandleInput() { var originalColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Black; var exitInputLoop = false; do { var input = GetPlayerInput(); if (input == Inputs.cancel) { var dialog = new ConfirmDialog("Are you sure you want to exit the game?"); dialog.Process(); var result = dialog.DialogResult; Draw(); if (result == ConfirmDialogResult.Yes) { Debug("Exit Game = [Y]"); ScreenResult = new ScreenTransitionResult { FromScreen = ScreenType.MainMenu, ToScreen = ScreenType.None }; return(false); } return(true); } if (input.Key == ConsoleKey.L) { if (Layout.SelectedHeroIndex == -1) { Debug("You have not selected a hero yet...."); return(true); } var selectedHero = Storage.Heroes[Layout.SelectedHeroIndex]; ScreenResult = new ScreenTransitionResult { FromScreen = ScreenType.NewPlayer, ToScreen = ScreenType.InGame, Result = selectedHero.Name }; Debug("Loading Hero...."); return(false); } if (input.Key == ConsoleKey.N) { Debug("New Hero...."); ScreenResult = new ScreenTransitionResult { FromScreen = ScreenType.MainMenu, ToScreen = ScreenType.NewPlayer }; return(false); } if (input.Key == ConsoleKey.D) { Debug("Deleting Hero...."); if (Layout.SelectedHeroIndex == -1) { Debug("You have not selected a hero yet...."); } else { var dialog = new ConfirmDialog("Are you sure you want to delete this hero?"); dialog.Process(); var result = dialog.DialogResult; Draw(); if (result == ConfirmDialogResult.Yes) { Debug("Deleting Hero = [Y]"); Storage.Heroes.RemoveAt(Layout.SelectedHeroIndex); Storage.Save(); Layout.Storage = Storage; Layout.Initialise(); var buffer = new BufferContainer(0, 0, (short)ScreenHeight, (short)ScreenWidth); Layout.Draw(buffer); } else { Debug("Deleting Hero = [N]"); } } return(true); } if (input == Inputs.n) { Layout.DecrementSelectedHero(); return(true); } if (input == Inputs.s) { Layout.IncrementSelectedHero(); return(true); } } while (exitInputLoop == false); Console.ForegroundColor = originalColor; return(false); }