diff --git a/KoogleApp/Components/Pages/Game.razor b/KoogleApp/Components/Pages/Game.razor index 3528da0..57fed56 100644 --- a/KoogleApp/Components/Pages/Game.razor +++ b/KoogleApp/Components/Pages/Game.razor @@ -44,8 +44,8 @@ case GameView.Throw: @* @DayState.Value *@ -@* @GetParticipantsState() - @GetSetupState(); *@ + @GetParticipantsState() + @* @GetSetupState(); *@ @if (DayState.Value.Status != DayStatus.Started) { diff --git a/KoogleApp/Games/GameProgressExtension.cs b/KoogleApp/Games/GameProgressExtension.cs new file mode 100644 index 0000000..e0f439c --- /dev/null +++ b/KoogleApp/Games/GameProgressExtension.cs @@ -0,0 +1,16 @@ +using KoogleApp.Store.Game.ThrowPanel; + +namespace KoogleApp.Games +{ + public static class GameProgressExtension + { + public static bool IsNextRound(this GameProgress progress) + { + if (progress.BeforeThrowState.ThrowCounter + 1 >= progress.AfterThrowState.ThrowsPerRound) + { + return true; + } + return false; + } + } +} diff --git a/KoogleApp/Games/IGameService.cs b/KoogleApp/Games/IGameService.cs index 9d5bd03..c98be41 100644 --- a/KoogleApp/Games/IGameService.cs +++ b/KoogleApp/Games/IGameService.cs @@ -7,6 +7,6 @@ namespace KoogleApp.Games { public IKnownGame Game { get; } - public IEnumerable HandleThrow(GameLogicAction action); + public IEnumerable HandleThrow(GameProgress progress); } } diff --git a/KoogleApp/Games/NextPlayerHandler.cs b/KoogleApp/Games/NextPlayerHandler.cs new file mode 100644 index 0000000..9b8d1cb --- /dev/null +++ b/KoogleApp/Games/NextPlayerHandler.cs @@ -0,0 +1,30 @@ +using KoogleApp.Store.Game.Participants; +using KoogleApp.Store.Game.ThrowPanel; +using Microsoft.IdentityModel.Abstractions; + +namespace KoogleApp.Games +{ + public static class NextPlayerHandler + { + public static int? GetNextPlayerIndex(ParticipantsState players, ParticipantsMode participantsMode) + { + switch (participantsMode) + { + case ParticipantsMode.GameLogic: + if (players.PlayerIds.Length > 1) + { + return players.PlayerIds[1]; + } + return players.PlayerIds[0]; + case ParticipantsMode.FreeToChoose: + return null; + case ParticipantsMode.Random: + var random = new Random(); + var randomIndex = random.Next(players.PlayerIds.Length); + return players.PlayerIds[randomIndex]; + default: + throw new ArgumentOutOfRangeException(nameof(participantsMode), participantsMode, null); + } + } + } +} diff --git a/KoogleApp/Games/Training/GameTrainingService.cs b/KoogleApp/Games/Training/GameTrainingService.cs index d9cd245..81fb50d 100644 --- a/KoogleApp/Games/Training/GameTrainingService.cs +++ b/KoogleApp/Games/Training/GameTrainingService.cs @@ -1,4 +1,5 @@ -using KoogleApp.Store.Game.ThrowPanel; +using KoogleApp.Store.Game.Participants; +using KoogleApp.Store.Game.ThrowPanel; namespace KoogleApp.Games.Training { @@ -6,9 +7,20 @@ namespace KoogleApp.Games.Training { public IKnownGame Game => new GameTraining(); - public IEnumerable HandleThrow(GameLogicAction action) + public IEnumerable HandleThrow(GameProgress progress) { - return Array.Empty(); + var res = new List(); + + if (progress.IsNextRound()) + { + var nextId = NextPlayerHandler.GetNextPlayerIndex(progress.AfterParticipantsState, progress.SetupState.ParticipantsMode); + if (nextId != null) + { + res.Add(new ChangePlayerAction(nextId.Value)); + } + } + + return res; } } } diff --git a/KoogleApp/Store/Game/Participants/Actions.cs b/KoogleApp/Store/Game/Participants/Actions.cs index 8a1514b..c613e24 100644 --- a/KoogleApp/Store/Game/Participants/Actions.cs +++ b/KoogleApp/Store/Game/Participants/Actions.cs @@ -20,6 +20,6 @@ namespace KoogleApp.Store.Game.Participants public record SelectedPlayerChangedAction(ParticipantsState ParticipantsState, int NewId); - + public record ChangePlayerAction(int NextPlayerId); } diff --git a/KoogleApp/Store/Game/Participants/Reducers.cs b/KoogleApp/Store/Game/Participants/Reducers.cs index 1065cdf..0a6f8d0 100644 --- a/KoogleApp/Store/Game/Participants/Reducers.cs +++ b/KoogleApp/Store/Game/Participants/Reducers.cs @@ -7,8 +7,7 @@ namespace KoogleApp.Store.Game.Participants public static class ParticipantsStateReducer { [ReducerMethod] - public static ParticipantsState OnSetThrowsPerRoundAction(ParticipantsState state, - SetParticipatingPlayersAction action) + public static ParticipantsState OnSetParticipatingPlayersAction(ParticipantsState state, SetParticipatingPlayersAction action) { return state with { @@ -17,7 +16,7 @@ namespace KoogleApp.Store.Game.Participants } [ReducerMethod] - public static ParticipantsState OnParticipantsState(ParticipantsState state, ParticipantsStateChangedAction action) + public static ParticipantsState OnParticipantsStateChangedAction(ParticipantsState state, ParticipantsStateChangedAction action) { return action.ParticipantsState; } @@ -41,5 +40,22 @@ namespace KoogleApp.Store.Game.Participants { return action.ParticipantsState; } + + [ReducerMethod] + public static ParticipantsState OnChangePlayerAction(ParticipantsState state, ChangePlayerAction action) + { + var lst = state.PlayerIds.ToList(); + var first = lst.First(); + lst.Remove(action.NextPlayerId); + lst.Remove(first); + lst.Insert(0,action.NextPlayerId); + lst.Add(first); + return state with + { + PlayerIds = lst.ToArray() + }; + } + + } } \ No newline at end of file diff --git a/KoogleApp/Store/Game/ThrowPanel/Actions.cs b/KoogleApp/Store/Game/ThrowPanel/Actions.cs index b63380f..e252a3a 100644 --- a/KoogleApp/Store/Game/ThrowPanel/Actions.cs +++ b/KoogleApp/Store/Game/ThrowPanel/Actions.cs @@ -41,7 +41,9 @@ namespace KoogleApp.Store.Game.ThrowPanel public record EnsureBeforeThrowStatusAction(ParticipantsState ParticipantsState); - public record GameLogicAction(ThrowPanelState? BeforeThrowState, ParticipantsState? BeforeParticipantsState, ThrowPanelState AfterThrowState, ParticipantsState AfterParticipantsState); + public record GameProgress(ThrowPanelState? BeforeThrowState, ParticipantsState? BeforeParticipantsState, + ThrowPanelState AfterThrowState, ParticipantsState AfterParticipantsState, + SetupState SetupState); public record DeleteThrowPanelSessionAction(); diff --git a/KoogleApp/Store/Game/ThrowPanel/Effects.cs b/KoogleApp/Store/Game/ThrowPanel/Effects.cs index a145eac..c01f547 100644 --- a/KoogleApp/Store/Game/ThrowPanel/Effects.cs +++ b/KoogleApp/Store/Game/ThrowPanel/Effects.cs @@ -126,15 +126,19 @@ namespace KoogleApp.Store.Game.ThrowPanel var afterState = throwPanelState.Value; - var gameLogic = new GameLogicAction(beforeStates.Status?.ThrowPanelState, - beforeStates.Status?.ParticipantsState, afterState, throwAction.ParticipantsState); + var progress = new GameProgress(beforeStates.Status?.ThrowPanelState, + beforeStates.Status?.ParticipantsState, afterState, throwAction.ParticipantsState, _setupState.Value); - dispatcher.Dispatch(gameLogic); // currently unused + dispatcher.Dispatch(progress); // currently unused var gameService = gameServiceFactory.GetService(_setupState.Value.Game); if (gameService != null) { - var actions = gameService.HandleThrow(gameLogic); + var actions = gameService.HandleThrow(progress); + foreach (var action in actions) + { + dispatcher.Dispatch(action); + } } diff --git a/KoogleApp/appdata.json b/KoogleApp/appdata.json index 5e42c6b..21a80d7 100644 --- a/KoogleApp/appdata.json +++ b/KoogleApp/appdata.json @@ -27,14 +27,14 @@ } }, "Version": 2, - "LastModified": "2025-11-22T15:36:50.809194+01:00", + "LastModified": "2025-11-22T17:12:18.0301054+01:00", "LastModifiedBy": "test1@test.de" }, "UndoHistory": [ { "Status": null, "Version": 1, - "LastModified": "2025-11-22T15:36:50.8053396+01:00", + "LastModified": "2025-11-22T17:12:18.025238+01:00", "LastModifiedBy": "system" } ],