oecs-sharp/Game.Blackjack/Systems/PlayerBustCheckSystem.cs

25 lines
677 B
C#
Raw Normal View History

2026-07-18 23:26:56 +08:00
using OECS;
namespace Game.Blackjack;
2026-07-18 23:26:56 +08:00
/// <summary>
/// Evaluates the player's hand total after each hit.
/// Busts the player if they exceed 21.
/// </summary>
public class PlayerBustCheckSystem : ISystem
{
public void RunImpl(World world)
2026-07-18 23:26:56 +08:00
{
var state = world.ReadSingleton<GameState>();
if (state.Phase != GamePhase.PlayerTurn)
return;
var total = HandUtil.CalculateHand(world, PlayerHandTag.Instance);
if (total <= 21)
return;
ref var mutableState = ref world.GetSingleton<GameState>();
mutableState.Phase = GamePhase.RoundOver;
mutableState.Result = RoundResult.PlayerBust;
}
}