/// is to be drawn face up
public Card(byte cardNo, bool faceUp)
{
CardNo = cardNo;
FaceUp = faceUp;
}
///
/// Constructs a face up card with that number
///
///
public Card(byte cardNo)
: this(cardNo, true)
{
}
///
/// String description of the card
///
/// the name and suit of the card
public override string ToString()
{
return ValueName + " of " + Suit;
}
}
///
/// Provides a container for a number of cards.
/// May be used to draw the cards and compute their score.
///
public class CardHand : ArrayList
{
///
/// Used as a destination of teh draw action
///
private static Rectangle drawRect;
///
/// Draws the hand on the graphics.
///
/// graphics to draw with
/// left edge of first card
/// top of first card
/// x gap between each card
/// y gap between each card
public void DrawHand(Graphics g, int startx, int starty,
int gapx, int gapy)
{
drawRect.X = startx;
drawRect.Y = starty;
foreach (Card card in this)
{
drawRect.Width = card.CardImage.Width;
drawRect.Height = card.CardImage.Height;
g.DrawImage(
card.CardImage, // Image
drawRect, // destination rectange
0, // srcX
0, // srcY
card.CardImage.Width, // srcWidth
card.CardImage.Height, // srcHeight
GraphicsUnit.Pixel, // srcUnit
Card.cardAttributes); // ImageAttributes
drawRect.X += gapx;
drawRect.Y += gapy;
}
}
///
/// Computes the score of the hand
///
/// the value of the score
public int BlackJackScoreHand()
{
int score = 0;
int aces = 0;
foreach (Card card in this)
{
score += card.BlackJackScore;
if (card.BlackJackScore == 11)
{
aces++;
}
}
while ((score > 21) && (aces > 0))
{
score -= 10;
aces–;
}
return score;
}
}
///
/// Contains a number of card decks
/// which can be dealt one at a time.
///
public class CardShoe
{
private int noOfDecks = 1;
private byte[] decks;
private int nextCard;
private bool testShoe = false;
///
/// True if the deck is "stacked",
/// i.e. was created from a byte array