예제 #1
0
        public void LaunchRoverMenu()
        {
            _userIo.Clear();
            while (true)
            {
                try {
                    _userIo.WriteLine("Where would you like to place the new rover?\n" +
                                      "Syntax: 'X Y Direction' ('E' to exit)");
                    var input = GetUserInput().ToUpper().Split(' ');

                    if (input[0] == "E")
                    {
                        break;
                    }

                    if (input.Length != MAX_ROVER_INPUT_LENGTH || !IsValidRoverInput(input))
                    {
                        throw new InvalidInputException("Invalid input, please try again.");
                    }

                    if (!IsValidRoverCoords(input))
                    {
                        throw new RoverInTheWayException("Cannot place a rover here, space occupied.");
                    }

                    if (!CheckGridEdge(new[] { int.Parse(input[0]), int.Parse(input[1]) }))
                    {
                        throw new EdgeReachedException("Cannot place a rover outside of grid.");
                    }

                    LaunchRover(input);
                    break;
                }
                catch (InvalidInputException invalidInputException) {
                    ClearAndWriteLine(invalidInputException.Message);
                }
                catch (RoverInTheWayException roverInTheWayException) {
                    ClearAndWriteLine(roverInTheWayException.Message);
                }
                catch (EdgeReachedException edgeReachedException) {
                    ClearAndWriteLine(edgeReachedException.Message);
                }
            }

            ClearAndWriteLine("Rover launched successfully.");
        }