Solved sonarlint issue and some more code documentation
All checks were successful
Build Mau & Deploy Mau / build (push) Successful in 1m1s
Build Mau & Deploy Mau / deploy (push) Has been skipped

This commit is contained in:
2024-06-12 16:07:31 +02:00
parent 0918b2b3cc
commit 25b7a8fb1e

View File

@@ -13,9 +13,16 @@ public class Deck
*/
public Deck()
{
// Create a new set of cards
CreateSet();
// Shuffle the deck
ShuffleDeck();
// Draw the first card
var initialCard = DrawCard();
// Set the current card to the first card
CurrentCard = initialCard;
}
@@ -27,7 +34,10 @@ public class Deck
*/
public void AddCardToUsedDeck(Card card)
{
// Add the card to the used deck
_usedDeck.Add(card);
// Set the current card to the given card
CurrentCard = card;
}
@@ -50,9 +60,13 @@ public class Deck
*/
public Card DrawCard()
{
// Check if the deck is empty, if so, reshuffle it
if (_unusedDeck.Count == 0) ReshuffleDeck();
// Grab the first card from the deck and remove it
var card = _unusedDeck[0];
_unusedDeck.RemoveAt(0);
return card;
}
@@ -64,6 +78,7 @@ public class Deck
*/
public IEnumerable<Card> DrawCards(int amount)
{
// Create a list of cards and add the drawn cards to it
var cards = new List<Card>();
for (var i = 0; i < amount; i++)
{
@@ -103,14 +118,17 @@ public class Deck
*/
private void ReshuffleDeck()
{
// Move all used cards back to the unused deck
_unusedDeck.AddRange(_usedDeck);
_usedDeck.Clear();
if (_unusedDeck.Count == 0)
// If there are no cards left, create a new set and add it
if (!_unusedDeck.Any())
{
CreateSet();
}
// Shuffle the deck
ShuffleDeck();
}
@@ -121,9 +139,14 @@ public class Deck
*/
private void ShuffleDeck()
{
// Clear the unused ceck
var unusedDeckCopy = new List<Card>(_unusedDeck);
_unusedDeck.Clear();
// Shuffle the deck
unusedDeckCopy = unusedDeckCopy.OrderBy(x => Guid.NewGuid()).ToList();
// Add the shuffled deck back to the unused deck
_unusedDeck.AddRange(unusedDeckCopy);
}
}