From 061ba4dbdbde5879154b127051d54875184a6393 Mon Sep 17 00:00:00 2001 From: beo3000 Date: Sat, 27 Dec 2025 14:01:32 +0100 Subject: [PATCH] fix decrease mode --- .../Components/Game/GameInputPanel.razor | 26 ++++++++++++++----- src/Koogle.Web/Store/GameState/GameState.cs | 21 +++++++++++++++ 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/Koogle.Web/Components/Game/GameInputPanel.razor b/src/Koogle.Web/Components/Game/GameInputPanel.razor index 2a2271e..2da2214 100644 --- a/src/Koogle.Web/Components/Game/GameInputPanel.razor +++ b/src/Koogle.Web/Components/Game/GameInputPanel.razor @@ -171,6 +171,13 @@ private void HandlePinClick(int pinNumber) { var currentStatus = GetPinStatus(pinNumber); + + // In Decrease mode, fallen pins cannot be reset to standing + if (GameState.Value.ThrowPanel.ThrowMode == ThrowMode.Decrease && currentStatus == PinStatus.Fallen) + { + return; + } + var newStatus = currentStatus == PinStatus.Standing ? PinStatus.Fallen : PinStatus.Standing; Dispatcher.Dispatch(new SetPinStatusAction(pinNumber, newStatus)); @@ -246,18 +253,25 @@ if (newThrowPanel.ThrowCounterPerRound >= newThrowPanel.ThrowsPerRound) { newThrowPanel = newThrowPanel with { ThrowCounterPerRound = 0 }; - - // Reset pins if in Reposition mode - if (newThrowPanel.ThrowMode == ThrowMode.Reposition) - { - newThrowPanel = newThrowPanel.ResetPins(); - } + // Reset all pins at end of round (both modes) + newThrowPanel = newThrowPanel.ResetPins(); } else if (newThrowPanel.ThrowMode == ThrowMode.Reposition) { // In Reposition mode, always reset pins after each throw newThrowPanel = newThrowPanel.ResetPins(); } + else if (newThrowPanel.ThrowMode == ThrowMode.Decrease) + { + // In Decrease mode: Mark fallen pins as disabled (not available for next throw) + newThrowPanel = newThrowPanel.MarkFallenAsDisabled(); + + // If all pins are down, reset all pins for a fresh set + if (newThrowPanel.AllPinsDown()) + { + newThrowPanel = newThrowPanel.ResetPins(); + } + } // Dispatch record throw action Dispatcher.Dispatch(new RecordThrowAction(newThrowPanel, GameState.Value.GameModel)); diff --git a/src/Koogle.Web/Store/GameState/GameState.cs b/src/Koogle.Web/Store/GameState/GameState.cs index a2312c0..3b20b07 100644 --- a/src/Koogle.Web/Store/GameState/GameState.cs +++ b/src/Koogle.Web/Store/GameState/GameState.cs @@ -257,6 +257,27 @@ public record ThrowPanelState 9 => this with { Pin9 = status }, _ => this }; + + /// + /// Marks all fallen pins as disabled (for Decrease mode). + /// + public ThrowPanelState MarkFallenAsDisabled() => this with + { + Pin1 = Pin1 == PinStatus.Fallen ? PinStatus.Disabled : Pin1, + Pin2 = Pin2 == PinStatus.Fallen ? PinStatus.Disabled : Pin2, + Pin3 = Pin3 == PinStatus.Fallen ? PinStatus.Disabled : Pin3, + Pin4 = Pin4 == PinStatus.Fallen ? PinStatus.Disabled : Pin4, + Pin5 = Pin5 == PinStatus.Fallen ? PinStatus.Disabled : Pin5, + Pin6 = Pin6 == PinStatus.Fallen ? PinStatus.Disabled : Pin6, + Pin7 = Pin7 == PinStatus.Fallen ? PinStatus.Disabled : Pin7, + Pin8 = Pin8 == PinStatus.Fallen ? PinStatus.Disabled : Pin8, + Pin9 = Pin9 == PinStatus.Fallen ? PinStatus.Disabled : Pin9 + }; + + /// + /// Checks if all pins are knocked down (fallen or disabled). + /// + public bool AllPinsDown() => GetPins().All(p => p != PinStatus.Standing); } ///