KoogleApp/KoogleApp/Games/GameProgress.cs

146 lines
5.8 KiB
C#

using KoogleApp.Games.Training;
using KoogleApp.Store.Game.Participants;
using KoogleApp.Store.Game.ThrowPanel;
namespace KoogleApp.Games
{
public class GameProgress(
ThrowPanelState? BeforeThrowState,
ParticipantsState? BeforeParticipantsState,
ThrowPanelState AfterThrowState,
ParticipantsState AfterParticipantsState,
IGameSetupModel StartParams,
IGameModel GameModel,
ThrowPanelState? NextThrowState)
{
public ThrowPanelState? BeforeThrowState { get; set; } = BeforeThrowState;
public ThrowPanelState? AfterThrowState { get; set; } = AfterThrowState;
public ParticipantsState? BeforeParticipantsState { get; set; } = BeforeParticipantsState;
public IGameModel GameModel { get; set; } = GameModel;
public ParticipantsState AfterParticipantsState { get; set; } = AfterParticipantsState;
public IGameSetupModel StartParams { get; set; } = StartParams;
// 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 SelectedNextPlayerIdsAction? NextPlayer(Func<ParticipantsState, ParticipantsMode, int[]> getNextPlayer)
{
var newPlayersList = getNextPlayer(AfterParticipantsState, StartParams.ParticipantsMode);
AfterParticipantsState = AfterParticipantsState with { PlayerIds = newPlayersList };
return new SelectedNextPlayerIdsAction(AfterParticipantsState);
}
}
public static class GameProgressExtension
{
public static int GetCurrentPlayerId(this GameProgress progress)
{
return progress.BeforeParticipantsState.PlayerIds.First();
}
public static bool IsNextRound(this GameProgress progress)
{
if (progress.AfterThrowState.ThrowCounterPerRound + 1 > progress.NextThrowState.ThrowsPerRound)
{
return true;
}
return false;
}
public static bool NextRound(this GameProgress progress)
{
var res = progress.IsNextRound();
if (res)
{
}
return res;
}
public static bool IsCircle(this GameProgress progress)
{
var res = 0;
var possible = progress.BeforeThrowState.Pin5State == PinStatus.Standing && progress.AfterThrowState.Pin5State == PinStatus.Standing;
if (progress.BeforeThrowState.Pin1State == PinStatus.Standing && progress.AfterThrowState.Pin1State == PinStatus.Fallen)
{
res++;
}
if (progress.BeforeThrowState.Pin2State == PinStatus.Standing && progress.AfterThrowState.Pin2State == PinStatus.Fallen)
{
res++;
}
if (progress.BeforeThrowState.Pin3State == PinStatus.Standing && progress.AfterThrowState.Pin3State == PinStatus.Fallen)
{
res++;
}
if (progress.BeforeThrowState.Pin4State == PinStatus.Standing && progress.AfterThrowState.Pin4State == PinStatus.Fallen)
{
res++;
}
if (progress.BeforeThrowState.Pin6State == PinStatus.Standing && progress.AfterThrowState.Pin6State == PinStatus.Fallen)
{
res++;
}
if (progress.BeforeThrowState.Pin7State == PinStatus.Standing && progress.AfterThrowState.Pin7State == PinStatus.Fallen)
{
res++;
}
if (progress.BeforeThrowState.Pin8State == PinStatus.Standing && progress.AfterThrowState.Pin8State == PinStatus.Fallen)
{
res++;
}
if (progress.BeforeThrowState.Pin9State == PinStatus.Standing && progress.AfterThrowState.Pin9State == PinStatus.Fallen)
{
res++;
}
return res == 8 && possible;
}
public static int PinCount(this GameProgress progress)
{
var res = 0;
if (progress.BeforeThrowState.Pin1State == PinStatus.Standing && progress.AfterThrowState.Pin1State == PinStatus.Fallen)
{
res++;
}
if (progress.BeforeThrowState.Pin2State == PinStatus.Standing && progress.AfterThrowState.Pin2State == PinStatus.Fallen)
{
res++;
}
if (progress.BeforeThrowState.Pin3State == PinStatus.Standing && progress.AfterThrowState.Pin3State == PinStatus.Fallen)
{
res++;
}
if (progress.BeforeThrowState.Pin4State == PinStatus.Standing && progress.AfterThrowState.Pin4State == PinStatus.Fallen)
{
res++;
}
if (progress.BeforeThrowState.Pin5State == PinStatus.Standing && progress.AfterThrowState.Pin5State == PinStatus.Fallen)
{
res++;
}
if (progress.BeforeThrowState.Pin6State == PinStatus.Standing && progress.AfterThrowState.Pin6State == PinStatus.Fallen)
{
res++;
}
if (progress.BeforeThrowState.Pin7State == PinStatus.Standing && progress.AfterThrowState.Pin7State == PinStatus.Fallen)
{
res++;
}
if (progress.BeforeThrowState.Pin8State == PinStatus.Standing && progress.AfterThrowState.Pin8State == PinStatus.Fallen)
{
res++;
}
if (progress.BeforeThrowState.Pin9State == PinStatus.Standing && progress.AfterThrowState.Pin9State == PinStatus.Fallen)
{
res++;
}
return res;
}
}
}