/// <summary> /// Function called to start the game. /// </summary> public void StartGame() { panelMenu.SetActive(false); panelGameOver.SetActive(false); score = 0; scoreText.text = "SCORE: " + score.ToString(); spawner.enabled = true; spawner.Spawn(); }
private IEnumerator CheckMatch3() { HashSet <Block>[] matchingBlocks = new HashSet <Block> [4]; for (int i = 0; i < 4; i++) { Block block = Blocks[i]; matchingBlocks[i] = new HashSet <Block>() { block }; if (block.BlockDef.BlockType == BlockType.Bomb) { block.GetSurroundingNeighbors(matchingBlocks[i], 2f); } else { block.GetMatchingNeighbors(matchingBlocks[i]); } } for (int i = 0; i < 4; i++) { var matchSet = matchingBlocks[i]; for (int j = i + 1; j < 4; j++) { if (matchingBlocks[j].Any(x => matchSet.Contains(x))) { foreach (var item in matchingBlocks[j]) { matchSet.Add(item); } matchingBlocks[j].Clear(); } } } for (int i = 0; i < 4; i++) { var matchSet = matchingBlocks[i]; if (matchSet.Count >= 3) { foreach (var block in matchSet) { block.SetToBeDestroyed(); } } } yield return(new WaitForSeconds(0.4f)); for (int i = 0; i < 4; i++) { var matchSet = matchingBlocks[i]; if (matchSet.Count >= 3) { if (matchSet.Any(x => x.BlockDef.BlockType == BlockType.Explosive)) { SoundPlayer.Play(ExplosiveSound); var pointsDisplay = Instantiate(PointsDisplayPrefab, Blocks[i].transform.position, Quaternion.identity); int points = ScoreManager.AddPoints(-matchSet.Count(x => x.BlockDef.BlockType == BlockType.Coin)); Health.RemoveHealth(points); pointsDisplay.SetPointsText(points); } else if (matchSet.Any(x => x.BlockDef.BlockType == BlockType.Bomb)) { SoundPlayer.Play(BombSound); } else if (matchSet.Any(x => x.BlockDef.BlockType == BlockType.Coin)) { SoundPlayer.Play(CoinSound); var pointsDisplay = Instantiate(PointsDisplayPrefab, Blocks[i].transform.position, Quaternion.identity); int points = ScoreManager.AddPoints(matchSet.Count); Health.AddHealth(points); pointsDisplay.SetPointsText(points); } else { SoundPlayer.Play(MatchedSound); } foreach (var block in matchSet) { block.gameObject.transform.SetParent(null); Destroy(block.gameObject); } } } //Board.Instance.MakeBlocksFall(); ScoreManager.AddTetromino(); if (ScoreManager.TetrominoCount % 15 == 0) { ScoreManager.AddLevel(); FallDelay *= 0.6f; } TetrominoSpawner.Spawn(); Destroy(gameObject); }
public static Tetromino Spawn() { return(_instance.Spawn(_instance.transform.position)); }