/JTacticalSim.Console/CommandProcessor/ConsoleCommandHandler.cs
C# | 859 lines | 611 code | 201 blank | 47 comment | 141 complexity | 713901f87959dd8636b95bc4e466913d MD5 | raw file
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Diagnostics;
- using System.Configuration;
- using System.Transactions;
- using System.IO;
- using JTacticalSim.API;
- using JTacticalSim.API.Component;
- using JTacticalSim.API.Game;
- using JTacticalSim.API.InfoObjects;
- using JTacticalSim.API.DTO;
- using JTacticalSim.API.Service;
- using JTacticalSim.Utility;
- using JTacticalSim.World;
-
- namespace JTacticalSim.Console
- {
-
- internal class ConsoleCommandHandler : BaseConsoleIOHandler, IInputCommandHandler
- {
- public ConsoleCommandHandler(IGame theGame)
- : base(theGame)
- {}
-
- #region Interface
-
- // Game
-
- public void Exit()
- {
- System.Environment.Exit(1);
- }
-
- public void Play()
- {
- // TODO: Check for loaded game
- if (_theGame.SavedGame == null)
- {
- SetInputError("No game is loaded. Please load a game from the list.");
- return;
- }
-
- _theGame.Start();
- DisplayMainBoardScreen();
- }
-
- public void LoadGame()
- {
- if (_commandArgs.Args.Length < 1)
- {
- SetInputError("Command requires a game title.");
- return;
- }
-
- var r = _theGame.LoadGame(_commandArgs.Args[0]);
-
- if (r.Status == ResultStatus.SUCCESS) System.Console.WriteLine(r.Message);
- if (r.Status == ResultStatus.EXCEPTION) _theGame.Renderer.HandleErrorUI(r.Message, r.ex);
- // TODO: Handle other results
-
- }
-
- public void NewGame()
- {
- if (_commandArgs.Args.Length < 2)
- {
- SetInputError("Command requires a game title and a scenario.");
- return;
- }
-
- // Handle the scenario input
- var scenarioTitle = _commandArgs.Args[0];
- var scResult = IsValidScenarioTitleEntered(scenarioTitle);
-
- if (scResult.Status == ResultStatus.FAILURE)
- {
- SetInputError(scResult.Message);
- return;
- }
-
- // Handle the new game input
- var gTitle = _commandArgs.Args[1];
- var gResult = IsValidGameTitleEntered(gTitle);
-
- if (gResult.Status == ResultStatus.FAILURE)
- {
- SetInputError(gResult.Message);
- return;
- }
-
- var scenario = _theGame.JTSServices.GenericComponentService.GetByName<IScenario, IScenarioDTO>(scenarioTitle);
-
- var newGame = _theGame.SavedGame.ShallowCopy();
-
- newGame.Name = gTitle;
- newGame.GameFileDirectory = gTitle;
- newGame.LastPlayed = true;
- newGame.Scenario = scenario;
-
- using (var txn = new TransactionScope())
- {
- // Save the saved game record.
- var sResult = _theGame.JTSServices.GameService.SaveSavedGame(newGame);
-
- if (sResult.Status == ResultStatus.SUCCESS) System.Console.WriteLine(sResult.Message);
- if (sResult.Status == ResultStatus.EXCEPTION) _theGame.Renderer.HandleErrorUI(sResult.Message, sResult.ex);
-
- // Save the saved game data.
- var cResult = _theGame.SaveAs(scenario, newGame);
-
- if (cResult.Status == ResultStatus.SUCCESS) System.Console.WriteLine(cResult.Message);
- if (cResult.Status == ResultStatus.EXCEPTION) _theGame.Renderer.HandleErrorUI(cResult.Message, cResult.ex);
-
- // Load the newly saved game
- _theGame.LoadGame(newGame.GameFileDirectory);
- Play();
-
- txn.Complete();
- }
-
- }
-
- public void SaveGame()
- {
- var cResult = _theGame.Save();
-
- if (cResult.Status == ResultStatus.SUCCESS) System.Console.WriteLine(cResult.Message);
- if (cResult.Status == ResultStatus.EXCEPTION) _theGame.Renderer.HandleErrorUI(cResult.Message, cResult.ex);
- }
-
- public void SaveGameAs()
- {
- if (_commandArgs.Args.Length < 1)
- {
- SetInputError("Command requires a game name.");
- return;
- }
-
- var title = _commandArgs.Args[0];
- var result = IsValidGameTitleEntered(title);
-
- if (result.Status == ResultStatus.FAILURE)
- {
- SetInputError(result.Message);
- return;
- }
-
- var newGame = _theGame.SavedGame.ShallowCopy();
-
- newGame.Name = title;
- newGame.GameFileDirectory = title;
- newGame.LastPlayed = true;
-
- using (var txn = new TransactionScope())
- {
- // Save the saved game record.
- var sResult = _theGame.JTSServices.GameService.SaveSavedGame(newGame);
-
- if (sResult.Status == ResultStatus.SUCCESS) System.Console.WriteLine(sResult.Message);
- if (sResult.Status == ResultStatus.EXCEPTION) _theGame.Renderer.HandleErrorUI(sResult.Message, sResult.ex);
-
- // Save the saved game data.
- var cResult = _theGame.SaveAs(_theGame.SavedGame, newGame);
-
- if (cResult.Status == ResultStatus.SUCCESS) System.Console.WriteLine(cResult.Message);
- if (cResult.Status == ResultStatus.EXCEPTION) _theGame.Renderer.HandleErrorUI(cResult.Message, cResult.ex);
-
- // Load the newly saved game
- _theGame.LoadGame(newGame.GameFileDirectory);
- Play();
-
- txn.Complete();
- }
- }
-
- public void DeleteGame()
- {
- if (_commandArgs.Args.Length < 1)
- {
- SetInputError("Command requires a game name.");
- return;
- }
-
- var title = _commandArgs.Args[0];
- ISavedGame delGame = null;
-
- try
- {
- delGame = _theGame.JTSServices.GameService.GetSavedGameByName(title);
- if (_theGame.SavedGame.Equals(delGame)) _theGame.LoadGame(null);
- }
- catch (ComponentNotFoundException cnfex)
- {
- SetInputError(cnfex.Message);
- return;
- }
-
- // Verify the delete
- System.Console.Write("Delete Game {0}? ".F(delGame.Name));
- if (!CommandLineUtil.ConsoleUtils.GetYesNoInputAsBool()) return;
-
- using (var txn = new TransactionScope())
- {
- // Delete the saved game record.
- var sResult = _theGame.JTSServices.GameService.RemoveSavedGame(delGame);
-
- if (sResult.Status == ResultStatus.SUCCESS) System.Console.WriteLine(sResult.Message);
- if (sResult.Status == ResultStatus.EXCEPTION) _theGame.Renderer.HandleErrorUI(sResult.Message, sResult.ex);
-
- // Remove the saved game directory and files
- var dResult = _theGame.JTSServices.DataService.RemoveSavedGameData(delGame);
-
- if (dResult.Status == ResultStatus.SUCCESS) System.Console.WriteLine(dResult.Message);
- if (dResult.Status == ResultStatus.EXCEPTION) _theGame.Renderer.HandleErrorUI(dResult.Message, dResult.ex);
-
- txn.Complete();
- }
- }
-
- public void DisplayLegend()
- {
- _theGame.Renderer.DisplayLegend();
- }
-
- // Screens
-
- public void DisplayMainBoardScreen()
- {
- RenderBoard();
- }
-
- public void DisplayReinforcementsScreen()
- {
- GetReinforcements();
- }
-
- public void DisplayTitleScreen()
- {
- // Enter Title Screen state ...
- _theGame.StateSystem.ChangeState(StateType.TITLE_MENU);
- }
-
-
- public void DisplayCommandList()
- {
- foreach (KeyValuePair<CommandType, List<string>> kvp in CommandInterface.GetInputCommands(_theGame.StateSystem.CurrentStateType))
- {
- System.Console.WriteLine("{0} : ", kvp.Key.ToString());
- kvp.Value.ForEach(c => System.Console.WriteLine("\t{0}", c));
- System.Console.WriteLine();
- }
- }
-
- public void EndTurn()
- {
- _theGame.CurrentTurn.End();
- }
-
- public void DisplayUnit()
- {
- if (_commandArgs.Args.Length < 1 && (_theGame.GameBoard.SelectedUnits == null || _theGame.GameBoard.SelectedUnits.Count == 0))
- {
- SetInputError("Command requires a unit name.");
- return;
- }
-
- IUnit unit = (_theGame.GameBoard.SelectedUnits == null || _theGame.GameBoard.SelectedUnits.Count == 0)
- ? GetValidUnit(_commandArgs.Args[0])
- : _theGame.GameBoard.SelectedUnits.First();
-
- INode node = _theGame.JTSServices.NodeService.GetNodeAt(unit.Location);
- unit.DisplayInfo();
- node.DisplayInfo();
- }
-
- public void DisplayPlayer()
- {
- _theGame.CurrentTurn.Player.DisplayInfo();
- }
-
- public void DisplayAssignedUnits()
- {
- if (_commandArgs.Args.Length < 1)
- {
- SetInputError("Command requires a unit name.");
- return;
- }
-
- IUnit unit = GetValidUnit(_commandArgs.Args[0]);
- List<IUnit> assignedUnits = _theGame.JTSServices.UnitService.GetUnitsByUnitAssignment(unit.ID);
-
- if (assignedUnits != null)
- assignedUnits.ForEach(m => m.DisplayInfo());
-
- DrawLine();
- }
-
- public void DisplayUnits()
- {
- var atCurrentLocation = _commandArgs.Switches.Contains("--currentnode");
-
- INode n = null;
-
- if (atCurrentLocation)
- {
- n = GetSelectedNode();
- if (n == null) return;
- }
-
- var tmp = (atCurrentLocation)
- ? _theGame.JTSServices.UnitService.GetAllUnitsAt(n.Location)
- : _theGame.JTSServices.UnitService.GetAllUnits(_theGame.CurrentTurn.Player.Country);
-
- foreach (var o in tmp)
- {
- o.DisplayName();
- System.Console.WriteLine();
- }
-
- DrawLine();
- }
-
- public void SetCurrentNode()
- {
- if (_commandArgs.Args.Length < 2)
- {
- SetInputError("Command requires a Row and column value.");
- return;
- }
-
- if (!IsValidLocationEntered())
- return;
-
- var buttonClicked = (_commandArgs.Args.Length == 3) ? _commandArgs.Args[2] : null;
- var l = _theGame.JTSServices.TileService.CreateCoordinate(Convert.ToInt32(_commandArgs.Args[0]), Convert.ToInt32(_commandArgs.Args[1]), 0);
-
- // Fire events
- _theGame.JTSServices.NodeService.GetNodeAt(l).On_ComponentClicked(this, new ComponentClickedEventArgs(GetValidMouseButtonClick(buttonClicked)));
- }
-
- public void SetSelectedUnit()
- {
- _theGame.GameBoard.ClearSelectedItems();
-
- if (_commandArgs.Args.Length < 1)
- {
- SetInputError("Command requires unit name.");
- return;
- }
-
- var selectAttachedUnits = _commandArgs.Switches.Contains("--attachedunits");
- var unit = GetValidUnit(_commandArgs.Args[0]);
- var buttonClicked = (_commandArgs.Args.Length == 2) ? _commandArgs.Args[1] : null;
-
- // Fire unit clicked event
- // This will handle selecting the correct unit - the next cycled unit (displayed after cycle) for LL/currently displayed unit for others
- unit.On_ComponentClicked(this, new ComponentClickedEventArgs(GetValidMouseButtonClick(buttonClicked)));
-
- if (selectAttachedUnits)
- {
- var attached = unit.GetAllAttachedUnits().Where(u => u.LocationEquals(unit.Location));
- _theGame.GameBoard.SelectedUnits.AddRange(attached);
- }
- }
-
- public void SetSelectedUnits()
- {
- _theGame.GameBoard.ClearSelectedItems();
-
- if (_commandArgs.Args.Length < 2)
- {
- SetInputError("Command requires a Row and column value.");
- return;
- }
-
- if (!IsValidLocationEntered())
- return;
-
-
- var l = _theGame.JTSServices.TileService.CreateCoordinate(Convert.ToInt32(_commandArgs.Args[0]), Convert.ToInt32(_commandArgs.Args[1]), 0);
-
- // Only the units for the current player
- var countries = new List<ICountry>{_theGame.CurrentTurn.Player.Country};
-
- var units = _theGame.JTSServices.UnitService.GetUnitsAt(l, countries);
-
- if (units == null || units.Count == 0)
- {
- SetInputError("{0} has no units at the selected location.".F(_theGame.CurrentTurn.Player.Country.Name));
- return;
- }
-
- // var buttonClicked = (_commandArgs.Args.Length == 3) ? _commandArgs.Args[2] : null;
-
- // Fire unit clicked event
- // This will handle selecting the correct unit - the next cycled unit (displayed after cycle) for LL/currently displayed unit for others
- units.ForEach(u => u.Select());
- }
-
- public void DisplayCurrentNode()
- {
- var n = GetSelectedNode();
-
- if (n == null) return;
-
- n.DisplayInfo();
-
- var factions = _theGame.JTSServices.GenericComponentService.GetAll<IFaction, IFactionDTO>();
- var units = _theGame.JTSServices.UnitService.GetUnitsAt(_theGame.GameBoard.SelectedNode.Location, factions);
-
- if (units != null && units.Any())
- units.DisplayInfo();
-
- DrawLine();
- }
-
- public void MoveUnitsToSelectedNode()
- {
- var units = _theGame.GameBoard.SelectedUnits;
-
- if (units == null || units.Count == 0)
- {
- SetInputError("You must first select units to move.");
- return;
- }
-
- var results = new List<bool>();
-
- units.ForEach(u => results.Add(MoveUnitToSelectedNode(u)));
-
- if (results.Any(r => r))
- {
- var node = _theGame.GameBoard.SelectedNode;
- _theGame.GameBoard.ClearSelectedItems();
- // Reset the selected node
- _theGame.GameBoard.SelectedNode = node;
- }
- }
-
- public void MoveUnitToSelectedNode()
- {
- if (_theGame.GameBoard.SelectedUnits.Count > 1)
- {
- SetInputError("You have multiple units selected. Use command 'MoveUnits'.");
- return;
- }
-
- var unit = (_theGame.GameBoard.SelectedUnits.Any()) ? _theGame.GameBoard.SelectedUnits.Single() : null;
-
- if (unit == null)
- {
- SetInputError("You must first select a unit to move.");
- return;
- }
-
- var success = MoveUnitToSelectedNode(unit);
- if (success)
- {
- var node = _theGame.GameBoard.SelectedNode;
- _theGame.GameBoard.ClearSelectedItems();
- // Reset the selected node
- _theGame.GameBoard.SelectedNode = node;
- }
-
- }
-
- public void CycleUnits()
- {
- var n = GetSelectedNode();
- if (n == null) return;
-
- n.DefaultTile().GetCountryComponentStack(_theGame.CurrentTurn.Player.Country).CycleUnits();
- }
-
- public void AddUnit()
- {
- // Can only add units to a friendly node
- if (_theGame.GameBoard.SelectedNode == null || !_theGame.GameBoard.SelectedNode.IsFriendly())
- {
- SetInputError("You must first select a friendly space to add the unit to.");
- return;
- }
-
- var unitType = GetValidUnitType(true);
- var unitName = GetValidUnitName();
- var unitClass = GetValidUnitClass(unitType);
- var unitGroupType = GetValidUnitGroupType();
- var subNodeLocation = new SubNodeLocation(5);
- var ui = new UnitInfo(unitType, unitClass, unitGroupType);
-
- IUnit unit = _theGame.JTSServices.UnitService.CreateUnit(unitName,
- _theGame.GameBoard.SelectedNode.Location,
- _theGame.GameBoard.SelectedNode.Country,
- ui,
- subNodeLocation).SuccessfulObjects.First();
-
- unit.UnitInfo = ui;
- unit.SetNextID();
- unit.Description = unit.Name;
-
- INode node = _theGame.JTSServices.NodeService.GetNodeAt(_theGame.GameBoard.SelectedNode.Location);
-
- unit.StackOrder = node.VisibleUnitCount() + 1;
-
- _theGame.JTSServices.UnitService.SaveUnits(new List<IUnit> { unit });
- node.DefaultTile().AddComponentsToStacks(new List<IUnit> {unit});
-
- node.ResetUnitStackOrder();
- }
-
- public void RemoveUnit()
- {
- if (_commandArgs.Args.Length < 1)
- {
- SetInputError("Command requires a unit name.");
- return;
- }
-
- IUnit unit = GetValidUnit(_commandArgs.Args[0]);
-
- //From node - reset the unit stack order for all units at node AFTER move
- INode node = _theGame.JTSServices.NodeService.GetNodeAt(unit.Location);
-
- // Remove the unit object
- unit.RemoveFromGame();
-
- node.ResetUnitStackOrder();
- }
-
- public void AttachUnit()
- {
- var unitToAttach = (_theGame.GameBoard.SelectedUnits.Any()) ? _theGame.GameBoard.SelectedUnits.Single() : null;
-
- if (unitToAttach == null)
- {
- SetInputError("You must first select a unit to attach.");
- return;
- }
-
- if (_commandArgs.Args.Length < 1)
- {
- SetInputError("Command requires unit name.");
- return;
- }
-
- var attachToUnit = GetValidUnit(_commandArgs.Args[0]);
-
- var result = unitToAttach.AttachToUnit(attachToUnit);
-
- if (result.Status != ResultStatus.SUCCESS)
- SetInputError(result.Message);
- }
-
- public void DetachUnit()
- {
- var unitToDetach = (_theGame.GameBoard.SelectedUnits.Any()) ? _theGame.GameBoard.SelectedUnits.Single() : null;
-
- if (unitToDetach == null)
- {
- SetInputError("You must first select a unit to detach.");
- return;
- }
-
- var result = unitToDetach.DetachFromUnit();
-
- if (result.Status != ResultStatus.SUCCESS)
- SetInputError(result.Message);
- }
-
- public void LoadUnit()
- {
- var unitToLoad = (_theGame.GameBoard.SelectedUnits.Any()) ? _theGame.GameBoard.SelectedUnits.Single() : null;
-
- if (_commandArgs.Args.Length < 1)
- {
- SetInputError("Command requires a unit transport unit name.");
- return;
-
- }
-
- if (unitToLoad == null)
- {
- SetInputError("You must first select a unit to load.");
- return;
- }
-
- var transport = GetValidUnit(_commandArgs.Args[0]);
-
- var fromNode = unitToLoad.GetNode();
- var toNode = transport.GetNode();
-
- var result = transport.LoadUnits(new List<IUnit>{unitToLoad});
-
- if (result.Status != ResultStatus.SUCCESS)
- {
- SetInputError(result.Message);
- }
- else
- {
- fromNode.ResetUnitStackOrder();
- toNode.ResetUnitStackOrder();
-
- _theGame.GameBoard.ClearSelectedItems();
- }
- }
-
- public void DeployUnit()
- {
- var transportUnit = (_theGame.GameBoard.SelectedUnits.Any()) ? _theGame.GameBoard.SelectedUnits.Single() : null;
- var selectedNode = _theGame.GameBoard.SelectedNode ?? ((transportUnit == null) ? null : transportUnit.GetNode());
-
-
- if (transportUnit == null)
- {
- SetInputError("You must first select a transport unit.");
- return;
- }
-
- if (selectedNode == null)
- {
- SetInputError("You must first select a node to deploy to.");
- return;
- }
-
- if (_commandArgs.Args.Length < 1)
- {
- SetInputError("Command requires a unit name to deploy.");
- return;
- }
-
- var unitToDeploy = GetValidUnit(_commandArgs.Args[0]);
-
- var result = transportUnit.DeployUnits(new List<IUnit> {unitToDeploy}, selectedNode);
-
- if (result.Status != ResultStatus.SUCCESS)
- {
- SetInputError(result.Message);
- }
- else
- {
- _theGame.GameBoard.ClearSelectedItems();
- selectedNode.ResetUnitStackOrder();
- }
- }
-
- // Battle
-
- public void BarrageNode()
- {
- var units = (_theGame.GameBoard.SelectedUnits.Any()) ? _theGame.GameBoard.SelectedUnits : null;
-
- if (units == null)
- {
- SetInputError("You must first select attacking units.");
- return;
- }
-
- if (_theGame.GameBoard.SelectedNode == null)
- {
- SetInputError("You must first select an attack location.");
- return;
- }
-
- // Enter battle state ...
- _theGame.StateSystem.ChangeState(StateType.BATTLE);
-
- var sourceNode = units.First().GetNode();
- var targetNode = _theGame.GameBoard.SelectedNode;
-
- var r = _theGame.BattleHandler.BarrageUnitsAtLocation(_theGame.GameBoard.SelectedNode);
-
- // Handle issues with creating and doing battle
- if (r.Status == ResultStatus.FAILURE)
- {
- // Exit battle state ....
- _theGame.StateSystem.ChangeState(StateType.GAME_IN_PLAY);
- SetInputError(r.Message);
- return;
- }
-
- sourceNode.ResetUnitStackOrder();
- targetNode.ResetUnitStackOrder();
-
- _theGame.GameBoard.ClearSelectedItems();
- // Reset the selected node
- _theGame.GameBoard.SelectedNode = targetNode;
-
- // Exit battle state ...
- _theGame.StateSystem.ChangeState(StateType.GAME_IN_PLAY);
-
- }
-
- public void DoBattleAtLocation()
- {
-
- if (_theGame.GameBoard.SelectedNode == null)
- {
- SetInputError("You must first select a battle location.");
- return;
- }
-
- // Enter battle state ...
- _theGame.StateSystem.ChangeState(StateType.BATTLE);
-
- var targetNode = _theGame.GameBoard.SelectedNode;
-
- var r = _theGame.BattleHandler.DoBattleAtLocation(_theGame.GameBoard.SelectedNode);
-
- // Handle issues with creating and doing battle
- if (r.Status == ResultStatus.FAILURE)
- {
- // Exit battle state ...
- _theGame.StateSystem.ChangeState(StateType.GAME_IN_PLAY);
- SetInputError(r.Message);
- return;
- }
-
- targetNode.ResetUnitStackOrder();
-
- _theGame.GameBoard.ClearSelectedItems();
- // Reset the selected node
- _theGame.GameBoard.SelectedNode = targetNode;
-
- // Exit battle state ...
- _theGame.StateSystem.ChangeState(StateType.GAME_IN_PLAY);
- }
-
- // Other
-
- public void ScenarioEditor()
- {
- var curDrive = Directory.GetDirectoryRoot(Directory.GetCurrentDirectory());
- var scenarioExecutablePath = ConfigurationManager.AppSettings["gameeditor_executablepath"].ToString();
- Process.Start("{0}{1}{2}".F(curDrive, scenarioExecutablePath,"\\JTacticalSimEditor.exe"));
- }
-
- // Reinforcements
-
- public void GetReinforcements()
- {
- // Enter reinforcement state ...
- _theGame.StateSystem.ChangeState(StateType.REINFORCE);
-
- }
-
- public void AddReinforcementUnit()
- {
- var unitType = GetValidUnitType(false);
- var unitName = GetValidUnitName();
- var unitClass = GetValidUnitClass(unitType);
- var unitGroupType = GetValidUnitGroupType();
-
- // Validate the reinforcement points
-
- var subNodeLocation = new SubNodeLocation(5);
- var ui = new UnitInfo(unitType, unitClass, unitGroupType);
-
- IUnit unit = _theGame.JTSServices.UnitService.CreateUnit(unitName,
- null,
- _theGame.CurrentTurn.Player.Country,
- ui,
- subNodeLocation).SuccessfulObjects.First();
-
-
- // Remove points and update player
-
- unit.UnitInfo = ui;
- unit.SetNextID();
- unit.Description = unit.Name;
-
- _theGame.JTSServices.UnitService.SaveUnits(new List<IUnit> { unit });
-
- var r = _theGame.CurrentTurn.Player.AddReinforcementUnit(unit);
-
- if (r.Status == ResultStatus.EXCEPTION)
- {
- SetInputError(r.ex.Message);
- }
-
- if (r.Status == ResultStatus.FAILURE)
- {
- SetInputError(r.Message);
- }
- }
-
- public void PlaceReinforcementUnit()
- {
- // Can only add units to a friendly node
- if (_theGame.GameBoard.SelectedNode == null || !_theGame.GameBoard.SelectedNode.IsFriendly())
- {
- SetInputError("You must first select a friendly space to add the unit to.");
- return;
- }
-
- if (_commandArgs.Args.Length < 1)
- {
- SetInputError("Command requires unit name.");
- return;
- }
-
- var unit = GetValidReinforcementUnit(_commandArgs.Args[0]);
- INode node = _theGame.JTSServices.NodeService.GetNodeAt(_theGame.GameBoard.SelectedNode.Location);
- var placeResult = unit.PlaceAtLocation(node);
-
- // Handle issues
- if (placeResult.Status == ResultStatus.FAILURE)
- {
- SetInputError(placeResult.Message);
- return;
- }
-
- if (placeResult.Status == ResultStatus.EXCEPTION)
- {
- SetInputError(placeResult.ex.Message);
- return;
- }
-
-
- // Remove from player and handle result
- var removeResult = _theGame.CurrentTurn.Player.RemoveReinforcementUnit(unit);
-
- if (removeResult.Status == ResultStatus.EXCEPTION)
- {
- SetInputError(removeResult.ex.Message);
- }
-
- if (removeResult.Status == ResultStatus.FAILURE)
- {
- SetInputError(removeResult.Message);
- }
-
- }
-
- #region base overrides
-
- public override void GetCommandInput(ICommandInterface ci)
- {
- System.Console.ResetColor();
- System.Console.WriteLine("");
- System.Console.BackgroundColor = ConsoleColor.DarkYellow;
- System.Console.ForegroundColor = ConsoleColor.Black;
- System.Console.Write("Command: ");
- System.Console.ResetColor();
- System.Console.Write(" ");
- var command = System.Console.ReadLine();
-
- if (string.IsNullOrEmpty(command)) return;
-
- ParseCommandArgs(command);
- RunCommand(ci);
- }
-
- #endregion
-
- #endregion
-
- }
- }