Skip to content

Instantly share code, notes, and snippets.

@edhedges
Created November 29, 2011 14:29
Show Gist options
  • Save edhedges/1404978 to your computer and use it in GitHub Desktop.
Save edhedges/1404978 to your computer and use it in GitHub Desktop.
Deck class
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