private void ApplyGravity(GameObject[,] go, Texture2D[] boxColors) { //x axis is [1], y axis is [0] //i.e. go[y,x] for actual game objects for (int y = go.GetLength(1) - 2; y >= 0; y--) { for (int x = go.GetLength(0) - 1; x >= 0; x--) { if (go[y + 1, x].Texture == boxColors[0]) //if the box below is black { go[y + 1, x].Texture = go[y, x].Texture; go[y, x].Texture = boxColors[0]; } } } }
private void DropBoxFromTop(GameObject topBox, GameObject[,] boxes) { if (boxes[0, topRowPointer].Texture == boxColors[0]) //if the top space is empty, enter the main method { if (boxes[0, topRowPointer].Texture == boxColors[0] && boxes[1,topRowPointer].Texture != boxColors[0]) { boxes[0, topRowPointer].Texture = topBoxes[topRowPointer].Texture; } else { for (int row = 0; row < boxes.GetLength(1) - 1; row++) { if (boxes[row + 1, topRowPointer].Texture == boxColors[0]) //if the space below is empty { boxes[row, topRowPointer].Texture = boxColors[0]; boxes[row + 1, topRowPointer].Texture = topBoxes[topRowPointer].Texture; } else { topBoxes[topRowPointer].Texture = boxColors[0]; getRandomColor(topBoxes[topRowPointer]); } } } } else { } //do nothing; the box shouldn't be dropped }
private void RotateClockWise(GameObject[,] go, Texture2D[] boxColors) { int n = go.GetLength(0); int m = go.GetLength(1); Texture2D[,] matrix = new Texture2D[n, m]; for (int i = 0; i < go.GetLength(0); i++) { for (int j = 0; j < go.GetLength(1); j++) { matrix[i,j] = go[i, j].Texture; } } Texture2D[,] temp1 = new Texture2D[n, m]; Texture2D[,] temp2 = new Texture2D[n, m]; Texture2D[,] temp3 = new Texture2D[n, m]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { temp1[i, j] = matrix[n - j - 1, i]; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { temp2[i, j] = temp1[n - j - 1, i]; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { temp3[i, j] = temp2[n - j - 1, i]; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { go[i, j].Texture = temp3[i, j]; } } }
private void CheckForMatches(GameObject[,] box, Texture2D[] boxColors) { for (int i = 0; i < box.GetLength(0); i++) { for (int j = 0; j < box.GetLength(1); j++) { try { if (box[i, j].Texture == box[i - 1, j].Texture && box[i, j].Texture== box[i - 2, j].Texture) //if the three boxes have the same color - 1 { box[i, j].Texture = boxColors[0]; box[i - 1, j].Texture = boxColors[0]; box[i - 2, j].Texture = boxColors[0]; } } catch { } try { if (box[i, j].Texture == box[i - 1, j].Texture && box[i, j].Texture == box[i + 1, j].Texture) //if the three boxes have the same color - 2 { box[i, j].Texture = boxColors[0]; box[i - 1, j].Texture = boxColors[0]; box[i + 1, j].Texture = boxColors[0]; } } catch { } try { if (box[i, j].Texture == box[i + 1, j].Texture && box[i, j].Texture == box[i + 2, j].Texture) //if the three boxes have the same color - 3 { box[i, j].Texture = boxColors[0]; box[i + 1, j].Texture = boxColors[0]; box[i + 2, j].Texture = boxColors[0]; } } catch { } try { if (box[i, j].Texture == box[i, j - 1].Texture && box[i, j].Texture == box[i, j - 2].Texture) //if the three boxes have the same color - 4 { box[i, j].Texture = boxColors[0]; box[i, j - 1].Texture = boxColors[0]; box[i, j - 2].Texture = boxColors[0]; } } catch { } try { if (box[i, j].Texture == box[i , j - 1].Texture && box[i, j].Texture == box[i, j + 1].Texture) //if the three boxes have the same color - 5 { box[i, j].Texture = boxColors[0]; box[i, j - 1].Texture = boxColors[0]; box[i, j + 1].Texture = boxColors[0]; } } catch { } try { if (box[i, j].Texture == box[i , j + 1].Texture && box[i, j].Texture == box[i, j + 2].Texture) //if the three boxes have the same color - 6 { box[i, j].Texture = boxColors[0]; box[i, j + 1].Texture = boxColors[0]; box[i, j + 2].Texture = boxColors[0]; } } catch { } } } }