mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 01:38:27 -04:00
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:
@@ -0,0 +1,28 @@
|
||||
namespace Nadeko.Econ;
|
||||
|
||||
public class MultipleRegularDeck : NewDeck<RegularCard, RegularSuit, RegularValue>
|
||||
{
|
||||
private int Decks { get; }
|
||||
|
||||
public override int TotalCount { get; }
|
||||
|
||||
public MultipleRegularDeck(int decks = 1)
|
||||
{
|
||||
if (decks < 1)
|
||||
throw new ArgumentOutOfRangeException(nameof(decks), "Has to be more than 0");
|
||||
|
||||
Decks = decks;
|
||||
TotalCount = base.TotalCount * decks;
|
||||
|
||||
for (var i = 0; i < Decks; i++)
|
||||
{
|
||||
foreach (var suit in _suits)
|
||||
{
|
||||
foreach (var val in _values)
|
||||
{
|
||||
_cards.AddLast((RegularCard)Activator.CreateInstance(typeof(RegularCard), suit, val)!);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,20 +1,4 @@
|
||||
namespace Nadeko.Econ;
|
||||
|
||||
public sealed class RegularCard : NewCard<RegularSuit, RegularValue>
|
||||
{
|
||||
public RegularCard(RegularSuit suit, RegularValue value) : base(suit, value)
|
||||
{
|
||||
}
|
||||
|
||||
private bool Equals(RegularCard other)
|
||||
=> other.Suit == this.Suit && other.Value == this.Value;
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
=> ReferenceEquals(this, obj) || obj is RegularCard other && Equals(other);
|
||||
|
||||
public override int GetHashCode()
|
||||
=> Suit.GetHashCode() * 17 + Value.GetHashCode();
|
||||
|
||||
public override string ToString()
|
||||
=> $"{Value.ToString()}-{Suit.ToString()}";
|
||||
}
|
||||
public sealed record class RegularCard(RegularSuit Suit, RegularValue Value)
|
||||
: NewCard<RegularSuit, RegularValue>(Suit, Value);
|
@@ -2,4 +2,14 @@
|
||||
|
||||
public sealed class RegularDeck : NewDeck<RegularCard, RegularSuit, RegularValue>
|
||||
{
|
||||
public RegularDeck()
|
||||
{
|
||||
foreach (var suit in _suits)
|
||||
{
|
||||
foreach (var val in _values)
|
||||
{
|
||||
_cards.AddLast((RegularCard)Activator.CreateInstance(typeof(RegularCard), suit, val)!);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user