Ejemplo n.º 1
0
 public CommandCycle(
     IConsoleIO consoleIO,
     GameCmdHandler gameCmdHandler,
     TurnCmdHandler turnCmdHandler,
     BoardPrinter boardPrinter,
     CommandParser commandParser)
 {
     Console        = consoleIO;
     GameCmdHandler = gameCmdHandler;
     TurnCmdHandler = turnCmdHandler;
     BoardPrinter   = boardPrinter;
     CommandParser  = commandParser;
 }
Ejemplo n.º 2
0
        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 (UserError ue)
                {
                    PrintError(ue);
                    PrintHelp();
                }
            }
        }