added christmasTree additional End Option:
ChristmasTreeGameSetup.cs
- Neues Enum GameEndCondition mit AllFivesGone (Standard) und TreeCleared
- Property EndCondition zum Setup hinzugefügt
ChristmasTreeGameModel.cs
- Property EndCondition hinzugefügt
ChristmasTreeGameLogicService.cs
- Neue Methode CheckGameEndCondition() prüft je nach Einstellung
- Neue Methode CheckAnyTreeCleared() prüft ob ein Team alle Zahlen gestrichen hat
- Alle 3 Stellen wo Spielende geprüft wird nutzen jetzt die flexible Methode
ChristmasTreeSetup.razor
- Neues Dropdown "Spielende" mit zwei Optionen:
- "Alle 5er gestrichen" (Standard)
- "Ein Baum komplett leer"
- Hilfstexte erklären die jeweilige Bedingung
This commit is contained in:
parent
56f3e63046
commit
65c18f4f51
|
|
@ -38,6 +38,7 @@ public class ChristmasTreeGameLogicService : IGameLogicService
|
||||||
return new ChristmasTreeGameModel
|
return new ChristmasTreeGameModel
|
||||||
{
|
{
|
||||||
Variant = options.Variant,
|
Variant = options.Variant,
|
||||||
|
EndCondition = options.EndCondition,
|
||||||
TeamTrees = teamTrees,
|
TeamTrees = teamTrees,
|
||||||
Teams = options.Teams.ToList(),
|
Teams = options.Teams.ToList(),
|
||||||
CurrentTeamIndex = 0,
|
CurrentTeamIndex = 0,
|
||||||
|
|
@ -123,8 +124,8 @@ public class ChristmasTreeGameLogicService : IGameLogicService
|
||||||
CrossedOutCount = teamTrees[playerTeamIndex].CrossedOutCount + 1
|
CrossedOutCount = teamTrees[playerTeamIndex].CrossedOutCount + 1
|
||||||
};
|
};
|
||||||
|
|
||||||
// Check if game ended (last 5 crossed)
|
// Check if game ended
|
||||||
bool gameEnded = CheckAllFivesGone(teamTrees);
|
bool gameEnded = CheckGameEndCondition(teamTrees, model.EndCondition);
|
||||||
if (gameEnded)
|
if (gameEnded)
|
||||||
{
|
{
|
||||||
lastThrow = lastThrow with { TriggeredGameEnd = true };
|
lastThrow = lastThrow with { TriggeredGameEnd = true };
|
||||||
|
|
@ -154,7 +155,7 @@ public class ChristmasTreeGameLogicService : IGameLogicService
|
||||||
};
|
};
|
||||||
|
|
||||||
// Check if game ended
|
// Check if game ended
|
||||||
bool gameEnded = CheckAllFivesGone(teamTrees);
|
bool gameEnded = CheckGameEndCondition(teamTrees, model.EndCondition);
|
||||||
if (gameEnded)
|
if (gameEnded)
|
||||||
{
|
{
|
||||||
lastThrow = lastThrow with { TriggeredGameEnd = true };
|
lastThrow = lastThrow with { TriggeredGameEnd = true };
|
||||||
|
|
@ -557,7 +558,7 @@ public class ChristmasTreeGameLogicService : IGameLogicService
|
||||||
};
|
};
|
||||||
|
|
||||||
// Check for game end
|
// Check for game end
|
||||||
bool gameEnded = CheckAllFivesGone(teamTrees);
|
bool gameEnded = CheckGameEndCondition(teamTrees, model.EndCondition);
|
||||||
var triggers = new List<TriggerEvent>();
|
var triggers = new List<TriggerEvent>();
|
||||||
|
|
||||||
if (gameEnded)
|
if (gameEnded)
|
||||||
|
|
@ -735,6 +736,18 @@ public class ChristmasTreeGameLogicService : IGameLogicService
|
||||||
return crossedTeams;
|
return crossedTeams;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool CheckGameEndCondition(
|
||||||
|
Dictionary<int, TeamTreeState> teamTrees,
|
||||||
|
GameEndCondition endCondition)
|
||||||
|
{
|
||||||
|
return endCondition switch
|
||||||
|
{
|
||||||
|
GameEndCondition.AllFivesGone => CheckAllFivesGone(teamTrees),
|
||||||
|
GameEndCondition.TreeCleared => CheckAnyTreeCleared(teamTrees),
|
||||||
|
_ => CheckAllFivesGone(teamTrees)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private static bool CheckAllFivesGone(Dictionary<int, TeamTreeState> teamTrees)
|
private static bool CheckAllFivesGone(Dictionary<int, TeamTreeState> teamTrees)
|
||||||
{
|
{
|
||||||
foreach (var state in teamTrees.Values)
|
foreach (var state in teamTrees.Values)
|
||||||
|
|
@ -747,6 +760,18 @@ public class ChristmasTreeGameLogicService : IGameLogicService
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool CheckAnyTreeCleared(Dictionary<int, TeamTreeState> teamTrees)
|
||||||
|
{
|
||||||
|
foreach (var state in teamTrees.Values)
|
||||||
|
{
|
||||||
|
if (state.RemainingNumbers.Values.Sum() == 0)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private static ChristmasTreeGameSetup ParseSetupOptions(object? setupOptions)
|
private static ChristmasTreeGameSetup ParseSetupOptions(object? setupOptions)
|
||||||
{
|
{
|
||||||
if (setupOptions is null)
|
if (setupOptions is null)
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,11 @@ public record ChristmasTreeGameModel : IGameModel
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public TreeVariant Variant { get; init; }
|
public TreeVariant Variant { get; init; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The game end condition.
|
||||||
|
/// </summary>
|
||||||
|
public GameEndCondition EndCondition { get; init; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tree state for each team. Key = team index (0-based).
|
/// Tree state for each team. Key = team index (0-based).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,22 @@ using Koogle.Domain.Enums;
|
||||||
|
|
||||||
namespace Koogle.Application.Games.ChristmasTree;
|
namespace Koogle.Application.Games.ChristmasTree;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Game end condition for the Christmas Tree game.
|
||||||
|
/// </summary>
|
||||||
|
public enum GameEndCondition
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Game ends when all 5s are crossed out from all trees.
|
||||||
|
/// </summary>
|
||||||
|
AllFivesGone,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Game ends when any team has cleared their entire tree.
|
||||||
|
/// </summary>
|
||||||
|
TreeCleared
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tree variant for the Christmas Tree game.
|
/// Tree variant for the Christmas Tree game.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -47,6 +63,11 @@ public record ChristmasTreeGameSetup : GameSetupModelBase
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int MaxContinueThrows { get; init; } = 3;
|
public int MaxContinueThrows { get; init; } = 3;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Condition that triggers game end.
|
||||||
|
/// </summary>
|
||||||
|
public GameEndCondition EndCondition { get; init; } = GameEndCondition.AllFivesGone;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new setup with default values.
|
/// Creates a new setup with default values.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -56,6 +77,7 @@ public record ChristmasTreeGameSetup : GameSetupModelBase
|
||||||
TreeVariant variant = TreeVariant.Beginner,
|
TreeVariant variant = TreeVariant.Beginner,
|
||||||
bool enableContinueOnMiss = false,
|
bool enableContinueOnMiss = false,
|
||||||
int maxContinueThrows = 3,
|
int maxContinueThrows = 3,
|
||||||
|
GameEndCondition endCondition = GameEndCondition.AllFivesGone,
|
||||||
IReadOnlyList<GameTeam>? teams = null) => new()
|
IReadOnlyList<GameTeam>? teams = null) => new()
|
||||||
{
|
{
|
||||||
ThrowMode = throwMode,
|
ThrowMode = throwMode,
|
||||||
|
|
@ -64,6 +86,7 @@ public record ChristmasTreeGameSetup : GameSetupModelBase
|
||||||
Variant = variant,
|
Variant = variant,
|
||||||
EnableContinueOnMiss = enableContinueOnMiss,
|
EnableContinueOnMiss = enableContinueOnMiss,
|
||||||
MaxContinueThrows = maxContinueThrows,
|
MaxContinueThrows = maxContinueThrows,
|
||||||
|
EndCondition = endCondition,
|
||||||
Teams = teams
|
Teams = teams
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,15 @@
|
||||||
<MudSelectItem Value="TreeVariant.LargePyramid">Große Pyramide</MudSelectItem>
|
<MudSelectItem Value="TreeVariant.LargePyramid">Große Pyramide</MudSelectItem>
|
||||||
</MudSelect>
|
</MudSelect>
|
||||||
|
|
||||||
|
<MudSelect T="GameEndCondition"
|
||||||
|
@bind-Value="_options.EndCondition"
|
||||||
|
Label="Spielende"
|
||||||
|
Variant="Variant.Outlined"
|
||||||
|
HelperText="@GetEndConditionDescription(_options.EndCondition)">
|
||||||
|
<MudSelectItem Value="GameEndCondition.AllFivesGone">Alle 5er gestrichen</MudSelectItem>
|
||||||
|
<MudSelectItem Value="GameEndCondition.TreeCleared">Ein Baum komplett leer</MudSelectItem>
|
||||||
|
</MudSelect>
|
||||||
|
|
||||||
<MudSwitch T="bool"
|
<MudSwitch T="bool"
|
||||||
@bind-Value="_options.EnableContinueOnMiss"
|
@bind-Value="_options.EnableContinueOnMiss"
|
||||||
Label="Weiterkegeln bei Fehlwurf"
|
Label="Weiterkegeln bei Fehlwurf"
|
||||||
|
|
@ -103,7 +112,8 @@
|
||||||
{
|
{
|
||||||
Variant = setup.Variant,
|
Variant = setup.Variant,
|
||||||
EnableContinueOnMiss = setup.EnableContinueOnMiss,
|
EnableContinueOnMiss = setup.EnableContinueOnMiss,
|
||||||
MaxContinueThrows = setup.MaxContinueThrows
|
MaxContinueThrows = setup.MaxContinueThrows,
|
||||||
|
EndCondition = setup.EndCondition
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -131,6 +141,13 @@
|
||||||
_ => ""
|
_ => ""
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private string GetEndConditionDescription(GameEndCondition condition) => condition switch
|
||||||
|
{
|
||||||
|
GameEndCondition.AllFivesGone => "Spiel endet, wenn alle 5er bei allen Teams gestrichen sind",
|
||||||
|
GameEndCondition.TreeCleared => "Spiel endet, wenn ein Team alle Zahlen gestrichen hat",
|
||||||
|
_ => ""
|
||||||
|
};
|
||||||
|
|
||||||
public IGameSetupModel GameSetupModel => new ChristmasTreeGameSetup
|
public IGameSetupModel GameSetupModel => new ChristmasTreeGameSetup
|
||||||
{
|
{
|
||||||
ThrowMode = ThrowMode.Reposition,
|
ThrowMode = ThrowMode.Reposition,
|
||||||
|
|
@ -139,6 +156,7 @@
|
||||||
Variant = _options.Variant,
|
Variant = _options.Variant,
|
||||||
EnableContinueOnMiss = _options.EnableContinueOnMiss,
|
EnableContinueOnMiss = _options.EnableContinueOnMiss,
|
||||||
MaxContinueThrows = _options.MaxContinueThrows,
|
MaxContinueThrows = _options.MaxContinueThrows,
|
||||||
|
EndCondition = _options.EndCondition,
|
||||||
Teams = Teams
|
Teams = Teams
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -147,5 +165,6 @@
|
||||||
public TreeVariant Variant { get; set; } = TreeVariant.Beginner;
|
public TreeVariant Variant { get; set; } = TreeVariant.Beginner;
|
||||||
public bool EnableContinueOnMiss { get; set; } = false;
|
public bool EnableContinueOnMiss { get; set; } = false;
|
||||||
public int MaxContinueThrows { get; set; } = 3;
|
public int MaxContinueThrows { get; set; } = 3;
|
||||||
|
public GameEndCondition EndCondition { get; set; } = GameEndCondition.AllFivesGone;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue