T
Tony Johansson
Hello!
Here is some code that initialize one card of Deck A card of Deck have 52
cards.
Now to my question I also want to be able to initialize any number of decks
in a collection
For example when this method InitDeck is called the array collection cards
have already been allocated to the right size.
So the comment is there now but I just wonder if there is possible to write
some nice code that initialize for example 3
card of deck which mean that this cards array can store three decks of card
private void InitDeck()
{
int currentCard;
cards[0] = new Card(0, 0); //index on position 0 is not used
// for (int deck = 1; deck <= cards.Length/52; deck++)
// {
for (int suit = (int)CardSuit.Club; suit <= (int)CardSuit.Spade;
suit++)
{
for (int rank = (int)CardValue.Ace; rank <=
(int)CardValue.King; rank++)
{
currentCard = (rank + (suit - 1) * 13) * deck;
cards[currentCard] = new Card((CardSuit)suit,
(CardValue)rank);
}
}
// }
}
//Tony
Here is some code that initialize one card of Deck A card of Deck have 52
cards.
Now to my question I also want to be able to initialize any number of decks
in a collection
For example when this method InitDeck is called the array collection cards
have already been allocated to the right size.
So the comment is there now but I just wonder if there is possible to write
some nice code that initialize for example 3
card of deck which mean that this cards array can store three decks of card
private void InitDeck()
{
int currentCard;
cards[0] = new Card(0, 0); //index on position 0 is not used
// for (int deck = 1; deck <= cards.Length/52; deck++)
// {
for (int suit = (int)CardSuit.Club; suit <= (int)CardSuit.Spade;
suit++)
{
for (int rank = (int)CardValue.Ace; rank <=
(int)CardValue.King; rank++)
{
currentCard = (rank + (suit - 1) * 13) * deck;
cards[currentCard] = new Card((CardSuit)suit,
(CardValue)rank);
}
}
// }
}
//Tony