public CommandCycle( IConsoleIO consoleIO, GameCmdHandler gameCmdHandler, TurnCmdHandler turnCmdHandler, BoardPrinter boardPrinter, CommandParser commandParser) { Console = consoleIO; GameCmdHandler = gameCmdHandler; TurnCmdHandler = turnCmdHandler; BoardPrinter = boardPrinter; CommandParser = commandParser; }
int IConsoleApplication.Run(string[] args) { PrintWelcome(); while (true) { BoardPrinter.PrintCurrentGameState(); Console.Write("> "); string cmdStr = Console.ReadLine(); try { var cmd = CommandParser.Parse(cmdStr); if (cmd is TurnCommand tc) { MakeTurn(tc.Turn); } else if (cmd is GameCommand gc) { GameCmdHandler.Execute(gc); } else if (cmd is Exit) { return(0); } else { throw new NotImplementedException($"Not implemented command: {cmd}"); } } catch (UserErrorException ue) { PrintError(ue); PrintHelp(); } } }