Exemple #1
0
    public TreeControl.TreeColor[] GetColors()
    {
        int count = System.Enum.GetNames(typeof(TreeControl.TreeColor)).Length - 2;

        TreeControl.TreeColor[] colors = new TreeControl.TreeColor[count];
        for (int i = 0; i < count; i++)
        {
            colors [i] = (TreeControl.TreeColor)i;
        }
        Shuffle(colors);

        TreeControl.TreeColor[] colorDrops = new TreeControl.TreeColor[drops.Length];

        for (int i = 0; i < drops.Length; i++)
        {
            if (drops [i] == -1)
            {
                colorDrops [i] = TreeControl.TreeColor.NONE;
            }
            else if (drops [i] == -2)
            {
                colorDrops [i] = TreeControl.TreeColor.WILDCARD;
            }
            else
            {
                colorDrops [i] = colors [drops [i]];
            }
        }
        return(colorDrops);
    }
Exemple #2
0
    public TreeControl.TreeColor SetColor(List <TreeControl.TreeColor> possibleColors)
    {
        this.possibleColors = possibleColors;
        int rand = Random.Range(0, possibleColors.Count);

        finalColor = possibleColors[rand];
        return(finalColor);
    }
Exemple #3
0
 public void Shuffle(TreeControl.TreeColor[] array)
 {
     for (int i = 0; i < array.Length; i++)
     {
         int j = Random.Range(i, array.Length);
         TreeControl.TreeColor temp = array[i];
         array[i] = array[j];
         array[j] = temp;
     }
 }
Exemple #4
0
    private void MakeTree(int x, TreeControl.TreeColor color)
    {
        Vector2     position       = new Vector2((x - (float)width / 2 + .5f) * gridSpacing, 0);
        GameObject  newTree        = Instantiate(tree, position, Quaternion.identity);
        TreeControl newTreeControl = newTree.GetComponent <TreeControl> ();

        newTreeControl.color       = color;
        newTreeControl.gridSpacing = gridSpacing;
        newTreeControl.gridSize    = (int)(Mathf.Max(width, height) * 2);
        newTreeControl.Create();
        addingSet[newTreeControl] = new List <int[]>();
        addingSet[newTreeControl].Add(new int[] { x, 0 });
        addingSet[newTreeControl].Add(new int[] { x, 1 });
    }
Exemple #5
0
    public int CheckNeighbors(Vector2 point, Marker marker)
    {
        int x = (int)point.x;
        int y = (int)point.y;

        TreeControl.TreeColor color = marker.color;

        if (y > 0)
        {
            if (CanAdd(x - 1, y, color) || CanAdd(x + 1, y, color) || CanAdd(x, y - 1, color))
            {
                AddPoint(point, marker);
                return(1);
            }
            else if (pointsToTrees [x, y - 1] != null && pointsToTrees [x, y - 1].color != color)
            {
                return(-1);
            }
            else
            {
                return(0);
            }
        }
        else
        {
            if (color == TreeControl.TreeColor.WILDCARD)
            {
                return(-1);
            }
            else
            {
                AddPoint(point, marker);
                return(1);
            }
        }
    }
Exemple #6
0
 private bool CanAdd(int x, int y, TreeControl.TreeColor color)
 {
     return(x >= 0 && y >= 0 && x < width && y < height &&
            pointsToTrees [x, y] != null && (pointsToTrees [x, y].color == color ||
                                             color == TreeControl.TreeColor.WILDCARD));
 }
Exemple #7
0
    private void AddPoint(Vector2 point, Marker marker)
    {
        int x = (int)point.x;
        int y = (int)point.y;

        TreeControl.TreeColor color = marker.color;

        if (y > 0)
        {
            HashSet <TreeControl> added = new HashSet <TreeControl> ();
            if (CanAdd(x - 1, y, color))
            {
                added.Add(pointsToTrees [x - 1, y]);
            }
            if (CanAdd(x + 1, y, color))
            {
                added.Add(pointsToTrees [x + 1, y]);
            }
            if (CanAdd(x, y - 1, color))
            {
                added.Add(pointsToTrees [x, y - 1]);
            }

            List <TreeControl> addingList = new List <TreeControl>(added);
            if (color == TreeControl.TreeColor.WILDCARD)
            {
                Dictionary <TreeControl.TreeColor, List <TreeControl> > colorsToTrees =
                    new Dictionary <TreeControl.TreeColor, List <TreeControl> >();
                foreach (TreeControl treeControl in added)
                {
                    if (!colorsToTrees.ContainsKey(treeControl.color))
                    {
                        colorsToTrees[treeControl.color] = new List <TreeControl>();
                    }
                    colorsToTrees[treeControl.color].Add(treeControl);
                }

                List <TreeControl.TreeColor> colorsList = new List <TreeControl.TreeColor>(colorsToTrees.Keys);
                WildCardMarker        wildMarker        = (WildCardMarker)marker;
                TreeControl.TreeColor wildColor         = wildMarker.SetColor(colorsList);
                addingList = colorsToTrees[wildColor];
            }

            if (addingList.Count > 1)
            {
                foreach (TreeControl treeControl in addingList)
                {
                    GameControl.animationLock.Inc();
                    deletingSet.Add(treeControl);
                }
                AddToTrees(addingList, marker, point);
            }
            else
            {
                TreeControl addedTree = addingList [0];
                GameControl.animationLock.Inc();
                AddToTrees(addingList, marker, point);

                if (!addingSet.ContainsKey(addedTree))
                {
                    addingSet[addedTree] = new List <int[]>();
                }
                addingSet[addedTree].Add(new int[] { x, y });
            }
        }
        else if (color != TreeControl.TreeColor.WILDCARD)
        {
            GameControl.animationLock.Inc();
            MakeTree(x, color);
        }
    }