Example #1
0
        private BoardAction Translate(CommandTypes type,
                                      int?XBlock = null,
                                      int?YBlock = null,
                                      char?F     = null)
        {
            //INFO: all actions created as executable - validation further down the chain
            BoardAction ret = new BoardAction()
            {
                CommandType = type, IsExecutable = true
            };

            switch (type)
            {
            case CommandTypes.PLACE:
                ret.Position = CommandsLogic.GetPlacePosition(XBlock.Value, YBlock.Value, F.Value);
                break;

            case CommandTypes.MOVE:
            case CommandTypes.LEFT:
            case CommandTypes.RIGHT:
            case CommandTypes.REPORT:
                ret.Position = null;
                break;
            }

            return(ret);
        }
        public void ActionsManager_RegisterAction_NoValidation()
        {
            var sut = new ActionsManagerFixture()
                      .WithValidActionsValidationManager()
                      .WithValidLogger()
                      .Build();

            var input = new BoardAction()
            {
                CommandType =
                    CommandTypes.LEFT,
                IsExecutable = true,
                Position     = new BoardPosition()
                {
                    Direction = InternalDirections.NORTH1,
                    X         = 0,
                    XBlock    = 0,
                    Y         = 1,
                    YBlock    = 1
                }
            };

            sut.RegisterAction(input);

            int expectedCount = 1;

            Assert.AreEqual(sut.GetActions(validate: false).Count(), expectedCount);
        }
Example #3
0
        public List <Cell> Perform(BoardAction action)
        {
            List <Cell> changes = new List <Cell>();

            switch (action)
            {
            case BoardAction.None: return(changes);

            case BoardAction.Backtracking: Backtracking(changes); break;

            case BoardAction.NakedSingle: NakedSingle(changes); break;

            case BoardAction.HiddenSingle: HiddenSingle(changes); break;

            case BoardAction.NakedPair: NakedPair(changes); break;

            case BoardAction.HiddenPair: HiddenPair(changes); break;

            case BoardAction.PointingPair: PointingPair(changes); break;

            default:
                throw new ArgumentOutOfRangeException("action");
            }

            foreach (var cell in changes)
            {
                if (cell.Possibilities == 1 && action != BoardAction.Backtracking)
                {
                    cell.Value = Cell.ToValue(cell.Candidates);
                }
            }
            return(changes);
        }
Example #4
0
        public void OnPlayerEndDragBoard(Cell cell)
        {
            changeState(GameState.MY_TURN);
            _processAction(_nextAction);

            _nextAction = new BoardAction();             // reset next action
        }
Example #5
0
 public void FireBoardEvent(BoardAction OnSomething)
 {
     if (OnSomething != null)
     {
         OnSomething();
     }
 }
Example #6
0
        public void LogRegisterAction(BoardAction action)
        {
            string curr      = LogTextBox.Text;
            string lineBreak = !string.IsNullOrEmpty(curr) ? "\r\n" : string.Empty;
            string register  = $"-> Registered action: {action.ToStringRegister()}";

            LogTextBox.AppendText($"{lineBreak}{register}");
        }
Example #7
0
        public void LogExecution(BoardAction action)
        {
            string curr      = LogTextBox.Text;
            string lineBreak = !string.IsNullOrEmpty(curr) ? "\r\n" : string.Empty;
            string exec      = $"-> Run action: {action.ToString()}";

            LogTextBox.AppendText($"{lineBreak}{exec}");
        }
Example #8
0
        private void RegisterAction(CommandTypes type,
                                    int?XBlock = null,
                                    int?YBlock = null,
                                    char?F     = null)
        {
            BoardAction action = ActionsTranslator.TranslateAction(type, XBlock, YBlock, F);

            ActionsManager.RegisterAction(action);
        }
        public void ValidateAction(BoardAction action)
        {
            if (action.CommandType == CommandTypes.MOVE)
            {
                var xBoundaries = BoardStatus.GetXBoundaries();
                var yBoundaries = BoardStatus.GetYBoundaries();

                action.IsExecutable = !(action.Position.X <xBoundaries.Min || action.Position.X> xBoundaries.Max) &&
                                      !(action.Position.Y <yBoundaries.Min || action.Position.Y> yBoundaries.Max);
            }
        }
Example #10
0
        // Function Referenced by the UI
        public void Undo()
        {
            if (m_actionStack.Count == 0)
            {
                return;
            }

            BoardAction lastAction = m_actionStack.Pop();

            m_cellList[lastAction.cellListPosition].CopyFrom(lastAction.currentCellStatus);
            m_cellList[lastAction.cellListPosition].UpdateUI();
        }
Example #11
0
    private void OnBoardAction(BoardAction action)
    {
        if (action.Type == BoardActionType.Null)
        {
            return;
        }
        var      popup   = Instantiate(_alertPrefab, _alertSpawn);
        TMP_Text tmpText = popup.GetComponentInChildren <TMP_Text>();

        switch (action.Type)
        {
        case BoardActionType.Single:
            tmpText.text = "Single";
            break;

        case BoardActionType.Double:
            tmpText.text = "Double";
            break;

        case BoardActionType.Triple:
            tmpText.text = "Triple";
            break;

        case BoardActionType.Tetris:
            tmpText.text = "Tetris";
            break;

        case BoardActionType.T_Spin:
            tmpText.text = "T-Spin";
            break;

        case BoardActionType.T_Spin_Double:
            tmpText.text = "T-Spin Double";
            break;

        case BoardActionType.T_Spin_Triple:
            tmpText.text = "T-Spin Triple";
            break;

        case BoardActionType.T_Spin_Mini:
            tmpText.text = "T-Spin Mini";
            break;

        case BoardActionType.T_Spin_Mini_Single:
            tmpText.text = "T-Spin Mini Single";
            break;

        case BoardActionType.T_Spin_Mini_Double:
            tmpText.text = "T-Spin Mini Double";
            break;
        }
    }
Example #12
0
 private void ExceptionControl(BoardAction action, string boardName)
 {
     try
     {
         action(boardName);
     }
     catch (Exception ex)
     {
         this._logger.Error(boardName + ":" + ex.Message);
         this._logger.Error(boardName + ex.StackTrace);
         this._boardManager.ChangeBoardState(boardName, BoardState.CONFLICT);
     }
 }
Example #13
0
        private void _processAction(BoardAction action)
        {
            _gameEngine.Board.ClearMovingUI();
            switch (action.Name)
            {
            case BoardAction.END_LEVEL:
                action.CellFrom.Piece.Stats.visible = false;
                action.CellFrom.Piece.zIndex        = ZIndex.FIGHT_UI;
                MoveAndScalePieceCallback(action.CellFrom.Piece, action.CellTo.Pos, 0.4f, new Vector3(0, -0.25f, 0),
                                          LevelComplete);
                break;

            case BoardAction.MOVE:
                if (action.CellTo)
                {
                    changeState(GameState.ANIMATING_MOVE);
                    _gameEngine.Board.MovePiece(action.CellFrom, action.CellTo);
                }

                break;

            case BoardAction.ATTACK:
                changeState(GameState.MY_TURN_FIGHTING);
                _gameEngine.Board.AttackPiece(action.CellFrom, action.CellTo);
                break;

            case BoardAction.ATTACK_HELP:
                changeState(GameState.MY_TURN_FIGHTING);
                _gameEngine.Board.AttackHelpPiece(action.CellFrom, action.CellTo);
                break;

            case BoardAction.DEFEND_HELP:
                changeState(GameState.MY_TURN_FIGHTING);
                _gameEngine.Board.DefendHelpPiece(action.CellFrom, action.CellTo);
                break;

            case BoardAction.INTERACTION:
                changeState(GameState.ANIMATING_MOVE);
                PieceInteraction.Interact(action.CellFrom, action.CellTo);
                break;
            }

            if (action.Name != BoardAction.END_LEVEL && action.CellTo)
            {
                if (action.CellTo.Piece.HasKing() || action.CellFrom.Piece.HasKing() ||
                    (action.CellTo.HasFight && action.CellTo.AttackerPiece.HasKing()))
                {
                    _gameEngine.CenterCamera(action.CellTo.transform.position);
                }
            }
        }
Example #14
0
        // ------------------------
        // Undo
        // ------------------------

        #region UNDO
        public void AddToActionStack(CellScript _cell)
        {
            BoardAction boardAction = new BoardAction();

            // finding where the cell is on the list
            int index = m_cellList.FindIndex(cell => {
                return(cell == _cell);
            });

            boardAction.cellListPosition  = index;
            boardAction.currentCellStatus = GetSerializableCellFromCellScript(_cell);

            m_actionStack.Push(boardAction);
        }
Example #15
0
 private void UpdateUiForAction(BoardAction action)
 {
     if (action is SetLedBoardAction)
     {
         SetLedAction.Checked = true;
         SetLedBoardAction a = (SetLedBoardAction)action;
         SetLedActionStateOption.Checked = a.SetToState;
     }
     else if (action is SetPinBoardAction)
     {
         SetPinAction.Checked = true;
         SetPinBoardAction a = (SetPinBoardAction)action;
         if (Board.OutputPins.Contains(a.Pin))
         {
             SetPinActionPinOption.SelectedItem = a.Pin;
         }
         SetPinActionStateOption.Checked = a.SetToState;
     }
     else if (action is TogglePinBoardAction)
     {
         TogglePinAction.Checked = true;
         TogglePinBoardAction a = (TogglePinBoardAction)action;
         if (Board.OutputPins.Contains(a.Pin))
         {
             TogglePinActionPinOption.SelectedItem = a.Pin;
         }
     }
     else if (action is RunScriptBoardAction)
     {
         RunScriptAction.Checked = true;
         RunScriptBoardAction a = (RunScriptBoardAction)action;
         RunScriptActionFileNameOption.Text  = a.FileName;
         RunScriptActionArgumentsOption.Text = a.Arguments;
     }
     else if (action is SendTextBoardAction)
     {
         SendTextAction.Checked = true;
         SendTextBoardAction a = (SendTextBoardAction)action;
         SendTextActionTextOption.Text = a.Text;
     }
     else
     {
         NoAction.Checked = true;
     }
 }
 private void ActionsGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.RowIndex >= 0 && ActionsGridView.Columns[e.ColumnIndex].Name == ActionsColumnAction.Name)
     {
         BoardAction  action = BoardActions[e.RowIndex];
         ActionDialog d      = new ActionDialog(Board, "Edit Action", action);
         if (d.ShowDialog() == DialogResult.OK)
         {
             if (d.Action == null)
             {
                 BoardActions.RemoveAt(e.RowIndex);
             }
             else
             {
                 BoardActions[e.RowIndex] = d.Action;
             }
         }
     }
 }
Example #17
0
        private void Ok_Click(object sender, EventArgs e)
        {
            BoardAction a;

            if (CreateActionFromUi(out a))
            {
                if (!a.Valid(Board))
                {
                    ShowError("Invalid action");
                }
                else
                {
                    Action = a;

                    DialogResult = DialogResult.OK;
                    this.Close();
                }
            }
        }
Example #18
0
        private void _onNextActionChanged(BoardAction action)
        {
            Debug.Log(action.Name);
            switch (action.Name)
            {
            case BoardAction.MOVE:
                _showMoveToAction(action.CellFrom);
                _currentArrow.iconVisible = false;
                break;

            case BoardAction.ATTACK:
                _currentArrow.iconVisible = true;
                _currentArrow.icon.Sprite = InteractionIcon.ICON_ATTACK;
                break;

            case BoardAction.INTERACTION:
                _currentArrow.iconVisible = true;
                _currentArrow.icon.Sprite = InteractionIcon.ICON_INTERACTION;
                break;
            }
        }
Example #19
0
 void AnimateAction(BoardAction action)
 {
     if (action is RotateAction)
     {
         AnimateRotateAction((RotateAction)action);
     }
     else if (action is NewPieceAction)
     {
         AnimateNewPiece((NewPieceAction)action);
     }
     else if (action is RemoveAction)
     {
         AnimateRemoveAction((RemoveAction)action);
     }
     else if (action is FallAction)
     {
         AnimateFallAction((FallAction)action);
     }
     else if (action is CompactAction)
     {
         AnimateCompactAction((CompactAction)action);
     }
 }
Example #20
0
        public ActionDialog(BoardInterface board, String title, BoardAction currentAction)
        {
            InitializeComponent();

            Text   = title;
            Board  = board;
            Action = currentAction;

            DialogResult = DialogResult.Cancel;

            NoAction.Tag        = NoActionLabel;
            SetLedAction.Tag    = SetLedActionOptions;
            SetPinAction.Tag    = SetPinActionOptions;
            TogglePinAction.Tag = TogglePinActionOptions;
            RunScriptAction.Tag = RunScriptActionOptions;
            SendTextAction.Tag  = SendTextActionOptions;

            NoActionLabel.Enabled          = false;
            SetLedActionOptions.Enabled    = false;
            SetPinActionOptions.Enabled    = false;
            TogglePinActionOptions.Enabled = false;
            RunScriptActionOptions.Enabled = false;
            SendTextActionOptions.Enabled  = false;

            if (Board != null)
            {
                Object[] pins = Board.OutputPins.Cast <Object>().ToArray();
                SetPinActionPinOption.Items.AddRange(pins);
                TogglePinActionPinOption.Items.AddRange(pins);
            }
            else
            {
                TestAction.Hide();
            }

            UpdateUiForAction(Action);
        }
Example #21
0
    /*private void UpdateBoard()
    {
        foreach(Card card in Cards)
            if (card.State == CardStates.OnBoard && card.Health <= 0)
                DoDie (card.ID);
    }*/
    public static bool CanDoAction(BoardState InitialState, BoardAction Action)
    {
        if (Action.Type == "ACTION_DRAW_CARDS")
            return true;
        if (Action.Type == "ACTION_DEAL_DAMAGE")
            return true;
        if (Action.Type == "ACTION_START_TURN")
            return true;
        if (Action.Type == "ACTION_END_TURN")
            return true;
        if (Action.Type == "ACTION_PLAY_CARD")
        {
            Card ActorCard = InitialState.GetCard((int)Action.Actor);
            BoardState.Player Player = InitialState.Players[(int)Action.Player];
            return Player.CurrentMana >= InitialState.GetCardManaCost(ActorCard) && Action.Player == InitialState.ActivePlayer && ActorCard.State == CardStates.InHand;
        }
        if (Action.Type == "ACTION_ATTACK")
        {
            Card ActorCard = InitialState.GetCard((int)Action.Actor);
            int TargetID = (int)Action.Target;
            Card TargetCard = InitialState.GetCard(TargetID);

            if (ActorCard.CanAttack == false)
                return false;
            if (Action.Player != InitialState.ActivePlayer)
                return false;
            if (ActorCard.PlayerID == TargetCard.PlayerID)
                return false;
            if (InitialState.GetCardAttack(ActorCard) > 0 && (ActorCard.State == CardStates.Hero || ActorCard.State == CardStates.OnBoard) && (TargetCard.State == CardStates.Hero || TargetCard.State == CardStates.OnBoard))
                return true;

            return false;
        }
        if (Action.Type == "ACTION_DIE")
            return true;
        return true;
    }
Example #22
0
        private System.TimeSpan AnimationTime(BoardAction action)
        {
            if (action is NewPieceAction)
            {
                return(System.TimeSpan.FromSeconds(addPieceTime));
            }

            if (action is RemoveAction)
            {
                return(System.TimeSpan.FromSeconds(removeTime));
            }

            if (action is FallAction)
            {
                return(System.TimeSpan.FromSeconds(pieceFallTime));
            }

            if (action is CompactAction)
            {
                return(System.TimeSpan.FromSeconds(removeTime));
            }

            return(System.TimeSpan.Zero);
        }
Example #23
0
 private void CreateAndRunAction(BoardAction action)
 {
     _actionBroadcaster.Broadcast(action);
     RunAction(action);
 }
Example #24
0
 public void RunAction(BoardAction action)
 {
     action.Execute(this);
 }
 public void RegisterAction(BoardAction action)
 {
     Logger.LogRegisterAction(action);
     Actions.Add(action);
 }
Example #26
0
        private bool CreateActionFromUi(out BoardAction action)
        {
            if (NoAction.Checked)
            {
                action = null;
                return(true);
            }
            else if (SetLedAction.Checked)
            {
                bool setToState = SetLedActionStateOption.Checked;
                action = new SetLedBoardAction(setToState);
                return(true);
            }
            else if (SetPinAction.Checked)
            {
                if (SetPinActionPinOption.SelectedItem != null)
                {
                    NamedPin pin        = (NamedPin)SetPinActionPinOption.SelectedItem;
                    bool     setToState = SetPinActionStateOption.Checked;
                    action = new SetPinBoardAction(pin, setToState);
                    return(true);
                }
                else
                {
                    ShowError("Must select pin.");
                }
            }
            else if (TogglePinAction.Checked)
            {
                if (TogglePinActionPinOption.SelectedItem != null)
                {
                    NamedPin pin = (NamedPin)TogglePinActionPinOption.SelectedItem;
                    action = new TogglePinBoardAction(pin);
                    return(true);
                }
                else
                {
                    ShowError("Must select pin.");
                }
            }
            else if (RunScriptAction.Checked)
            {
                String fileName  = RunScriptActionFileNameOption.Text;
                String arguments = RunScriptActionArgumentsOption.Text;
                if (String.IsNullOrWhiteSpace(fileName))
                {
                    ShowError("File name cannot be blank.");
                }
                else
                {
                    action = new RunScriptBoardAction(fileName, arguments);
                    return(true);
                }
            }
            else if (SendTextAction.Checked)
            {
                String text = SendTextActionTextOption.Text;
                if (String.IsNullOrEmpty(text))
                {
                    ShowError("Text cannot be empty.");
                }
                else
                {
                    action = new SendTextBoardAction(text);
                    return(true);
                }
            }

            action = null;
            return(false);
        }
Example #27
0
 IEnumerator ExecuteAndAnimate(BoardAction action)
 {
     Game.Execute(action);
     AnimateAction(action);
     yield return(Util.Wait(AnimationTime(action)));
 }
Example #28
0
 // Use this for initialization
 void Start()
 {
     _gameEngine = GetComponent <GameEngine>() as GameEngine;
     _nextAction = new BoardAction();
 }
Example #29
0
 private void Awake()
 {
     _puzzleScale = GetComponent <PuzzleScale>();
     _boardAction = GetComponent <BoardAction>();
 }
Example #30
0
 public ActionData(BoardAction Action, BoardState FinalState, List<KeyValuePair<BoardAction, BoardState>> History)
 {
     this.Action = Action;
     this.FinalState = FinalState;
     this.History = History;
 }
Example #31
0
 public void BroadcastAction(BoardAction action)
 {
     // need to trim this to just the clients in a single session
     Clients.All.Broadcast(action);
 }