26 lines
730 B
C#
26 lines
730 B
C#
|
|
using OECS;
|
||
|
|
|
||
|
|
namespace 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 Run(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;
|
||
|
|
world.MarkModified<GameState>(World.SingletonEntity);
|
||
|
|
}
|
||
|
|
}
|