// Use this for initialization private void Start() { int i, j; GameObject tileObject = Resources.Load("InGame/Tile", typeof(GameObject)) as GameObject; for (i = 0; i < MAX_ROW_COUNT; i++) { for (j = 0; j < MAX_COL_COUNT; j++) { GameObject tileObjectClone = (GameObject)Instantiate(tileObject); tileObjectClone.name = "Tile(" + i + "," + j + ")"; TileScript tileScript = tileObjectClone.GetComponent <TileScript>(); tileScript.Init(i, j, new TileStatus()); mTiles[i, j] = tileScript; } } BlownUpStatus[,] blownUpStatusTemp = new BlownUpStatus[MAX_ROW_COUNT, MAX_COL_COUNT]; BlownUpStatus.Construct(blownUpStatusTemp); while (CheckBlowUpTiles(blownUpStatusTemp)) { for (i = 0; i < MAX_ROW_COUNT; i++) { for (j = 0; j < MAX_COL_COUNT; j++) { mTiles[i, j].SetTile(new TileStatus()); } } } mClickedTile = null; mIsSwapEnable = false; mIsReSwapNeeded = false; mIsEnemyActionDone = false; mIsBlownThisTurn = false; mTurn = 0; mBlownTileCount = 0; mBaseMP = 0; InGameUIManager.Instance.UpdateHP(UserManager.Instance.HP); InGameUIManager.Instance.UpdateMP(UserManager.Instance.MP); InGameUIManager.Instance.UpdateTurn(mTurn); }
private bool BlowUpTiles() { int i, j; BlownUpStatus[,] blownUpStatus = new BlownUpStatus[MAX_ROW_COUNT, MAX_COL_COUNT]; BlownUpStatus.Construct(blownUpStatus); mCheckToDestroyed = new bool[MAX_ROW_COUNT, MAX_COL_COUNT]; mTilesDestroyed = new bool[MAX_ROW_COUNT, MAX_COL_COUNT]; if (!CheckBlowUpTiles(blownUpStatus)) { return(false); } // delete for (i = 0; i < MAX_ROW_COUNT; i++) { for (j = 0; j < MAX_COL_COUNT; j++) { // add if (!mCheckToDestroyed[i, j] && blownUpStatus[i, j].IsBlownUp()) { mCheckToDestroyed[i, j] = true; if (blownUpStatus[i, j].mShape == BlownUpStatus.EffectShape.NONE) { mTiles[i, j].Status.CountToDestroy--; if (mTiles[i, j].Status.CountToDestroy <= 0) { //Tile Destroyed :: give exp, money and special effects mTilesDestroyed[i, j] = true; } } else { int[] notDestroyedTilePath = SearchSameShape(blownUpStatus, i, j); if (notDestroyedTilePath[0] != -1 && notDestroyedTilePath[1] != -1) { TileStatus nowStatus = mTiles[notDestroyedTilePath[0], notDestroyedTilePath[1]].Status; TileTypeManager.TileType madeSpecialType = TileTypeManager.TileType.NORMAL; mTilesDestroyed[notDestroyedTilePath[0], notDestroyedTilePath[1]] = false; mBlownTileCount++; if (blownUpStatus[i, j].mShape == BlownUpStatus.EffectShape.FOUR) { madeSpecialType = TileTypeManager.TileType.HEAL; } else if (blownUpStatus[i, j].mShape == BlownUpStatus.EffectShape.L) { madeSpecialType = TileTypeManager.TileType.CROSS; } else if (blownUpStatus[i, j].mShape == BlownUpStatus.EffectShape.FIVE) { madeSpecialType = TileTypeManager.TileType.SPECIAL; } mTiles[notDestroyedTilePath[0], notDestroyedTilePath[1]].SetTile(new TileStatus(madeSpecialType, nowStatus.Color)); } } } } } //Cross & heal & sepcial Effect. bool[,] isAlreadyBomb = new bool[MAX_ROW_COUNT, MAX_COL_COUNT]; bool isStop = false; while (!isStop) { isStop = true; for (i = 0; i < MAX_ROW_COUNT; i++) { for (j = 0; j < MAX_COL_COUNT; j++) { if (!isAlreadyBomb[i, j] && mTilesDestroyed[i, j]) { isAlreadyBomb[i, j] = true; if (mTiles[i, j].mStatus.Type == TileTypeManager.TileType.HEAL) { // Add Heal. UserManager.Instance.decreaseHP(-3); InGameUIManager.Instance.UpdateHP(UserManager.Instance.HP); } else if (mTiles[i, j].mStatus.Type == TileTypeManager.TileType.CROSS) { int k; for (k = 0; k < MAX_COL_COUNT; k++) { if (mTiles[i, k].IsBlowable) { mTilesDestroyed[i, k] = true; } } for (k = 0; k < MAX_ROW_COUNT; k++) { if (mTiles[k, j].IsBlowable) { mTilesDestroyed[k, j] = true; } } } else if (mTiles[i, j].mStatus.Type == TileTypeManager.TileType.SPECIAL) { // Special Effect. } isStop = false; } } } } //Real delete int row; for (j = 0; j < MAX_COL_COUNT; j++) { Queue <int> q = new Queue <int>(); for (i = MAX_ROW_COUNT - 1; i >= 0; i--) { if (mTilesDestroyed[i, j]) { q.Enqueue(i); mBlownTileCount++; } else { if (q.Count > 0) { row = q.Dequeue(); mTiles[row, j].IsBlowable = false; mTiles[row, j].SetPosition(mTiles[i, j].gameObject.transform.localPosition); mTiles[row, j].SetTile(mTiles[i, j].Status); StartCoroutine(InGameAnimationManager.Instance.TileMoveToOriginalPositionStart(mTiles[row, j])); q.Enqueue(i); } } } while (q.Count > 0) { row = q.Dequeue(); mTiles[row, j].IsBlowable = false; Vector3 topTilePosition = TileScript.GetTileVectorWithRowCol(0, j); if (q.Count + 1 < MAX_ROW_COUNT) { Vector3 lastFellingTilePosition = mTiles[q.Count + 1, j].gameObject.transform.localPosition; if (lastFellingTilePosition.y <= topTilePosition.y) { mTiles[row, j].SetPosition(new Vector3(topTilePosition.x, topTilePosition.y + TileScript.tileSize, 0)); } else { mTiles[row, j].SetPosition(new Vector3(lastFellingTilePosition.x, lastFellingTilePosition.y + TileScript.tileSize, 0)); } } else { mTiles[row, j].SetPosition(new Vector3(topTilePosition.x, topTilePosition.y + TileScript.tileSize, 0)); } mTiles[row, j].SetTile(new TileStatus()); StartCoroutine(InGameAnimationManager.Instance.TileMoveToOriginalPositionStart(mTiles[row, j])); } } UserManager.Instance.setMP(mBaseMP + MP_INCREASING_CONSTANT * mBlownTileCount); InGameUIManager.Instance.UpdateMP(UserManager.Instance.MP); return(true); }