Ejemplo n.º 1
0
    public void ClickToSwap(int x, int y)
    {
        int dx = GetDx(x, y);
        int dy = GetDy(x, y);

        NumberBox currentBox = grid[x, y];
        NumberBox nextBox    = grid[x + dx, y + dy];

        grid[x, y]           = nextBox;
        grid[x + dx, y + dy] = currentBox;

        currentBox.UpdatePos(x + dx, y + dy);
        currentBox.StartMovingAnimation(GetIconCenterByCell(new CCell(x, y)), GetIconCenterByCell(new CCell(x + dx, y + dy)));

        nextBox.UpdatePos(x, y);
        nextBox.transform.position = GetIconCenterByCell(new CCell(x, y));
    }
Ejemplo n.º 2
0
    public void Shuffle(System.Random random, NumberBox[,] array)
    {
        int lengthRow = array.GetLength(1);

        for (int i = array.Length - 1; i > 0; i--)
        {
            int x0 = i % lengthRow;
            int y0 = i / lengthRow;

            int j  = random.Next(i + 1);
            int x1 = j % lengthRow;
            int y1 = j / lengthRow;

            NumberBox temp = array[x0, y0];
            array[x0, y0] = array[x1, y1];
            array[x1, y1] = temp;

            temp.UpdatePos(x1, y1);
            temp.transform.position = GetIconCenterByCell(new CCell(x1, y1));

            array[x0, y0].UpdatePos(x0, y0);
            array[x0, y0].transform.position = GetIconCenterByCell(new CCell(x0, y0));
        }
    }