Add Audio
This commit is contained in:
@@ -21,6 +21,7 @@ namespace Services {
|
||||
private readonly GameVariables gameVariables;
|
||||
private readonly IMatchService matchService;
|
||||
private readonly IScoreService scoreService;
|
||||
private readonly AudioPresenter audioPresenter;
|
||||
private readonly IBombService bombService;
|
||||
private readonly IObjectPool<GemView> objectPool;
|
||||
private readonly Transform gemsHolder;
|
||||
@@ -32,7 +33,7 @@ namespace Services {
|
||||
private GameState currentState = GameState.Move;
|
||||
#endregion
|
||||
|
||||
public GameBoardService(IGameBoard gameBoard, GameVariables gameVariables, IMatchService matchService, IScoreService scoreSerivce, IBombService bombService, IObjectPool<GemView> objectPool, Transform gemsHolder, ScorePresenter scorePresenter) {
|
||||
public GameBoardService(IGameBoard gameBoard, GameVariables gameVariables, IMatchService matchService, IScoreService scoreSerivce, IBombService bombService, IObjectPool<GemView> objectPool, Transform gemsHolder, ScorePresenter scorePresenter, AudioPresenter audioPresenter) {
|
||||
this.gameBoard = gameBoard;
|
||||
this.gameVariables = gameVariables;
|
||||
this.matchService = matchService;
|
||||
@@ -41,6 +42,7 @@ namespace Services {
|
||||
this.objectPool = objectPool;
|
||||
this.gemsHolder = gemsHolder;
|
||||
this.scorePresenter = scorePresenter;
|
||||
this.audioPresenter = audioPresenter;
|
||||
}
|
||||
|
||||
public void Tick() {
|
||||
@@ -224,6 +226,19 @@ namespace Services {
|
||||
return;
|
||||
}
|
||||
|
||||
bool willBreakAnyNonBombGem = false;
|
||||
foreach (Vector2Int pos in matchPositions) {
|
||||
Gem gem = GetGem(pos);
|
||||
if (gem == null) continue;
|
||||
if (gem.Type == GemType.Bomb) continue;
|
||||
|
||||
willBreakAnyNonBombGem = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (willBreakAnyNonBombGem)
|
||||
this.audioPresenter.OnMatch(this.gameVariables.matchSfx);
|
||||
|
||||
foreach (Vector2Int pos in matchPositions.Distinct().ToList()) {
|
||||
Gem gem = GetGem(pos);
|
||||
if (gem == null) continue;
|
||||
@@ -248,6 +263,9 @@ namespace Services {
|
||||
Gem gem = GetGem(pos);
|
||||
if (gem == null)
|
||||
return UniTask.CompletedTask;
|
||||
|
||||
if (gem.Type == GemType.Bomb)
|
||||
this.audioPresenter.OnBombExplosion(this.gameVariables.bombExplodeSfx);
|
||||
|
||||
this.scoreService.ScoreCheck(gem.ScoreValue);
|
||||
DestroyMatchedGems(pos);
|
||||
|
||||
Reference in New Issue
Block a user