コード例 #1
0
ファイル: BoardSpace.cs プロジェクト: rcornwal/DotsGame
    // 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);
    }