Ejemplo n.º 1
0
    // Attempt to add the given space to the current dot link
    public void AddSpace(BoardSpace space)
    {
        // already connected, don't allow
        if (ConnectionExists(space))
        {
            return;
        }

        previousConnected = lastConnected;
        lastConnected     = space;

        // the link's type matches the first dot added
        if (IsEmpty())
        {
            dotType = space.GetCurrentDot().GetDotType();
        }

        // add the dot
        currentConnectedSpaces.Add(space);
        space.GetCurrentDot().Select();

        // connect last spaces with the line
        if (currentConnectedSpaces.Count >= 2)
        {
            previousConnected.Connect(lastConnected);
        }
    }
Ejemplo n.º 2
0
    IEnumerator Drop()
    {
        bool overlappingDrop = dotsDropping;

        dotsDropping = true;

        // Drop dots column by column
        for (int k = 0; k < boardHeight; k++)
        {
            for (int i = 0; i < boardWidth; i++)
            {
                BoardSpace    curSpace        = BoardArray[i][k];
                DotController curDot          = curSpace.GetCurrentDot();
                bool          alreadyDropping = curDot.IsDropping;
                if (curSpace.IsEmpty || curDot.FlaggedToDrop || curDot.IsDropping)
                {
                    dotsToDrop++;
                    curDot.OnDropComplete += OnDropComplete;
                    curSpace.DropDot(dropTime);
                }
            }

            // offset each row's drop, if its not an overlapping drop call
            if (!overlappingDrop)
            {
                yield return(dropRow);
            }
        }
    }
Ejemplo n.º 3
0
    // Line from the last connected space to the touch position
    void UpdateLine(Vector3 touchPos)
    {
        if (!currentDotLink.IsEmpty())
        {
            BoardSpace lastConnected = currentDotLink.lastConnected;
            Vector3    lineStart     = lastConnected.GetScreenPosition();

            touchLine.SetType(lastConnected.GetCurrentDot().GetDotType());
            touchLine.SetPoints(lineStart, touchPos);
        }
    }
Ejemplo n.º 4
0
 // Check if the given space is valid, and of the same type
 void AddPotentialSpace(BoardSpace space)
 {
     if (space == null || space.IsEmpty)
     {
         return;
     }
     if (space.GetCurrentDot().GetDotType().typeID != dotType.typeID)
     {
         return;
     }
     potentialSpaces.Add(space);
 }
Ejemplo n.º 5
0
    // Recursively propogates up adjacent spaces to find a new dot
    DotController FindNextDot(BoardSpace space, List <Waypoint> waypoints)
    {
        AdjacentSpaces adjacent      = space.GetAdjacentSpaces();
        Waypoint       spaceWaypoint = new Waypoint(screenPosition);

        if (space.IsTopSpace)
        {
            BoardSpaceSpawner boardSpaceSpawner = space.GetSpawner();
            DotController     dot = space.GetCurrentDot();

            // Spawn a new dot to drop
            if (space.IsEmpty || dot.FlaggedToDrop)
            {
                waypoints.Add(spaceWaypoint);
                DotController newDot = boardSpaceSpawner.SpawnDot(waypoints);
                newDot.FlaggedToDrop = true;
                return(newDot);
            }

            // Current dot is valid
            waypoints.Add(spaceWaypoint);
            for (int i = 0; i < waypoints.Count; i++)
            {
                dot.AddWaypoint(waypoints[i]);
            }
            dot.FlaggedToDrop = true;
            return(dot);
        }

        BoardSpace    nextSpace = adjacent.Top;
        DotController nextDot   = nextSpace.GetCurrentDot();

        // Propogate up adjacent dots
        if (nextSpace.IsEmpty || nextDot.FlaggedToDrop)
        {
            waypoints.Add(spaceWaypoint);
            return(FindNextDot(nextSpace, waypoints));
        }

        // Found valid dot
        waypoints.Add(spaceWaypoint);
        for (int i = 0; i < waypoints.Count; i++)
        {
            nextDot.AddWaypoint(waypoints[i]);
        }
        nextDot.FlaggedToDrop = true;
        return(nextDot);
    }
Ejemplo n.º 6
0
    // Square was created. Select all dots of given type
    public void Create(DotManager.DotType dotType)
    {
        for (int i = 0; i < board.BoardArray.Count; i++)
        {
            for (int k = 0; k < board.BoardArray[i].Count; k++)
            {
                BoardSpace    curSpace = board.BoardArray[i][k];
                DotController curDot   = curSpace.GetCurrentDot();
                if (curDot.GetDotType().typeID == dotType.typeID)
                {
                    curDot.Select();

                    // only add to our toScore list once
                    if (!squareCreated)
                    {
                        toScore.Add(curSpace);
                    }
                }
            }
        }
        squareCreated = true;
        Handheld.Vibrate();
    }
Ejemplo n.º 7
0
    // Drop dots to refill the board
    public void DropDots()
    {
        // stops all dot movement and drop coroutines, for overlapping drop calls
        if (DropCoroutine != null)
        {
            StopCoroutine(DropCoroutine);
        }
        dotsToDrop  = 0;
        dotsDropped = 0;
        for (int i = 0; i < boardWidth; i++)
        {
            for (int k = 0; k < boardHeight; k++)
            {
                BoardSpace    curSpace = BoardArray[i][k];
                DotController curDot   = curSpace.GetCurrentDot();
                if (!curSpace.IsEmpty)
                {
                    curDot.StopMovement();
                }
            }
        }

        // find or spawn new dots to go into score board spaces
        for (int i = 0; i < boardWidth; i++)
        {
            for (int k = 0; k < boardHeight; k++)
            {
                BoardSpace    curSpace = BoardArray[i][k];
                DotController curDot   = curSpace.GetCurrentDot();
                if (curSpace.IsEmpty || curDot.FlaggedToDrop)
                {
                    curSpace.SetNewDot();
                }
            }
        }
        DropCoroutine = StartCoroutine(Drop());
    }