Created
November 29, 2011 14:29
-
-
Save edhedges/1404978 to your computer and use it in GitHub Desktop.
Deck class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
namespace HedgesBlackjack | |
{ | |
class Deck | |
{ | |
private int _topCard = 51; | |
private Card[] _deck = new Card[52]; | |
private Random r = new Random(); | |
public Deck() | |
{ | |
int x = 0; | |
for (int k = 2; k < 15; k++) | |
{ | |
for (int j = 1; j < 5; j++) | |
{ | |
_deck[x] = new Card((Suits)j, k); | |
x++; | |
} | |
} | |
} | |
public Deck Shuffle() | |
{ | |
Card temp; | |
int x; | |
for (int i = _deck.Length; i > 0; i--) | |
{ | |
x = r.Next(0, i); | |
temp = _deck[x]; | |
_deck[x] = _deck[i - 1]; | |
_deck[i - 1] = temp; | |
} | |
return this; | |
} | |
public Card Draw() | |
{ | |
Card c = _deck[_topCard]; | |
_topCard--; | |
return c; | |
} | |
public void AddCard(Card c) | |
{ | |
_topCard++; | |
_deck[_topCard] = c; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment