Cleanup GameBOardService
This commit is contained in:
@@ -21,10 +21,6 @@ namespace Services
|
||||
|
||||
private BombSpawnRequest? pendingBombSpawn;
|
||||
public BombSpawnRequest? PendingBombSpawn => this.pendingBombSpawn;
|
||||
|
||||
public void ClearPendingBombs() {
|
||||
this.pendingBombSpawn = null;
|
||||
}
|
||||
|
||||
public BombService(GameVariables gameVariables, IGameBoard gameBoard) {
|
||||
this.gameVariables = gameVariables;
|
||||
@@ -34,6 +30,38 @@ namespace Services
|
||||
public void SetLastSwap(Vector2Int from, Vector2Int to) {
|
||||
this.lastSwapFrom = from;
|
||||
this.lastSwapTo = to;
|
||||
|
||||
ClearPendingBombs();
|
||||
}
|
||||
|
||||
public UniTask<List<Vector2Int>> GetInitialBombs(List<Vector2Int> protectedPositions, List<Vector2Int> bombCandidates) {
|
||||
List<Vector2Int> initialBombs = new List<Vector2Int>();
|
||||
foreach (Vector2Int p in bombCandidates) {
|
||||
if (!GemUtils.IsInBounds(p, this.gameBoard)) continue;
|
||||
|
||||
if (protectedPositions != null && protectedPositions.Contains(p))
|
||||
continue;
|
||||
|
||||
Gem gem = this.gameBoard.GetGemAt(p);
|
||||
if (gem is { Type: GemType.Bomb })
|
||||
initialBombs.Add(p);
|
||||
}
|
||||
|
||||
return UniTask.FromResult(initialBombs.Distinct().ToList());
|
||||
}
|
||||
|
||||
public List<Vector2Int> ApplyPendingBombSpawns(Action<Vector2Int, GemType, bool> spawnGem) {
|
||||
List<Vector2Int> positions = new List<Vector2Int>();
|
||||
BombSpawnRequest? bombSpawnRequest = PendingBombSpawn;
|
||||
|
||||
if (bombSpawnRequest != null) {
|
||||
BombSpawnRequest bombRequest = PendingBombSpawn.GetValueOrDefault();
|
||||
positions.Add(bombRequest.Position);
|
||||
spawnGem(bombRequest.Position, bombRequest.Color, true);
|
||||
}
|
||||
|
||||
ClearPendingBombs();
|
||||
return positions;
|
||||
}
|
||||
|
||||
public void DetectBombSpawnFromLastSwap(List<Gem> currentMatches) {
|
||||
@@ -201,5 +229,9 @@ namespace Services
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
public void ClearPendingBombs() {
|
||||
this.pendingBombSpawn = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user