Ejemplo n.º 1
0
        public IEnumerable <BoardAction> GetActions(bool validate = true)
        {
            if (validate)
            {
                ActionsValidationManager.ValidateActions(Actions);
            }

            return(Actions);
        }
Ejemplo n.º 2
0
        public void Execute()
        {
            var actions = ActionsManager.GetActions();

            if (actions.Count() == 0)
            {
                MessageBox.Show("No actions to execute",
                                "Information",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                return;
            }

            Logger.LogExecutionStart();

            foreach (var action in actions)
            {
                if (!action.IsExecutable)
                {
                    Logger.LogExecution(action);
                    continue;
                }

                if (action.CommandType == CommandTypes.PLACE)
                {
                    if (!RobotStatus.GetIsPlaced())
                    {
                        RobotStatus.SetIsPlaced(true);
                    }
                }
                else if (action.Position == null)
                {
                    action.Position = ActionsTranslator.TranslatePosition(action.CommandType);

                    if (action.CommandType == CommandTypes.MOVE)
                    {
                        ActionsValidationManager.ValidateAction(action);

                        if (!action.IsExecutable)
                        {
                            Logger.LogExecution(action);
                            continue;
                        }
                    }
                }

                Logger.LogExecution(action);
                RobotStatus.Update(position: action.Position);
                UIRobotManager.Update();
            }

            ActionsManager.ClearActions();
            Logger.LogExecutionEnd();
        }
Ejemplo n.º 3
0
        public void Place(string XBlock, string YBlock, string F)
        {
            var validationMsgs = ActionsValidationManager.ValidatePlaceInput(XBlock, YBlock, F);

            if (validationMsgs != null)
            {
                MessageBox.Show(string.Join(",\n", validationMsgs.ToArray()),
                                "Unexpected input",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);
                return;
            }

            int.TryParse(XBlock, out int xBlock);
            int.TryParse(YBlock, out int yBlock);
            char.TryParse(F, out char f);

            RegisterAction(CommandTypes.PLACE,
                           XBlock: xBlock,
                           YBlock: yBlock,
                           F: f);
        }