I have an array named mainDeck
which holds the values for a deck of playing cards. What I have to do next is distribute the cards within that array to two separate arrays named playerDeck
and computerDeck
and each deck must contain a unique card.
The problem I have is distributing the cards with a unique value - 26 cards per deck. I have tried a few different approaches and the coding at the bottom in comments is the last remnant of what I was trying to do before I had to leave for class which isn't finished.
To note: My programming skills are limited to please explain your answer rather then just give a solution as that doesn't further my understanding.
static void Main(string[] args)
{
// 1 = Ace , 13 = King : 0 = Hearts, 1 = Diamonds, 2 = Clubs, 3 = Spades
int[] mainDeck = new int[52];
FillDeck(mainDeck);
int[] playerDeck = new int[26];
int[] computerDeck = new int[26];
// Check mainDeck elements
foreach (int number in mainDeck)
{
Console.WriteLine(number);
}
}
public static void FillDeck(int [] mainDeck)
{
int cardType = 1;
List<int> deck = new List<int>();
// Add cards to a list
for (int x = 0; x < 13; x++)
for(int y = 0; y < 4; y++)
{
deck.Add(cardType);
if (y == 3)
++cardType;
}
// Insert deck list into a new Array
int[] cards = deck.GetRange(0, 52).ToArray();
// Add cards array to mainDeck
for (int x = 0; x < 52; ++x)
{
mainDeck[x] = cards[x];
}
}
//public static void Distribute()
//{
// RandomNumber number = new RandomNumber();
// int value = number.RandomNum;
// List<int> playerCards = new List<int>();
// for (int x = 0; x < 2; ++x)
// {
// Console.WriteLine(number.RandomNum);
// }
//}
}
//class RandomNumber
//{
// private int randomNum;
// Random ranNumberGenerator;
// public RandomNumber()
// {
// ranNumberGenerator = new Random();
// }
// public int RandomNum
// {
// get
// {
// randomNum = ranNumberGenerator.Next(1, 26);
// return randomNum;
// }
// }
//}