25 lines
677 B
C#
25 lines
677 B
C#
using OECS;
|
|
|
|
namespace Game.Blackjack;
|
|
|
|
/// <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)
|
|
{
|
|
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;
|
|
}
|
|
} |