mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2026-01-27 15:27:06 -08:00
Reorganise classes
This commit is contained in:
47
71_Poker/csharp/Players/Player.cs
Normal file
47
71_Poker/csharp/Players/Player.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using Poker.Cards;
|
||||
|
||||
namespace Poker.Players;
|
||||
|
||||
internal abstract class Player
|
||||
{
|
||||
private Table? _table;
|
||||
private bool _hasFolded;
|
||||
|
||||
protected Player(int bank)
|
||||
{
|
||||
Hand = Hand.Empty;
|
||||
Balance = bank;
|
||||
}
|
||||
|
||||
public Hand Hand { get; set; }
|
||||
public int Balance { get; set; }
|
||||
public int Bet { get; private set; }
|
||||
public bool HasFolded => _hasFolded;
|
||||
|
||||
protected Table Table =>
|
||||
_table ?? throw new InvalidOperationException("The player must be sitting at the table.");
|
||||
|
||||
public void Sit(Table table) => _table = table;
|
||||
|
||||
public virtual void NewHand(Hand hand)
|
||||
{
|
||||
Hand = hand;
|
||||
_hasFolded = false;
|
||||
}
|
||||
|
||||
public void Pay(int amount)
|
||||
{
|
||||
Balance -= amount;
|
||||
}
|
||||
|
||||
public virtual void TakeWinnings()
|
||||
{
|
||||
Balance += Table.Pot;
|
||||
Table.Pot = 0;
|
||||
}
|
||||
|
||||
public void Fold()
|
||||
{
|
||||
_hasFolded = true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user