Ejemplo n.º 1
0
    public void CalculateCenterPosAndToward(Vector2Int headPos, int[,] checkboard)
    {
        int row = checkboard.GetLength(0);
        int col = checkboard.GetLength(1);

        if (headPos.x + 1 < row && checkboard[headPos.x + 1, headPos.y] == TileMapUtil.centerNum)
        {
            toward    = PlaneToward.Top;
            centerPos = new Vector2Int(headPos.x + 1, headPos.y);
        }
        else if (headPos.y - 1 >= 0 && checkboard[headPos.x, headPos.y - 1] == TileMapUtil.centerNum)
        {
            toward    = PlaneToward.Right;
            centerPos = new Vector2Int(headPos.x, headPos.y - 1);
        }
        else if (headPos.x - 1 >= 0 && checkboard[headPos.x - 1, headPos.y] == TileMapUtil.centerNum)
        {
            toward    = PlaneToward.Bottom;
            centerPos = new Vector2Int(headPos.x - 1, headPos.y);
        }
        else if (headPos.y + 1 < col && checkboard[headPos.x, headPos.y + 1] == TileMapUtil.centerNum)
        {
            toward    = PlaneToward.Left;
            centerPos = new Vector2Int(headPos.x, headPos.y + 1);
        }
    }
Ejemplo n.º 2
0
    public void Toward()
    {
        int[,] copy = (int[, ])checkerboard.Clone();
        PlaneToward preToward = toward;

        ResetData();

        int t = (int)toward + 1;

        t     %= Enum.GetValues(typeof(PlaneToward)).Length;
        toward = (PlaneToward)t;

        Vector2Int extraOffset = new Vector2Int(0, 0);

        if (!CanSetPlane(checkerboard, extraOffset))
        {
            checkerboard = copy;
            toward       = preToward;
            return;
        }
        SetData(checkerboard, extraOffset);

        RotatePlane();
    }
Ejemplo n.º 3
0
    public void RandomPlanePos()
    {
        int[,] doneCheckboard = new int[row, col];
        while (true)
        {
            int doneNum = 0;
            int[,] tempCheckboard = new int[row, col];
            for (int num = 0; num < planes.Count; num++)
            {
                Array         values  = Enum.GetValues(typeof(PlaneToward));
                System.Random random  = new System.Random();
                int           indexTo = random.Next(0, values.Length);
                PlaneToward   to      = (PlaneToward)values.GetValue(indexTo);

                Plane plane = planes[num];
                plane.tempToward = to;

                Dictionary <int, List <int> > queue = new Dictionary <int, List <int> >();

                for (int i = 0; i < row; i++)
                {
                    queue[i] = new List <int>();
                    for (int j = 0; j < col; j++)
                    {
                        if (tempCheckboard[i, j] == 0)
                        {
                            queue[i].Add(j);
                        }
                    }
                }
                bool completed = false;

                while (!completed)
                {
                    List <int> keys = queue.Keys.ToList();
                    int        x    = random.Next(0, keys.Count);
                    int        r    = keys[x];

                    int y = random.Next(0, queue[r].Count);
                    int c = queue[r][y];


                    queue[r].Remove(c);
                    if (queue[r].Count < 1)
                    {
                        queue.Remove(r);
                    }

                    if (queue.Count < 1)
                    {
                        break;
                    }

                    plane.tempCenterPos = new Vector2Int(r, c);

                    if (!plane.CanSetTempPlane(tempCheckboard))
                    {
                        continue;
                    }
                    plane.PreSetData(tempCheckboard);
                    completed = true;
                    doneNum  += 1;
                }
            }
            if (doneNum >= 3)
            {
                doneCheckboard = tempCheckboard;
                break;
            }
        }
        foreach (Plane p in planes)
        {
            p.RandomDone(doneCheckboard);
            p.RotatePlane();
            TileMapUtil.SetPlanePos(p, tileMap);
        }

        checkerboard = doneCheckboard;

        TileMapUtil.Draw(tileMap, checkerboard, planeTile, wallTile);
    }
Ejemplo n.º 4
0
 public void RandomDone(int[,] tempCheckboard)
 {
     checkerboard = tempCheckboard;
     centerPos    = tempCenterPos;
     toward       = tempToward;
 }