private static void ProcessCommands() { CommandsHelper.ResetWells(); while (true) { var command = GetIntValue("command", false); switch (command) { case 1: var(x, y) = GetValidXAndYCoordinates(); CommandsHelper.Place(x, y); break; case 2: var direction = GetDirection(); CommandsHelper.Move(direction); break; case 3: Console.WriteLine(CommandsHelper.Detect()); break; case 4: CommandsHelper.Drop(); break; case 5: var report = CommandsHelper.Report(); Console.WriteLine(report + "\n"); break; case 6: return; default: Console.WriteLine("The option you have entered is invalid. Please try again \n"); break; } } }
public static (int, int) GetValidXAndYCoordinates() { int xLocation; int yLocation; while (true) { var x = GetIntValue("x", true); var y = GetIntValue("y", true); var isValid = CommandsHelper.IsValidCoordinate(x, y); if (isValid) { xLocation = x; yLocation = y; break; } Console.WriteLine("Entered x or y coordinate is out of range. Please try again \n"); } return(xLocation, yLocation); }