コード例 #1
0
ファイル: Balloons.cs プロジェクト: TIAMAT-Team/Baloons-PopUp
        static void Main(string[] args)
        {
            var             balloonsField = new BalloonsField(5, 10);
            RankList        rankList      = new RankList();
            IPrinter        printer       = new ConsolePrinter();
            ICommandParser  commandParser = new CommandParser();
            ICommandInfo    commandInfo;
            ICommandFactory commandFactory = new CommandFactory(printer, rankList, balloonsField);

            printer.PrintField(balloonsField);

            string userInput;

            while (true)
            {
                printer.PrintMessage("Enter a row and column: ");
                userInput = ReadUserInput();

                if (userInput == "EXIT")
                {
                    printer.PrintMessage("Good Bye! ");
                    break;
                }

                try
                {
                    commandInfo = commandParser.Parse(userInput);
                    IBalloonPopsCommand command = commandFactory.CreateCommand(commandInfo);

                    command.Execute(commandInfo.Arguments.ToArray());
                }
                catch (ArgumentException)
                {
                    printer.PrintMessage("Wrong input ! Try Again ! ");
                    continue;
                }
                catch (IndexOutOfRangeException)
                {
                    printer.PrintMessage("Wrong input ! Try Again ! ");
                    continue;
                }
            }
        }