// Hàm tạo 1 khối mới private void addShape(int shapeNumber, int _left = 0, int _down = 0) { removeShape(); currentTetrominoRow = new List <int>(); currentTetrominoColumn = new List <int>(); Rectangle square = null; if (!isRotated) { currentTetromino = null; currentTetromino = tetramino.getVariableByString(tetramino.getArrayTetrominos()[shapeNumber].ToString()); } int firstDim = currentTetromino.GetLength(0); int secondDim = currentTetromino.GetLength(1); currentTetrominoWidth = secondDim; currentTetrominoHeigth = firstDim; if (currentTetromino == tetramino.I_Tetromino_90) { currentTetrominoWidth = 1; } else if (currentTetromino == tetramino.I_Tetromino_0) { currentTetrominoHeigth = 1; } for (int row = 0; row < firstDim; row++) { for (int column = 0; column < secondDim; column++) { int bit = currentTetromino[row, column]; if (bit == 1) { square = tetramino.getBasicSquare(handleColor(board.getColor(), shapeNumber)); board.getMainGrid().Children.Add(square); square.Name = "moving_" + Grid.GetRow(square) + "_" + Grid.GetColumn(square); if (_down >= board.getMainGrid().RowDefinitions.Count - currentTetrominoHeigth) { _down = board.getMainGrid().RowDefinitions.Count - currentTetrominoHeigth; } Grid.SetRow(square, rowCount + _down); Grid.SetColumn(square, columnCount + _left); currentTetrominoRow.Add(rowCount + _down); currentTetrominoColumn.Add(columnCount + _left); } columnCount++; } columnCount = 0; rowCount++; } columnCount = 0; rowCount = 0; if (!nextShapeDrawed) { drawNextShape(nextShapeNumber); } }
// Hàm xoay khối public void shapeRotation(ref int _rotation, int currentShapeNumber, ref int[,] currentTetromino) { if (tetramino.getArrayTetrominos()[currentShapeNumber].IndexOf("I_") == 0) { if (_rotation > 90) { _rotation = 0; } currentTetromino = tetramino.getVariableByString("I_Tetromino_" + _rotation); } else if (tetramino.getArrayTetrominos()[currentShapeNumber].IndexOf("T_") == 0) { currentTetromino = tetramino.getVariableByString("T_Tetromino_" + _rotation); } else if (tetramino.getArrayTetrominos()[currentShapeNumber].IndexOf("S_") == 0) { if (_rotation > 90) { _rotation = 0; } currentTetromino = tetramino.getVariableByString("S_Tetromino_" + _rotation); } else if (tetramino.getArrayTetrominos()[currentShapeNumber].IndexOf("Z_") == 0) { if (_rotation > 90) { _rotation = 0; } currentTetromino = tetramino.getVariableByString("Z_Tetromino_" + _rotation); } else if (tetramino.getArrayTetrominos()[currentShapeNumber].IndexOf("J_") == 0) { currentTetromino = tetramino.getVariableByString("J_Tetromino_" + _rotation); } else if (tetramino.getArrayTetrominos()[currentShapeNumber].IndexOf("L_") == 0) { currentTetromino = tetramino.getVariableByString("L_Tetromino_" + _rotation); } else if (tetramino.getArrayTetrominos()[currentShapeNumber].IndexOf("O_") == 0) // Do not rotate this { return; } }