示例#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 RequestXCoordinate()
        {
            while (true)
            {
                PrintText("\nEnter the parameter X for the PLACE command [0-5] => ");

                if (!_commandTextValidator.TryParseXParameter(GetKeyFromUser(), out int x) ||
                    !XCoordinateIsInRange(x))
                {
                    PrintText("\nInvalid value entered for X. Please try again...\n");
                }
                else
                {
                    return(x);
                }
            }
        }