Пример #1
0
    private void ControlHandler_OnMadeMove(Enumerators.Control.SwipeDirection swipeDirection)
    {
        if (allowedToMove)
        {
            return;
        }

        segmentObjects = new List <SegmentObject>()
        {
            segmentObjects[0]
        };
        segmentPositions.Clear();

        // Получает позицию главного персонажа на сетке
        Point currentPlayerPosition = GetPlayerPosition();

        Point newPlayerPosition = GetNewPlayerPosition(currentPlayerPosition, swipeDirection);

        if (newPlayerPosition != null)
        {
            if (newPlayerPosition != currentPlayerPosition)
            {
                newGridSegmentForPlayer = GameManager.Source.GridManager.GridSegments[newPlayerPosition.X, newPlayerPosition.Y];

                allowedToMove = true;

                iTween.ScaleTo(gameObject, iTween.Hash("z", 1.8f, "time", 0.2f));

                // Проиграть звук
                if (Sounds.IsOn)
                {
                    audioSource.Play();
                }
            }
        }
        else
        {
            gridSegmentsWithBonus.Clear();

            if (segmentObjects.Count > 1)
            {
                segmentObjects = new List <SegmentObject>()
                {
                    segmentObjects[0]
                };
                segmentPositions.Clear();
            }
        }
    }
Пример #2
0
    public void CheckPlayerForBlocking()
    {
        bool playerIsBlocked = true;

        for (int i = 0; i < 4; i++)
        {
            Enumerators.Control.SwipeDirection swipeDirection = Enumerators.Control.SwipeDirection.Up;

            switch (i)
            {
            case 0:
                swipeDirection = Enumerators.Control.SwipeDirection.Up;
                break;

            case 1:
                swipeDirection = Enumerators.Control.SwipeDirection.Down;
                break;

            case 2:
                swipeDirection = Enumerators.Control.SwipeDirection.Left;
                break;

            case 3:
                swipeDirection = Enumerators.Control.SwipeDirection.Right;
                break;
            }

            // Получает позицию главного персонажа на сетке
            Point currentPlayerPosition = GetPlayerPosition();

            Point newPlayerPosition = GetNewPlayerPosition(currentPlayerPosition, swipeDirection, false);

            if (newPlayerPosition != null)
            {
                if (newPlayerPosition != currentPlayerPosition)
                {
                    playerIsBlocked = false;
                }
            }
        }

        if (playerIsBlocked)
        {
            DoPlayerIsBlocked();
        }
    }
Пример #3
0
    private void ControlHandler_OnMadeMove(Enumerators.Control.SwipeDirection direction)
    {
        if (currentTask > tasks.Length - 1)
        {
            return;
        }

        if (tasks[currentTask].SwipeDirection == direction)
        {
            ExecuteTask(currentTask);
            currentTask++;

            gestureCanvasGroup.alpha = 0f;
            mySequence.Kill();
            GestureForTask();
        }
    }
 private void DoMadeMove(Enumerators.Control.SwipeDirection swipeDirection)
 {
     OnMadeMove?.Invoke(swipeDirection);
 }
Пример #5
0
    /// <summary>
    /// Поиск новой точки, в которую может переместиться игрок
    /// </summary>
    private Point GetNewPlayerPosition(Point curPlayerPosition, Enumerators.Control.SwipeDirection swipeDirection, bool collectBonuses = true)
    {
        if (currentGridSegmentWithPlayer != null)
        {
            Point dir = null;

            var grid = GameManager.Source.GridManager.GridSegments;

            // Определяет количество клеток на сетке в выбранном направлении
            int iterCount = 0;
            int high      = grid.GetLength(0) - 1;

            switch (swipeDirection)
            {
            case Enumerators.Control.SwipeDirection.Left:
                dir       = new Point(0, -1);
                iterCount = curPlayerPosition.Y;
                break;

            case Enumerators.Control.SwipeDirection.Right:
                dir       = new Point(0, 1);
                iterCount = high - curPlayerPosition.Y;
                break;

            case Enumerators.Control.SwipeDirection.Down:
                dir       = new Point(1, 0);
                iterCount = high - curPlayerPosition.X;
                break;

            case Enumerators.Control.SwipeDirection.Up:
                dir       = new Point(-1, 0);
                iterCount = curPlayerPosition.X;
                break;
            }

            Point curr = curPlayerPosition;

            int emptyCount = 0;

            for (int i = 0; i < iterCount; i++)
            {
                Point next = new Point(curr.X + dir.X, curr.Y + dir.Y);

                SegmentObject obj = grid[next.X, next.Y].OccupiedObject;

                if (obj != null)
                {
                    if (obj.Type == Enumerators.Game.SegmentObjectType.NotDraggable)
                    {
                        break;
                    }
                    else if (obj.Type == Enumerators.Game.SegmentObjectType.Draggable)
                    {
                        segmentObjects.Add(obj);
                    }
                }
                else
                {
                    if (collectBonuses)
                    {
                        if (grid[next.X, next.Y].ContainsBonus)
                        {
                            gridSegmentsWithBonus.Add(grid[next.X, next.Y]);
                        }
                    }

                    emptyCount++;
                }

                curr = next;
            }

            curr = new Point(curPlayerPosition.X + (dir.X * emptyCount), curPlayerPosition.Y + (dir.Y * emptyCount));

            for (int i = 0; i < segmentObjects.Count; i++)
            {
                if (i == 0)
                {
                    segmentPositions.Add(curr);
                }
                else
                {
                    Point newPoint = new Point(curr.X + (dir.X * i), curr.Y + (dir.Y * i));

                    segmentPositions.Add(newPoint);
                }
            }

            return(emptyCount > 0 ? curr : null);
        }

        return(null);
    }