-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generalised CardDeck by using 'string' as the underlying data type of…
… a card type and sub type which will allow users to control what cards their game gave.
- Loading branch information
Showing
21 changed files
with
478 additions
and
432 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,42 @@ | ||
namespace Deck.Deck.Card; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
public enum CardSubType : byte | ||
namespace Deck.Deck.Card; | ||
|
||
public readonly struct CardSubType | ||
{ | ||
// Numeric | ||
Zero, | ||
One, | ||
Two, | ||
Three, | ||
Four, | ||
Five, | ||
Six, | ||
Seven, | ||
Eight, | ||
Nine, | ||
public CardSubType(string _name) | ||
{ | ||
SubTypeName = _name; | ||
hash = SubTypeName.GetHashCode(); | ||
} | ||
|
||
public string SubTypeName { get; } | ||
|
||
private readonly int hash; | ||
|
||
// Special | ||
PlusTwo, | ||
Skip, | ||
Reverse, | ||
public override int GetHashCode() | ||
{ | ||
return hash; | ||
} | ||
|
||
// Wild (Special | ||
Wild, | ||
WildPlusFour, | ||
public static bool operator ==(CardSubType _this, CardSubType _other) | ||
{ | ||
return _this.SubTypeName == _other.SubTypeName; | ||
} | ||
public static bool operator !=(CardSubType _this, CardSubType _other) | ||
{ | ||
return !(_this == _other); | ||
} | ||
public override bool Equals([NotNullWhen(true)] object? obj) | ||
{ | ||
if(obj == null) | ||
{ | ||
return false; | ||
} | ||
if(obj is not CardSubType _subType) | ||
{ | ||
return false; | ||
} | ||
return _subType == this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,55 @@ | ||
namespace Deck.Deck.Card; | ||
using System.Collections.Frozen; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
public enum CardType : byte | ||
namespace Deck.Deck.Card; | ||
|
||
public readonly struct CardType | ||
{ | ||
Numeric, | ||
Special | ||
public CardType(string _name, FrozenSet<CardSubType> _typeMembers) | ||
{ | ||
TypeName = _name; | ||
TypeMembers = _typeMembers; | ||
var _hash = new HashCode(); | ||
_hash.Add(TypeName); | ||
|
||
for(int i = 0; i < TypeMembers.Count; i++) | ||
{ | ||
_hash.Add(TypeMembers.ElementAt(i)); | ||
} | ||
|
||
hash = _hash.ToHashCode(); | ||
} | ||
public CardType(string _name, HashSet<CardSubType> _typeMembers) : this(_name, _typeMembers.ToFrozenSet()) { } | ||
public CardType(string _name, CardSubType[] _typeMembers) : this(_name, _typeMembers.ToFrozenSet()) { } | ||
|
||
public string TypeName { get; } | ||
public FrozenSet<CardSubType> TypeMembers { get; } | ||
|
||
private readonly int hash; | ||
|
||
public override int GetHashCode() | ||
{ | ||
return hash; | ||
} | ||
|
||
public static bool operator ==(CardType _this, CardType _other) | ||
{ | ||
return _this.hash == _other.hash; | ||
} | ||
public static bool operator !=(CardType _this, CardType _other) | ||
{ | ||
return !(_this.hash == _other.hash); | ||
} | ||
public override bool Equals([NotNullWhen(true)] object? _obj) | ||
{ | ||
if(_obj == null) | ||
{ | ||
return false; | ||
} | ||
if(_obj is not CardType _cardType) | ||
{ | ||
return false; | ||
} | ||
return _cardType == this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.