- Check for allowed card type was before the check for the mau cards, which caused incorrect cards to be played and mau cards to be passed to wrong players - Ending with a special card is now a faulty move, which grants the player 5 fault cards now - Grabbed cards could be registered as playable as it didnt include next allowed card type - If the first card is a joker, set the next allowed card type to a random other card type to prevent an instant softlock - Other cleanup :)
94 lines
2.0 KiB
C#
94 lines
2.0 KiB
C#
namespace MauMau_Server.Mau;
|
|
|
|
public class Card
|
|
{
|
|
public readonly CardType CardType;
|
|
public readonly CardValue CardValue;
|
|
|
|
public Card(CardType cardType, CardValue cardValue)
|
|
{
|
|
CardType = cardType;
|
|
CardValue = cardValue;
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return $"{CardType} {CardValue}";
|
|
}
|
|
|
|
public Card parseCard(string card)
|
|
{
|
|
var cardType = card.Split(" ")[0];
|
|
var cardValue = card.Split(" ")[1];
|
|
return new Card((CardType)Enum.Parse(typeof(CardType), cardType),
|
|
(CardValue)Enum.Parse(typeof(CardValue), cardValue));
|
|
}
|
|
}
|
|
|
|
public static class CardExtensions
|
|
{
|
|
public static bool IsSameCard(this Card card1, Card card2)
|
|
{
|
|
return card1.IsSameCardType(card2) && card1.IsSameCardValue(card2);
|
|
}
|
|
|
|
public static bool IsSameCardType(this Card card1, Card card2)
|
|
{
|
|
return card1.CardType == card2.CardType;
|
|
}
|
|
|
|
public static bool IsSameCardValue(this Card card1, Card card2)
|
|
{
|
|
return card1.CardValue == card2.CardValue;
|
|
}
|
|
|
|
public static bool CanBePlayedOn(this Card playedCard, Card currentCard)
|
|
{
|
|
return playedCard.IsSameCardType(currentCard)
|
|
|| playedCard.IsSameCardValue(currentCard)
|
|
|| playedCard.CardType == CardType.JOKER;
|
|
}
|
|
|
|
public static bool IsSpecialCard(this Card card)
|
|
{
|
|
return card.IsMauCard() || card.CardValue is
|
|
CardValue.SEVEN or
|
|
CardValue.EIGHT or
|
|
CardValue.JACK or
|
|
CardValue.KING or
|
|
CardValue.ACE;
|
|
}
|
|
|
|
public static bool IsMauCard(this Card card)
|
|
{
|
|
return card.CardType == CardType.JOKER || card.CardValue is CardValue.TWO;
|
|
}
|
|
}
|
|
|
|
public enum CardType
|
|
{
|
|
SPADES,
|
|
HEARTS,
|
|
DIAMONDS,
|
|
CLUBS,
|
|
JOKER
|
|
}
|
|
|
|
public enum CardValue
|
|
{
|
|
TWO,
|
|
THREE,
|
|
FOUR,
|
|
FIVE,
|
|
SIX,
|
|
SEVEN,
|
|
EIGHT,
|
|
NINE,
|
|
TEN,
|
|
JACK,
|
|
QUEEN,
|
|
KING,
|
|
ACE,
|
|
RED,
|
|
BLACK
|
|
} |