// INITIALZE public void CheckForDestroyBlocks(int setScoreMultiplier) { blockGrid = manager.blockGrid; scoreMultiplier = setScoreMultiplier; numFallingBlocks = 0; Queue <int[]> destroySquares = new Queue <int[]>(); int numDestroySquares = 0; pointsGrid = new int[towerWidth, towerHeight]; // All values should initialize to zero for (int i = 0; i < towerWidth - 1; i++) { for (int j = 0; j < towerHeight - 1; j++) { GameObject blockObject = blockGrid[i, j]; if (blockObject == null) { break; // blocks in a vertical stack must be contiguous } BlockScript blockScript = blockObject.GetComponent <BlockScript>(); string type = blockScript.type; if (i + 1 >= towerWidth || j + 1 >= towerHeight || blockGrid[i + 1, j] == null || blockGrid[i + 1, j].GetComponent <BlockScript>().type != type || blockGrid[i, j + 1] == null || blockGrid[i, j + 1].GetComponent <BlockScript>().type != type || blockGrid[i + 1, j + 1] == null || blockGrid[i + 1, j + 1].GetComponent <BlockScript>().type != type) { continue; } else { // Add block to pointsGrid pointsGrid[i, j] += 3; // CheckBlock will add +1, for a total of 4 points per DestroySquare block pointsGrid[i + 1, j] += 3; pointsGrid[i, j + 1] += 3; pointsGrid[i + 1, j + 1] += 3; destroySquares.Enqueue(new int[2] { i, j }); numDestroySquares++; } } } if (numDestroySquares == 0) { blockPair.InitializeBlockPair(); } else { audioManager.PlayBlockSound("BREAK"); Debug.Log("BLOCK BONUS: " + numDestroySquares * numDestroySquares * numDestroySquares * scoreMultiplier * manager.speed); manager.addPoints(numDestroySquares * numDestroySquares * numDestroySquares * scoreMultiplier * manager.speed); debugPointsFromBlocks += numDestroySquares * numDestroySquares * numDestroySquares * scoreMultiplier * manager.speed; startBlockDestroy(destroySquares); } }
private void startNewGame() { // Restart score and level gameOver = false; speed = 1; score = 0; backgroundPanel.SetActive(false); highScoreManager.HideHighScoreScreen(); audioManager.SetGameOver(false); updateText(); // Destroy all blocks for (int i = 0; i < blockGrid.GetLength(0); i++) { for (int j = 0; j < blockGrid.GetLength(1); j++) { GameObject blockObject = blockGrid[i, j]; if (blockObject != null) { Destroy(blockObject); blockGrid[i, j] = null; } } } if (blockPair.leftBlock != null) { Destroy(blockPair.leftBlock.gameObject); } if (blockPair.rightBlock != null) { Destroy(blockPair.rightBlock.gameObject); } currentHeights = new int[6] { 0, 0, 0, 0, 0, 0 }; // Add start blocks to column // AddBlockToColumn(blockPair.SpawnBlock("earth", 1).gameObject); // AddBlockToColumn(blockPair.SpawnBlock("air", 2).gameObject); // AddBlockToColumn(blockPair.SpawnBlock("water", 3).gameObject); // AddBlockToColumn(blockPair.SpawnBlock("fire", 4).gameObject); // // initialize block pair blockPair.isActive = true; blockPair.gameOver = false; blockPair.InitializePreviewBlocks(); blockPair.InitializeBlockPair(); flashPermanentAlert(""); audioManager.PlayAudio(); }