private Tile2048[,] rotateBoard(Tile2048[,] board, int amount)
    {
        Tile2048[,] rotBoard = copyBoard(board);
        for (int i = 0; i < amount; i++)
        {
            Tile2048[,] tempBoard = new Tile2048[4, 4];

            iterateOverBoardFromRight((int x, int y) => tempBoard [y, 3 - x] = rotBoard [x, y]);
            rotBoard = copyBoard(tempBoard);
        }

        return(rotBoard);
    }
Esempio n. 2
0
 public void findMergeTargets(int[] pos, Tile2048[,] board)
 {
     hasMerged = false;
     if (pos [0] + 1 >= 4)
     {
         return;
     }
     if (board[pos[0] + 1, pos[1]].canMerge(currentScore))
     {
         hasMerged   = true;
         mergeTarget = board [pos [0] + 1, pos [1]];
     }
 }
    private void slideBricks(int dir)
    {
        Tile2048[,] rotatedBoard = rotateBoard(vizGrid, dir);
        iterateOverBoardFromRight((int x, int y) => {
            if (rotatedBoard [x, y] != null)
            {
                Tile2048 temp      = rotatedBoard [x, y];
                int[] targetPos    = temp.calcNewPos(new int[] { x, y }, rotatedBoard);
                rotatedBoard[x, y] = null;
                rotatedBoard [targetPos [0], targetPos [1]] = temp;
            }
        });

        rotatedBoard = rotateBoard(rotatedBoard, 4 - dir);
        vizGrid      = copyBoard(rotatedBoard);

        //Slide all bricks
        iterateOverBoard((int x, int y) => { if (vizGrid [x, y] != null)
                                             {
                                                 vizGrid [x, y].startSlide(gridPos [x, y], new int[] { x, y });
                                             }
                         });
    }
 private Tile2048[,] copyBoard(Tile2048[,] a)
 {
     Tile2048[,] tempboard = new Tile2048[4, 4];
     iterateOverBoard((int x, int y) => tempboard[x, y] = a[x, y]);
     return(tempboard);
 }