I am having this silly issue and I have no idea how to fix, im creating a blackjack game and I have a card class with a Deck() and Shuffle() methods, and a dealer class that will hand out the cards.
The shuffle method is an Extension method that I got on this site funny enough but I cant get it to receive the list of cards from the Deck() method...
I did originaly use a dictionary and had trouble shuffling the dictionary and asked for help on this site Here And they suggested using a list and now im here.
Here is the Card and Dealer Classes
Card.cs
public static class Card
{
private static List<string> deckOfCards = new List<string>();
private static string[] Suite = new string[4] {"Clubs", "Hearts", "Spades", "Diamonds" };
private static string[] FaceValue = new string[13] {"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King" };
public static void Deck()
{
for (int s = 0; s < 4; s++ )
{
string sut = Suite[s];
for (int fV = 0; fV < 13; fV++)
{
string value = FaceValue[fV];
deckOfCards.Add(sut + value);
}
}
// End of For loop.
Shuffle(deckOfCards);
}
public static void Shuffle<T>(this IList<T> list)
{
Random rng = new Random();
int n = list.Count;
while (n > 1)
{
n--;
int k = rng.Next(n + 1);
T value = list[k];
list[k] = list[n];
list[n] = value;
}
}
}
Dealer.cs
class Dealer
{
private List<string> randomisedCards = new List<string>();
public Dealer()
{
randomisedCards.Shuffle();
}
public string dealCard()
{
string randCard = randomisedCards[0];
randomisedCards.RemoveAt(0);
return randCard;
}
}
Criticism is highlight recommended as that's how you learn but please keep in mind that im still a beginner and have no experience at all.
Thanks