// Mark chained Units then call destroy Units method public void markChainedUnits() { GameStateController.currentState = GameStateController.gameState.destroyingUnit; // Create a puzzle value matrix to scan for chained units _noChainedUnit = true; for (int YIndex = 0; YIndex < puzzleGen._rows; YIndex++) { for (int XIndex = 0; XIndex < puzzleGen._columns; XIndex++) { scanUnitARR[XIndex, YIndex] = new ScanUnit(puzzleGen._unitARR[XIndex, YIndex].GetComponent<UnitInfo>()._value); } } #region Scan and Mark chained Units scanBlockNineChained(); scanCrossNineChained(); scanTSevenChained(); scanUSevenChained(); scanLineFiveChained(); scanLFiveChained(); scanCrossFiveChained(); scanLineFourChained(); scanLineThreeChained(); #endregion // Call Destroy Chained Unit method if there are chained Units if (!_noChainedUnit) { StartCoroutine(destroyChainedUnits()); // Update game info texts _turnPointText.text = (_turnPoint.ToString()); _unitCounterText.text = (_unitCounter.ToString()); _unitTypeCounter = puzzleGen._unitPrefabsContainer.Length - _unitTypeCheckContainer.Count; _unitTypeCounterText.text = (_unitTypeCounter.ToString()); } else { // Update total score if there are no more chained units //StartCoroutine(updateScore()); //iTween.Stop(gameObject); iTween.ValueTo(gameObject, iTween.Hash("from", _score, "to", _score + (_turnPoint * _unitTypeCounter), "time", 0.6, "onUpdate", "updateScore", "ignoretimescale", true)); _score += (_turnPoint * _unitTypeCounter); GameStateController.currentState = GameStateController.gameState.idle; // End game if out of turns if (puzzleGen._turns < 1) { StartCoroutine(gameStateController.endGame()); } } }
// Mark chained Units then call destroy Units method public void markChainedUnits() { GameStateController.currentState = GameStateController.gameState.destroyingUnit; // Create a puzzle value matrix to scan for chained units bool noChainedUnit = true; for (int YIndex = 0; YIndex < puzzleGen._rows; YIndex++) { for (int XIndex = 0; XIndex < puzzleGen._columns; XIndex++) { scanUnitARR[XIndex, YIndex] = new ScanUnit(puzzleGen._unitARR[XIndex, YIndex].GetComponent<UnitInfo>()._value); } } #region Scan and Mark chained Units for (int YIndex = 0; YIndex < puzzleGen._rows; YIndex++) { for (int XIndex = 0; XIndex < puzzleGen._columns; XIndex++) { if (isBlockNineChained(XIndex, YIndex)) { scanUnitARR[XIndex - 1, YIndex - 1]._isChained = true; scanUnitARR[XIndex, YIndex - 1]._isChained = true; scanUnitARR[XIndex + 1, YIndex - 1]._isChained = true; scanUnitARR[XIndex - 1, YIndex]._isChained = true; scanUnitARR[XIndex, YIndex]._isChained = true; scanUnitARR[XIndex + 1, YIndex]._isChained = true; scanUnitARR[XIndex - 1, YIndex + 1]._isChained = true; scanUnitARR[XIndex, YIndex + 1]._isChained = true; scanUnitARR[XIndex + 1, YIndex + 1]._isChained = true; print("Block9 chained at" + XIndex + " : " + YIndex + "value :" + scanUnitARR[XIndex, YIndex]._value); noChainedUnit = false; _unitCounter += 9; if (_unitTypeCheckContainer.Contains(scanUnitARR[XIndex, YIndex]._value)) { _unitTypeCheckContainer.Remove(scanUnitARR[XIndex, YIndex]._value); } } } } for (int YIndex = 0; YIndex < puzzleGen._rows; YIndex++) { for (int XIndex = 0; XIndex < puzzleGen._columns; XIndex++) { if (isHorizontalTreeChained(XIndex, YIndex)) { scanUnitARR[XIndex - 1, YIndex]._isChained = true; scanUnitARR[XIndex, YIndex]._isChained = true; scanUnitARR[XIndex + 1, YIndex]._isChained = true; print("Horizontal3 chained at" + XIndex + " : " + YIndex + "value :" + scanUnitARR[XIndex, YIndex]._value); noChainedUnit = false; _unitCounter += 3; if (_unitTypeCheckContainer.Contains(scanUnitARR[XIndex, YIndex]._value)) { _unitTypeCheckContainer.Remove(scanUnitARR[XIndex, YIndex]._value); } } } } for (int YIndex = 0; YIndex < puzzleGen._rows; YIndex++) { for (int XIndex = 0; XIndex < puzzleGen._columns; XIndex++) { if (isVerticalTreeChained(XIndex, YIndex)) { scanUnitARR[XIndex, YIndex - 1]._isChained = true; scanUnitARR[XIndex, YIndex]._isChained = true; scanUnitARR[XIndex, YIndex + 1]._isChained = true; print("Vertical3 chained at" + XIndex + " : " + YIndex + "value :" + scanUnitARR[XIndex, YIndex]._value); noChainedUnit = false; _unitCounter += 3; if (_unitTypeCheckContainer.Contains(scanUnitARR[XIndex, YIndex]._value)) { _unitTypeCheckContainer.Remove(scanUnitARR[XIndex, YIndex]._value); } } } } #endregion // Call Destroy Chained Unit method if there are chained Units if (!noChainedUnit) { StartCoroutine(destroyChainedUnits()); _unitCounterText.text = (_unitCounter.ToString()); _unitTypeCounter = puzzleGen._unitPrefabsContainer.Count - _unitTypeCheckContainer.Count; _unitTypeCounterText.text = (_unitTypeCounter.ToString()); } else { StartCoroutine(updateScore()); GameStateController.currentState = GameStateController.gameState.idle; } }
// Mark chained Units then call destroy Units method public void markChainedUnits() { GameStateController.currentState = GameStateController.gameState.destroyingUnit; // Create a puzzle value matrix to scan for chained units bool noChainedUnit = true; for (int YIndex = 0; YIndex < puzzleGen._rows; YIndex++) { for (int XIndex = 0; XIndex < puzzleGen._columns; XIndex++) { scanUnitARR[XIndex, YIndex] = new ScanUnit(puzzleGen._unitARR[XIndex, YIndex].GetComponent <UnitInfo>()._value); } } #region Scan and Mark chained Units for (int YIndex = 0; YIndex < puzzleGen._rows; YIndex++) { for (int XIndex = 0; XIndex < puzzleGen._columns; XIndex++) { if (isBlockNineChained(XIndex, YIndex)) { scanUnitARR[XIndex - 1, YIndex - 1]._isChained = true; scanUnitARR[XIndex, YIndex - 1]._isChained = true; scanUnitARR[XIndex + 1, YIndex - 1]._isChained = true; scanUnitARR[XIndex - 1, YIndex]._isChained = true; scanUnitARR[XIndex, YIndex]._isChained = true; scanUnitARR[XIndex + 1, YIndex]._isChained = true; scanUnitARR[XIndex - 1, YIndex + 1]._isChained = true; scanUnitARR[XIndex, YIndex + 1]._isChained = true; scanUnitARR[XIndex + 1, YIndex + 1]._isChained = true; print("Block9 chained at" + XIndex + " : " + YIndex + "value :" + scanUnitARR[XIndex, YIndex]._value); noChainedUnit = false; _unitCounter += 9; if (_unitTypeCheckContainer.Contains(scanUnitARR[XIndex, YIndex]._value)) { _unitTypeCheckContainer.Remove(scanUnitARR[XIndex, YIndex]._value); } } } } for (int YIndex = 0; YIndex < puzzleGen._rows; YIndex++) { for (int XIndex = 0; XIndex < puzzleGen._columns; XIndex++) { if (isHorizontalTreeChained(XIndex, YIndex)) { scanUnitARR[XIndex - 1, YIndex]._isChained = true; scanUnitARR[XIndex, YIndex]._isChained = true; scanUnitARR[XIndex + 1, YIndex]._isChained = true; print("Horizontal3 chained at" + XIndex + " : " + YIndex + "value :" + scanUnitARR[XIndex, YIndex]._value); noChainedUnit = false; _unitCounter += 3; if (_unitTypeCheckContainer.Contains(scanUnitARR[XIndex, YIndex]._value)) { _unitTypeCheckContainer.Remove(scanUnitARR[XIndex, YIndex]._value); } } } } for (int YIndex = 0; YIndex < puzzleGen._rows; YIndex++) { for (int XIndex = 0; XIndex < puzzleGen._columns; XIndex++) { if (isVerticalTreeChained(XIndex, YIndex)) { scanUnitARR[XIndex, YIndex - 1]._isChained = true; scanUnitARR[XIndex, YIndex]._isChained = true; scanUnitARR[XIndex, YIndex + 1]._isChained = true; print("Vertical3 chained at" + XIndex + " : " + YIndex + "value :" + scanUnitARR[XIndex, YIndex]._value); noChainedUnit = false; _unitCounter += 3; if (_unitTypeCheckContainer.Contains(scanUnitARR[XIndex, YIndex]._value)) { _unitTypeCheckContainer.Remove(scanUnitARR[XIndex, YIndex]._value); } } } } #endregion // Call Destroy Chained Unit method if there are chained Units if (!noChainedUnit) { StartCoroutine(destroyChainedUnits()); _unitCounterText.text = (_unitCounter.ToString()); _unitTypeCounter = puzzleGen._unitPrefabsContainer.Count - _unitTypeCheckContainer.Count; _unitTypeCounterText.text = (_unitTypeCounter.ToString()); } else { StartCoroutine(updateScore()); GameStateController.currentState = GameStateController.gameState.idle; } }