Mostly finished implementation of the new deck? ALso added some tests

This commit is contained in:
Kwoth
2022-07-21 06:55:15 +02:00
parent 9a21ba3d53
commit c8c0b27d6a
10 changed files with 167 additions and 37 deletions

View File

@@ -0,0 +1,51 @@
namespace Nadeko.Econ;
public abstract class NewDeck<TCard, TSuit, TValue>
where TCard: NewCard<TSuit, TValue>
where TSuit : struct, Enum
where TValue : struct, Enum
{
public virtual int CurrentCount
=> _cards.Count;
public virtual int TotalCount { get; }
private 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)!);
}
}
}
public virtual TCard? Draw()
{
var first = _cards.First;
if (first is not null)
{
_cards.RemoveFirst();
return first.Value;
}
return null;
}
public virtual void Shuffle()
{
var cards = _cards.ToList();
cards.Shuffle();
_cards.Clear();
foreach (var card in cards)
_cards.AddFirst(card);
}
}