Fixed some bugs and added new features that came up while testing:
All checks were successful
Build Mau & Deploy Mau / build (push) Successful in 1m29s
Build Mau & Deploy Mau / deploy (push) Has been skipped

- 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 :)
This commit is contained in:
2024-06-12 15:57:09 +02:00
parent 2ef1de9d64
commit 0918b2b3cc
3 changed files with 126 additions and 78 deletions

View File

@@ -2,9 +2,9 @@
public class Deck
{
private List<Card> _unusedDeck = new();
private List<Card> _usedDeck = new();
public Card CurrentCard;
private readonly List<Card> _unusedDeck = new();
private readonly List<Card> _usedDeck = new();
public Card CurrentCard { get; private set; }
/**
* <summary>
@@ -15,23 +15,20 @@ public class Deck
{
CreateSet();
ShuffleDeck();
CurrentCard = DrawCard();
_usedDeck.Add(CurrentCard);
if (CurrentCard.CardType != CardType.JOKER) return;
CurrentCard = DrawCard();
_usedDeck.Add(CurrentCard);
var initialCard = DrawCard();
CurrentCard = initialCard;
}
/**
* <summary>
* Adds the given card to the used cards deck.
* Adds the given card to the used cards deck and sets the current card to the given card.
* </summary>
* <param name="card">The card to add to the used cards deck.</param>
*/
public void AddCardToUsedDeck(Card card)
{
_usedDeck.Add(card);
CurrentCard = card;
}
/**
@@ -44,29 +41,6 @@ public class Deck
{
_usedDeck.AddRange(cards);
}
/**
* <summary>
* Creates a new deck of cards and adds them to the unused deck.
* </summary>
*/
private void CreateSet()
{
foreach (CardType cardType in Enum.GetValues(typeof(CardType)))
{
if (cardType == CardType.JOKER)
{
_unusedDeck.Add(new Card(cardType, CardValue.RED));
_unusedDeck.Add(new Card(cardType, CardValue.BLACK));
continue;
}
foreach (CardValue cardValue in Enum.GetValues(typeof(CardValue)))
{
if (cardValue is CardValue.RED or CardValue.BLACK) continue;
_unusedDeck.Add(new Card(cardType, cardValue));
}
}
}
/**
* <summary>
@@ -97,6 +71,29 @@ public class Deck
}
return cards;
}
/**
* <summary>
* Creates a new deck of cards and adds them to the unused deck.
* </summary>
*/
private void CreateSet()
{
foreach (CardType cardType in Enum.GetValues(typeof(CardType)))
{
if (cardType == CardType.JOKER)
{
_unusedDeck.Add(new Card(cardType, CardValue.RED));
_unusedDeck.Add(new Card(cardType, CardValue.BLACK));
continue;
}
foreach (CardValue cardValue in Enum.GetValues(typeof(CardValue)))
{
if (cardValue is CardValue.RED or CardValue.BLACK) continue;
_unusedDeck.Add(new Card(cardType, cardValue));
}
}
}
/**
* <summary>
@@ -124,6 +121,9 @@ public class Deck
*/
private void ShuffleDeck()
{
_unusedDeck = _unusedDeck.OrderBy(x => Guid.NewGuid()).ToList();
var unusedDeckCopy = new List<Card>(_unusedDeck);
_unusedDeck.Clear();
unusedDeckCopy = unusedDeckCopy.OrderBy(x => Guid.NewGuid()).ToList();
_unusedDeck.AddRange(unusedDeckCopy);
}
}