From 6045de0c7d77b017277e19a701573386ee391cbb Mon Sep 17 00:00:00 2001 From: Vinzenz Schroeter Date: Sun, 21 Apr 2024 19:34:22 +0200 Subject: [PATCH] fix destroyed walls count too high --- tanks-backend/TanksServer/GameLogic/CollideBullets.cs | 5 +---- tanks-backend/TanksServer/GameLogic/MapService.cs | 8 +++++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/tanks-backend/TanksServer/GameLogic/CollideBullets.cs b/tanks-backend/TanksServer/GameLogic/CollideBullets.cs index b045bb6..1ec17cf 100644 --- a/tanks-backend/TanksServer/GameLogic/CollideBullets.cs +++ b/tanks-backend/TanksServer/GameLogic/CollideBullets.cs @@ -76,11 +76,8 @@ internal sealed class CollideBullets( for (var y = pixel.Y - i; y <= pixel.Y + i; y++) { var offsetPixel = new PixelPosition(x, y); - if (options.Value.DestructibleWalls) - { - map.Current.DestroyWallAt(offsetPixel); + if (options.Value.DestructibleWalls && map.Current.TryDestroyWallAt(offsetPixel)) owner.Scores.WallsDestroyed++; - } TryHitTankAt(offsetPixel.ToFloatPosition(), owner); } diff --git a/tanks-backend/TanksServer/GameLogic/MapService.cs b/tanks-backend/TanksServer/GameLogic/MapService.cs index ecfb252..82b0344 100644 --- a/tanks-backend/TanksServer/GameLogic/MapService.cs +++ b/tanks-backend/TanksServer/GameLogic/MapService.cs @@ -104,5 +104,11 @@ internal sealed class Map(string name, bool[,] walls) return false; } - public void DestroyWallAt(PixelPosition pixel) => walls[pixel.X, pixel.Y] = false; + public bool TryDestroyWallAt(PixelPosition pixel) + { + var result = walls[pixel.X, pixel.Y]; + if (result) + walls[pixel.X, pixel.Y] = false; + return result; + } }