Added MultipleDeck which can be used in place of the old QuadDeck, converted cards from classes to records as it is useful to have default equality checks.

This commit is contained in:
Kwoth
2022-07-23 07:43:18 +02:00
parent ccf92ca702
commit 967784c860
6 changed files with 62 additions and 46 deletions

View File

@@ -5,26 +5,18 @@ public abstract class NewDeck<TCard, TSuit, TValue>
where TSuit : struct, Enum
where TValue : struct, Enum
{
protected static readonly TSuit[] _suits = Enum.GetValues<TSuit>();
protected static readonly TValue[] _values = Enum.GetValues<TValue>();
public virtual int CurrentCount
=> _cards.Count;
public virtual int TotalCount { get; }
private readonly LinkedList<TCard> _cards = new();
protected readonly LinkedList<TCard> _cards = new();
public NewDeck()
{
var suits = Enum.GetValues<TSuit>();
var values = Enum.GetValues<TValue>();
TotalCount = suits.Length * values.Length;
foreach (var suit in suits)
{
foreach (var val in values)
{
_cards.AddLast((TCard)Activator.CreateInstance(typeof(TCard), suit, val)!);
}
}
TotalCount = _suits.Length * _values.Length;
}
public virtual TCard? Draw()