Exemplo n.º 1
0
        static void Main(string[] args)
        {
            try
            {
                BattleArenaCreateCommand createArenaCommand = WaitForArenaCreation();
                BattleArena arena = new BattleArena(createArenaCommand.MaximumPositionX, createArenaCommand.MaximumPositionY);

                while (true)
                {
                    try
                    {
                        IRobotCreateCommand createRobotCommand = WaitForRobotCreationCommand();
                        IRobot currentlyControlledRobot        = new Robot(createRobotCommand.PositionX, createRobotCommand.PositionY, createRobotCommand.Orientation);
                        arena.AddRobot(currentlyControlledRobot);

                        IList <ICommand> robotCommands = WaitForRobotCommands(currentlyControlledRobot);
                        foreach (ICommand command in robotCommands)
                        {
                            if (command is IRobotTurnCommand)
                            {
                                IRobotTurnCommand turnCommand = command as IRobotTurnCommand;
                                currentlyControlledRobot = currentlyControlledRobot.Turn(turnCommand);
                            }
                            else if (command is IRobotMoveCommand)
                            {
                                currentlyControlledRobot = currentlyControlledRobot.Move();
                            }
                        }

                        Console.WriteLine(currentlyControlledRobot.ToString());
                    }
                    catch (Exception ex) when(ex is CollisionException)
                    {
                        WriteError(ex);
                    }
                }
            }
            catch (Exception ex)
            {
                WriteError(ex);
            }
        }