get next player

This commit is contained in:
beo3000 2025-11-22 17:21:09 +01:00
parent b48ad5da73
commit a45b663fda
10 changed files with 97 additions and 17 deletions

View File

@ -44,8 +44,8 @@
case GameView.Throw:
<PanelToolbar>
@* @DayState.Value *@
@* @GetParticipantsState()
@GetSetupState(); *@
@GetParticipantsState()
@* @GetSetupState(); *@
@if (DayState.Value.Status != DayStatus.Started)
{

View File

@ -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;
}
}
}

View File

@ -7,6 +7,6 @@ namespace KoogleApp.Games
{
public IKnownGame Game { get; }
public IEnumerable<object> HandleThrow(GameLogicAction action);
public IEnumerable<object> HandleThrow(GameProgress progress);
}
}

View File

@ -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);
}
}
}
}

View File

@ -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<object> HandleThrow(GameLogicAction action)
public IEnumerable<object> HandleThrow(GameProgress progress)
{
return Array.Empty<object>();
var res = new List<object>();
if (progress.IsNextRound())
{
var nextId = NextPlayerHandler.GetNextPlayerIndex(progress.AfterParticipantsState, progress.SetupState.ParticipantsMode);
if (nextId != null)
{
res.Add(new ChangePlayerAction(nextId.Value));
}
}
return res;
}
}
}

View File

@ -20,6 +20,6 @@ namespace KoogleApp.Store.Game.Participants
public record SelectedPlayerChangedAction(ParticipantsState ParticipantsState, int NewId);
public record ChangePlayerAction(int NextPlayerId);
}

View File

@ -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()
};
}
}
}

View File

@ -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();

View File

@ -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);
}
}

View File

@ -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"
}
],