game-logic shitgame
This commit is contained in:
parent
9db87c633f
commit
9517559fe5
|
|
@ -23,13 +23,13 @@ namespace KoogleApp.Games
|
|||
// NextThrowState is used to store the state for the next throw, that is modified by game logic or a user interaction. It overrides the default behaviour of resetting pins etc.
|
||||
public ThrowPanelState? NextThrowState { get; set; } = NextThrowState;
|
||||
|
||||
public SelectedNextPlayerIds NextPlayer(Func<ParticipantsState, ParticipantsMode, int[]> getNextPlayer)
|
||||
public SelectedNextPlayerIdsAction? NextPlayer(Func<ParticipantsState, ParticipantsMode, int[]> getNextPlayer)
|
||||
{
|
||||
var newPlayersList = getNextPlayer(AfterParticipantsState, StartParams.ParticipantsMode);
|
||||
|
||||
AfterParticipantsState = AfterParticipantsState with { PlayerIds = newPlayersList };
|
||||
|
||||
return new SelectedNextPlayerIds(AfterParticipantsState);
|
||||
return new SelectedNextPlayerIdsAction(AfterParticipantsState);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,9 +11,15 @@
|
|||
<MudNumericField @bind-Value="_shitNumber" Label="Scheiss-Zahl" HelperText="Bei welcher Zahl verliehrt man?" Min="1" Max="9"/>
|
||||
</MudItem>
|
||||
|
||||
<MudItem>
|
||||
<MudNumericField @bind-Value="_startNumber" Label="Start-Zahl" HelperText="Von wie hoch soll runter gespielt werden?" Min="10" Max="1000" />
|
||||
</MudItem>
|
||||
|
||||
@code {
|
||||
int _shitNumber = 5;
|
||||
|
||||
int _startNumber = 50;
|
||||
|
||||
public IGameSetupModel GameSetupModel =>
|
||||
new ShitSetupState()
|
||||
{
|
||||
|
|
@ -23,7 +29,8 @@
|
|||
|
||||
} with
|
||||
{
|
||||
ShitNumber = _shitNumber
|
||||
ShitNumber = _shitNumber,
|
||||
StartNumber = _startNumber
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ namespace KoogleApp.Games.Shit
|
|||
//public string PlayerName { get; set; }
|
||||
}
|
||||
|
||||
|
||||
[FeatureState]
|
||||
public record ShitGameState(
|
||||
Dictionary<int, PointStatus> Points,
|
||||
int CollectedPoints,
|
||||
|
|
@ -92,6 +92,8 @@ namespace KoogleApp.Games.Shit
|
|||
public record ShitSetupState: GameSetupModelBase
|
||||
{
|
||||
public int ShitNumber { get; set; } = 5;
|
||||
|
||||
public int StartNumber { get; set; } = 50;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ namespace KoogleApp.Games.Shit
|
|||
|
||||
public GameProgress HandleThrow(GameProgress progress, IDispatcher dispatcher)
|
||||
{
|
||||
var actions = new List<object>();
|
||||
if (progress.GameModel is not ShitGameModel)
|
||||
{
|
||||
throw new InvalidOperationException("game service does not match game model");
|
||||
|
|
@ -26,21 +27,21 @@ namespace KoogleApp.Games.Shit
|
|||
var isShit = progress.PinCount() == ((ShitSetupState)progress.StartParams).ShitNumber;
|
||||
if (isShit)
|
||||
{
|
||||
// status.Points += GameModel.CollectedPoints;
|
||||
gameModel.Points[playerId].Points += gameModel.CollectedPoints;
|
||||
gameModel.CollectedPoints = 0;
|
||||
|
||||
SelectPlayerAndUpdateGameModel(progress, actions, gameModel);
|
||||
}
|
||||
else
|
||||
{
|
||||
gameModel.CollectedPoints += pinCount;
|
||||
gameModel.PreviewPointsOk -= Math.Max(pinCount, 0);
|
||||
gameModel.PreviewPointsShit += pinCount;
|
||||
}
|
||||
|
||||
gameModel.PreviewPointsOk -= pinCount;
|
||||
gameModel.PreviewPointsShit += pinCount;
|
||||
|
||||
//if (GameModel.PreviewPointsOk <= 0)
|
||||
//{
|
||||
// EndOfGame();
|
||||
if (gameModel.PreviewPointsOk <= 0)
|
||||
{
|
||||
EndOfGame();
|
||||
|
||||
//GameModel.Points.ForEach(_ => {
|
||||
// if (_.PlayerId.Equals(CurrentPlayer.Id))
|
||||
|
|
@ -55,31 +56,48 @@ namespace KoogleApp.Games.Shit
|
|||
// ExpenseTriggers = new[] { ExpenseTrigger.ExpensePoint }
|
||||
// });
|
||||
//});
|
||||
//}
|
||||
}
|
||||
|
||||
foreach (var action in actions)
|
||||
{
|
||||
dispatcher.Dispatch(action);
|
||||
}
|
||||
|
||||
return progress;
|
||||
}
|
||||
|
||||
private static void SelectPlayerAndUpdateGameModel(GameProgress progress, List<object> actions, ShitGameModel gameModel)
|
||||
{
|
||||
var nextPlayerAction = NextPlayer(progress, actions);
|
||||
if (nextPlayerAction != null)
|
||||
{
|
||||
UpdateGameModelForSelectedPlayer(gameModel, nextPlayerAction.ParticipantsState.PlayerIds.First());
|
||||
}
|
||||
}
|
||||
|
||||
private static void UpdateGameModelForSelectedPlayer(ShitGameModel gameModel, int playerId)
|
||||
{
|
||||
gameModel.PreviewPointsOk = gameModel.Points[playerId].Points;
|
||||
gameModel.PreviewPointsShit = gameModel.Points[playerId].Points;
|
||||
gameModel.CollectedPoints = 0;
|
||||
}
|
||||
|
||||
public IGameModel InitGameModel(IGameSetupModel startParams, IDispatcher dispatcher)
|
||||
{
|
||||
var dict = new Dictionary<int, PointStatus>();
|
||||
var startModel = startParams as ShitSetupState;
|
||||
|
||||
foreach (var participant in startParams.Participants)
|
||||
{
|
||||
var tm = new PointStatus() with { PlayerId = participant };
|
||||
var tm = new PointStatus() with { PlayerId = participant, Points = startModel.StartNumber };
|
||||
dict.Add(participant, tm);
|
||||
}
|
||||
|
||||
var newModel = new ShitGameModel(dict,0,0,0);
|
||||
var newModel = new ShitGameModel(dict,0, startModel.StartNumber, startModel.StartNumber);
|
||||
|
||||
return newModel;
|
||||
}
|
||||
|
||||
private void NextPlayerClick()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public IGameModel FinalizeGameModel()
|
||||
{
|
||||
return null;
|
||||
|
|
@ -89,16 +107,29 @@ namespace KoogleApp.Games.Shit
|
|||
{
|
||||
var actions = new List<object>();
|
||||
|
||||
|
||||
if (progress.AfterThrowState.ThrowCounterPerRound < 4) // three throws are at least required
|
||||
{
|
||||
return progress;
|
||||
}
|
||||
|
||||
|
||||
//var playerId = progress.GetCurrentPlayerId();
|
||||
// erreichte Punkte mitnehmen
|
||||
var playerId = progress.GetCurrentPlayerId();
|
||||
var gameModel = progress.GameModel as ShitGameModel;
|
||||
gameModel.Points[playerId].Points -= gameModel.CollectedPoints;
|
||||
|
||||
|
||||
SelectPlayerAndUpdateGameModel(progress, actions, gameModel);
|
||||
|
||||
foreach (var action in actions)
|
||||
{
|
||||
dispatcher.Dispatch(action);
|
||||
}
|
||||
|
||||
return progress;
|
||||
}
|
||||
|
||||
private static SelectedNextPlayerIdsAction? NextPlayer(GameProgress progress, List<object> actions)
|
||||
{
|
||||
// neue Runde starten: nächster Spieler und ThrowCounterPerRound zurücksetzen
|
||||
var nextPlayerAction = progress.NextPlayer(NextPlayerHandler.GetNextPlayerIndex);
|
||||
if (nextPlayerAction != null)
|
||||
|
|
@ -110,14 +141,7 @@ namespace KoogleApp.Games.Shit
|
|||
0, 0, progress.BeforeThrowState.ThrowMode, ThrowPanelStateStatus.BeforeThrow, progress.AfterThrowState.ThrowCounter, progress.BeforeThrowState.DayId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
foreach (var action in actions)
|
||||
{
|
||||
dispatcher.Dispatch(action);
|
||||
}
|
||||
|
||||
return progress;
|
||||
return nextPlayerAction;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ namespace KoogleApp.Games.Training
|
|||
//afterParticipantsState = progress.AfterParticipantsState with { PlayerIds = newPlayersList };
|
||||
//progress.AfterParticipantsState = afterParticipantsState;
|
||||
|
||||
//actions.Add(new SelectedNextPlayerIds(afterParticipantsState));
|
||||
//actions.Add(new SelectedNextPlayerIdsAction(afterParticipantsState));
|
||||
}
|
||||
|
||||
var playerId = progress.GetCurrentPlayerId();
|
||||
|
|
|
|||
|
|
@ -19,6 +19,6 @@ namespace KoogleApp.Store.Game.Participants
|
|||
|
||||
public record SelectedPlayerChangedAction(ParticipantsState ParticipantsState, int NewId);
|
||||
|
||||
public record SelectedNextPlayerIds(ParticipantsState ParticipantsState);
|
||||
public record SelectedNextPlayerIdsAction(ParticipantsState ParticipantsState);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ namespace KoogleApp.Store.Game.Participants
|
|||
}
|
||||
|
||||
[ReducerMethod]
|
||||
public static ParticipantsState OnSelectedNextPlayerIds(ParticipantsState state, SelectedNextPlayerIds action)
|
||||
public static ParticipantsState OnSelectedNextPlayerIds(ParticipantsState state, SelectedNextPlayerIdsAction action)
|
||||
{
|
||||
return action.ParticipantsState;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -186,9 +186,9 @@ namespace KoogleApp.Store.Game.ThrowPanel
|
|||
|
||||
//foreach (var action in actions)
|
||||
//{
|
||||
// if (action is SelectedNextPlayerIds)
|
||||
// if (action is SelectedNextPlayerIdsAction)
|
||||
// {
|
||||
// participants = ((SelectedNextPlayerIds)action).ParticipantsState;
|
||||
// participants = ((SelectedNextPlayerIdsAction)action).ParticipantsState;
|
||||
// }
|
||||
// dispatcher.Dispatch(action);
|
||||
//}
|
||||
|
|
|
|||
|
|
@ -1,19 +0,0 @@
|
|||
{
|
||||
"IsStated": true,
|
||||
"BellValue": false,
|
||||
"Pin1State": 1,
|
||||
"Pin2State": 1,
|
||||
"Pin3State": 1,
|
||||
"Pin4State": 1,
|
||||
"Pin5State": 1,
|
||||
"Pin6State": 1,
|
||||
"Pin7State": 1,
|
||||
"Pin8State": 1,
|
||||
"Pin9State": 1,
|
||||
"ThrowsPerRound": 2,
|
||||
"ThrowCounterPerRound": 1,
|
||||
"ThrowMode": 0,
|
||||
"ThrowPanelStateStatus": 2,
|
||||
"ThrowCounter": 6,
|
||||
"DayId": 35
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue