示例#1
0
    public IAction UpdateField()
    {
        ActionSequence updateActionSequence = new ActionSequence();

        List <RectInt> currentCombinations = combinationsFinder.GetCurrentCombinations();

        while (currentCombinations.Count > 0)
        {
            IAction removalAction           = RemoveCombinations(currentCombinations);
            IAction fillingEmptyCellsAction = CreateNewFieldObjectsAndFillEmptyCells();

            ActionSequence updateIterationActionSequence = new ActionSequence();
            updateIterationActionSequence.AddAction((callback) => { removalAction.Play(callback); });
            updateIterationActionSequence.AddAction((callback) => { fillingEmptyCellsAction.Play(callback); });

            updateActionSequence.AddAction((callback) => { updateIterationActionSequence.Play(callback); });

            currentCombinations = combinationsFinder.GetCurrentCombinations();
        }

        return(updateActionSequence);
    }
示例#2
0
    private void OnMouseDown()
    {
        Vector2    mouseToWorldPosition = CalculateMousePositionOnField();
        Vector2Int currentlyClickedCell = fieldProperties.CalculateCellFromLocalPosition(mouseToWorldPosition);

        if (fieldObjectMarker.IsAnyFieldObjectMarked())
        {
            Vector2Int previouslyClickedCell = fieldObjectMarker.GetMarkedFieldObjectCell();
            fieldObjectMarker.RemoveMark();

            if (AreSelectedCellsAdjacent(currentlyClickedCell, previouslyClickedCell))
            {
                DisableUserInput();

                ActionSequence fieldUpdateActionSequence = new ActionSequence();

                IAction swapAnimationActionPack = fieldObjectSwapper.SwapFieldObjects(currentlyClickedCell, previouslyClickedCell);
                fieldUpdateActionSequence.AddAction(swapAnimationActionPack);

                if (combinationsFinder.GetCurrentCombinations().Count > 0)
                {
                    IAction fieldUpdateActionPack = fieldUpdater.UpdateField();
                    fieldUpdateActionSequence.AddAction(fieldUpdateActionPack);
                }
                else
                {
                    IAction swapBackAnimationActionPack = fieldObjectSwapper.SwapFieldObjects(currentlyClickedCell, previouslyClickedCell);
                    fieldUpdateActionSequence.AddAction(swapBackAnimationActionPack);
                }

                fieldUpdateActionSequence.AddAction((callback) => { EnableUserInput(); callback(); });

                fieldUpdateActionSequence.Play(null);
            }
            else if (currentlyClickedCell != previouslyClickedCell)
            {
                fieldObjectMarker.MarkFieldObject(currentlyClickedCell);
            }
        }
        else
        {
            fieldObjectMarker.MarkFieldObject(currentlyClickedCell);
        }
    }