public bool GemsMatch(Gem gem1, Gem gem2, out BackToBackCount gem1Count, out BackToBackCount gem2Count) { gem1Count = backToBackCountOnIndex(gem1.GetIndex(), gem1.gemTypeSO.GemColor); gem2Count = backToBackCountOnIndex(gem2.GetIndex(), gem2.gemTypeSO.GemColor); //Debug.Log("CountG1H: " + gem1Count.horizontalGems.Count + " V: " + gem1Count.verticalGems.Count); //Debug.Log("CountG2H: " + gem2Count.horizontalGems.Count + " V: " + gem2Count.verticalGems.Count); return(gem1Count.HasEnoughToMatch() || gem2Count.HasEnoughToMatch()); }
void FixInitialBoard() { for (int x = 0, y = 0; x < boardNumCells.x; x++, y = 0) { for (; y < boardNumCells.y; y++) { Gem currentGem = gemsTable[x, y]; BackToBackCount cellCount = backToBackCountOnIndex(currentGem.GetIndex(), currentGem.gemTypeSO.GemColor); if (cellCount.HasEnoughToMatch()) { int currentIndex = 0; GemColor[] neighboursColours = new GemColor[4]; if (x != boardNumCells.x - 1) { Vector2Int newIndex = currentGem.GetIndex() + Vector2Int.right; neighboursColours[currentIndex++] = gemsTable[newIndex.x, newIndex.y].gemTypeSO.GemColor; } if (x != 0) { Vector2Int newIndex = currentGem.GetIndex() + Vector2Int.left; neighboursColours[currentIndex++] = gemsTable[newIndex.x, newIndex.y].gemTypeSO.GemColor; } if (y != boardNumCells.y - 1) { Vector2Int newIndex = currentGem.GetIndex() + Vector2Int.up; neighboursColours[currentIndex++] = gemsTable[newIndex.x, newIndex.y].gemTypeSO.GemColor; } if (y != 0) { Vector2Int newIndex = currentGem.GetIndex() + Vector2Int.down; neighboursColours[currentIndex++] = gemsTable[newIndex.x, newIndex.y].gemTypeSO.GemColor; } GemColor gemColor = GemColor.Blue; while (Array.Exists(neighboursColours, color => color == gemColor)) { gemColor++; } currentGem.SetType(gemsInfo.Info[(int)gemColor - 1]); } } } }
public void RecheckBoard() { bool exploded = false; for (int x = 0; x < boardNumCells.x; x++) { for (int y = 0; y < boardNumCells.y; y++) { BackToBackCount count = backToBackCountOnIndex(new Vector2Int(x, y), gemsTable[x, y].gemTypeSO.GemColor); if (count.HasEnoughToMatch()) { ExplodeGems(count); exploded = true; } } } if (exploded) { DropGems(); } }