public bool IsTetrominoInCollision(BrickType[,] tetrominoGrid, int column, int row) { // check for collisions between the tetromino and the game board's bricks for (int iRow = 0; iRow < tetrominoGrid.GetLength(0); iRow++) { for (int iCol = 0; iCol < tetrominoGrid.GetLength(1); iCol++) { if (tetrominoGrid[iRow, iCol] != BrickType.None && m_gameBoardState[iRow + row, iCol + column] != BrickType.None) return true; // collision } } return false; }
/// <summary> /// Can move the tetromino to within the horizontal boundaries of the game board (left,right boundaries only). /// </summary> /// <param name="tetrominoGrid"></param> /// <param name="column">Column in which the left top cell of the descriptive grid is. Top row has index 0.</param> /// <param name="row">Row in which the left top cell of the descriptive grid is. Leftmost column has index 0.</param> /// <returns>Returns false if the tetromino starts to intersect the bottom.</returns> public bool FitTetrominoToGameBoard(BrickType[,] tetrominoGrid, ref int column, ref int row) { // first move the tetromino within the boundaries: for (int iRow = 0; iRow < tetrominoGrid.GetLength(0); iRow++) { for (int iCol = 0; iCol < tetrominoGrid.GetLength(1); iCol++) { if (tetrominoGrid[iRow, iCol] != BrickType.None) { if (row + iRow < 0) { // not a problem, does not happen } if (row + iRow >= m_rows) { return false; // bottom was intersected } if (column + iCol < 0) { column = -iCol; } if (column + iCol >= m_columns) { column = m_columns - iCol - 1; } } } } return true; }