コード例 #1
0
    public void SetGridObject(Vector3 worldPosition, TestGridObject value)
    {
        int x, y;

        GetXY(worldPosition, out x, out y);
        SetGridObject(x, y, value);
    }
コード例 #2
0
 public void SetGridObject(int x, int y, TestGridObject value)
 {
     if (x >= 0 && y >= 0 && x < width && y < height)
     {
         gridArray[x, y]           = value;
         debugTestArray[x, y].text = gridArray[x, y]?.ToString();
     }
 }
コード例 #3
0
 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         Color   c = inventoryScreen.GetComponent <DisplayColors>().getCurrentColor();
         Vector3 position = GetMouseWorldPosition();
         int     x, y;
         grid.GetXYNew(position, out x, out y);
         Color c1 = grid.getXYColor(x, y);
         //Debug.Log(x + " , " + y + " " + position);// + " island number " + grid.GetGridObjectNew(position).getIslandNumber());
         TestGridObject testGridObject = grid.GetGridObjectNew(position);
         if (testGridObject != null && c1 == c)
         {
             testGridObject.unlock();
         }
     }
 }
コード例 #4
0
    public void colorInAllNeighbors(int x_start, int y_start)
    {
        if (x_start >= width || y_start >= height || x_start < 0 || y_start < 0)
        {
            return;
        }
        //if (debugTestArray[x_start, y_start].text == "done") return;
        //debugTestArray[x_start, y_start].text = "done";
        TestGridObject tgo = GetGridObject(x_start, y_start);

        if (tgo.isunlocked)
        {
            return;
        }
        tgo.isunlocked = true;
        debugTestArray[x_start, y_start].color = colorArray[x_start, y_start];

        colorInAllNeighbors(x_start + 1, y_start);
        colorInAllNeighbors(x_start - 1, y_start);
        colorInAllNeighbors(x_start, y_start + 1);
        colorInAllNeighbors(x_start, y_start - 1);
    }
コード例 #5
0
    public void colorInSameColorNeighbors(int x_start, int y_start, Color color)
    {
        if (x_start >= width || y_start >= height || x_start < 0 || y_start < 0)
        {
            return;
        }
        if (colorArray[x_start, y_start] != color)
        {
            return;
        }

        TestGridObject tgo = GetGridObject(x_start, y_start);

        if (tgo.isunlocked)
        {
            return;
        }

        tgo.isunlocked = true;
        debugTestArray[x_start, y_start].color = colorArray[x_start, y_start];

        int i = 1;

        while (i < Math.Max(width, height))
        {
            bool neighboringColor = false;
            int  x, y;
            for (y = Math.Max(y_start - i, 0); y <= Math.Min(y_start + i, height - 1); y++)
            {
                x = Math.Min(x_start + i, width - 1);
                if (colorArray[x, y] == color)
                {
                    debugTestArray[x, y].color = color;
                    neighboringColor           = true;
                }
                x = Math.Max(x_start - i, 0);
                if (colorArray[x, y] == color)
                {
                    debugTestArray[x, y].color = color;
                    neighboringColor           = true;
                }
            }
            for (x = Math.Max(x_start - i, 0); x <= Math.Min(x_start + i, width - 1); x++)
            {
                y = Math.Min(y_start + i, height - 1);
                if (colorArray[x, y] == color)
                {
                    debugTestArray[x, y].color = color;
                    neighboringColor           = true;
                }
                y = Math.Max(y_start - i, 0);
                if (colorArray[x, y] == color)
                {
                    debugTestArray[x, y].color = color;
                    neighboringColor           = true;
                }
            }
            if (!neighboringColor)
            {
                return;
            }
            i += 1;
        }

        //colorInSameColorNeighbors(x_start + 1, y_start, color);
        //colorInSameColorNeighbors(x_start - 1, y_start, color);
        //colorInSameColorNeighbors(x_start, y_start + 1, color);
        //colorInSameColorNeighbors(x_start, y_start - 1, color);
    }