예제 #1
0
        private bool PlaceCommandIsValid(string commandText, out int x, out int y, out Direction f)
        {
            try
            {
                string[] commandSplit = commandText.Split(' ');
                string[] parameters   = SplitIntoIndividualParameters(commandSplit);

                if (!_commandTextValidator.TryParseXParameter(parameters[0], out x) ||
                    !XCoordinateIsInRange(x) ||
                    !_commandTextValidator.TryParseYParameter(parameters[1], out y) ||
                    !YCoordinateIsInRange(y) ||
                    !TryParseDirection(parameters[2], out f))
                {
                    SetDefaults(out x, out y, out f);
                    return(false);
                }
            }
            catch (Exception)
            {
                SetDefaults(out x, out y, out f);
                return(false);
            }

            return(true);
        }
예제 #2
0
        public int RequestYCoordinate()
        {
            while (true)
            {
                PrintText("\nEnter the parameter Y for the PLACE command [0-5] => ");

                if (!_commandTextValidator.TryParseYParameter(GetKeyFromUser(), out int y) ||
                    !YCoordinateIsInRange(y))
                {
                    PrintText("\nInvalid value entered for Y. Please try again...\n");
                }
                else
                {
                    return(y);
                }
            }
        }