public void CreateExit(string command) { var validCommand = command.IsSpaceDelimitedNumbers(); if (!validCommand) { throw new FormatException("Exit Input Is Not Valid."); } var exit = command.ToIntArray(' '); var exitCoordinate = _coordinateService.Create(exit[0], exit[1]); var exception = ValidPosition(exitCoordinate, "exit"); if (exception == null) { if (_board.ExitPoint != null) { throw new Exception("You have already entered a valid exit point!"); } _board.ExitPoint = exitCoordinate; } else { throw exception; } }
public Mine CreateMine(int[] mineCoordinates) { var x = mineCoordinates[0]; var y = mineCoordinates[1]; var mine = new Mine { Position = _coordinateService.Create(x, y), Status = MineStatus.Active }; return(mine); }
public void CreateTurtle(string command) { var validCommand = command.IsSpaceDelimitedNumbersAndChar(); if (!validCommand) { throw new FormatException("Exit Input Is Not Valid."); } var array = command.ToStringArray(' '); var turtleStartingCoordinate = _coordinateService.Create(Convert.ToInt32(array[0]), Convert.ToInt32(array[1])); var exception = _boardService.ValidPosition(turtleStartingCoordinate, "turtle"); if (exception != null) { throw exception; } var turtleOrientation = EnumHelper <Orientation> .GetValueFromName(array[2]); var turtle = Create(turtleStartingCoordinate, turtleOrientation); var board = _boardService.GetBoard(); if (board == null) { throw new NullReferenceException("The board has not been initialized!"); } if (turtle.Board != null) { throw new Exception("The turtle already has a board!"); } turtle.Board = board; }