/// <summary> /// Gets a command from the user. /// </summary> /// <param name="moveNumber"> /// The current move number. /// </param> /// <param name="positions"> /// The number of code positions. /// </param> /// <param name="colors"> /// The maximum number of code colors. /// </param> /// <returns> /// The entered command and guess (if applicable). /// </returns> public static (Command command, Code?guess) GetCommand(int moveNumber, int positions, int colors) { while (true) { View.PromptGuess(moveNumber); var input = Console.ReadLine(); if (input is null) { Environment.Exit(0); } switch (input.ToUpperInvariant()) { case "BOARD": return(Command.ShowBoard, null); case "QUIT": return(Command.Quit, null); default: if (input.Length != positions) { View.NotifyBadNumberOfPositions(); } else if (input.FindFirstIndex(c => !TranslateColor(c).HasValue) is int invalidPosition) { View.NotifyInvalidColor(input[invalidPosition]); } else { return(Command.MakeGuess, new Code(input.Select(c => TranslateColor(c) !.Value))); } break; } } }