Example #1
0
    // Finds adjacent board spaces
    public void CalculateAdjacentSpaces(List <List <BoardSpace> > board)
    {
        BoardSpace left   = null;
        BoardSpace right  = null;
        BoardSpace top    = null;
        BoardSpace bottom = null;

        if (boardIndex.x > 0)
        {
            left = board[boardIndex.x - 1][boardIndex.y];
        }
        if (boardIndex.x < board.Count - 1)
        {
            right = board[boardIndex.x + 1][boardIndex.y];
        }
        if (boardIndex.y > 0)
        {
            bottom = board[boardIndex.x][boardIndex.y - 1];
        }
        if (boardIndex.y < board[0].Count - 1)
        {
            top = board[boardIndex.x][boardIndex.y + 1];
        }
        adjacentSpaces = new AdjacentSpaces(left, right, top, bottom);

        // add dot spawners to the top row
        if (top == null)
        {
            IsTopSpace = true;
            BoardSpaceSpawner boardSpaceSpawner = gameObject.AddComponent <BoardSpaceSpawner>();
            boardSpaceSpawner.SetCoordinateSpace(coordinateSpace);
            boardSpaceSpawner.SetDotManager(dotManager);
            spawner = boardSpaceSpawner;
        }
    }
Example #2
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);
    }