Implement Bombs

This commit is contained in:
2025-12-15 02:34:59 +08:00
parent 95b43ed772
commit abff76e4ab
36 changed files with 512 additions and 753 deletions

View File

@@ -89,12 +89,61 @@ namespace Services {
CheckForBombs();
}
public void CheckForBombs() {
throw new System.NotImplementedException();
private void CheckForBombs() {
Gem[,] gems = this.gameBoard.GemsGrid;
int width = this.gameBoard.Width;
int height = this.gameBoard.Height;
for (int i = 0; i < this.currentMatches.Count; i++)
{
Gem gem = this.currentMatches[i];
int x = gem.Position.x;
int y = gem.Position.y;
Vector2Int[] directions =
{
Vector2Int.left,
Vector2Int.right,
Vector2Int.down,
Vector2Int.up
};
foreach (Vector2Int direction in directions)
{
int newX = x + direction.x;
int newY = y + direction.y;
if (newX < 0 || newX >= width || newY < 0 || newY >= height)
continue;
Gem neighbor = gems[newX, newY];
if (neighbor?.Type == GemType.Bomb)
MarkBombArea(new Vector2Int(newX, newY), 1);
}
}
}
public void MarkBombArea(Vector2Int bombPosition, int blastSize) {
throw new System.NotImplementedException();
Gem[,] gems = this.gameBoard.GemsGrid;
int width = this.gameBoard.Width;
int height = this.gameBoard.Height;
for (int x = bombPosition.x - blastSize; x <= bombPosition.x + blastSize; x++)
{
for (int y = bombPosition.y - blastSize; y <= bombPosition.y + blastSize; y++)
{
if (x >= 0 && x < width && y >= 0 && y < height)
{
if (gems[x, y] != null)
{
gems[x, y].isMatch = true;
this.currentMatches.Add(gems[x, y]);
}
}
}
}
this.currentMatches = this.currentMatches.Distinct().ToList();
}
}
}