Solved

My picture wont show up

Posted on 2009-07-15
5
308 Views
Last Modified: 2012-05-07
I am trying to get a Black jack game running.
I have managed to get it work abit but when I am trying to show the cards picutre it is like it repaint it with the background on it instead of the card itself.

i cant seem to find the problem. Help needed.

Code below or download the project here:
http://www.2shared.com/file/6701386/ce7dcca4/Projects.html

Form1.cs

-------------------------
 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Collections;

using System.Windows.Forms;

using System.Configuration;

using System.Drawing.Drawing2D;

using CardGameClassLib;
 

namespace Black_Jack

{

    public partial class Form1 : Form

    {

        private Deck deck = new Deck();

        // An array of player objects

        private Player[] players = new Player[0];

        // The dealer object

        private Dealer dealer;

        // Whether or not the dealer's down card is visible

        private bool showDealerDownCard;

        // Indicates we are in insurance mode

        private bool insurance = false;

        private bool showInsurance = false;

        // This keeps track of how many times we've flashed the insurance highlight

        private int tickCount = 0;

        // currentPlayer keeps track of which player is active

        // currentPlayer > the number of Players (or -1) means the dealer is active

        private int currentPlayer = -1;

        // Determines what kind of label is drawn to the upper left of each player hand

        // Normally display the card total, but after a hand, display the outcome

        private LabelType labelType = LabelType.bothHands;

        // Statistics variables

        private int deals = 0;

        private int shuffles = 0;

        // variables to keep track of which player we are changing 

        private int playerNumber;

        // Boolean indicates end of shoe.  It is set via event from the shoe

        private bool endOfDeck;

        // This tells the paint routine that we're dealing so the advice doesn't get shown

        // until we know if this is an insurance round or not.

        bool dealing = false;

        private int nrofDecks = 5;
 
 
 
 

        public Form1()

        {

            InitializeComponent();

            deck.EndOfDeckEvent += new Deck.DeckEventHandler(EndOfDeck);

            deck.ShuffleEvent += new Deck.DeckEventHandler(ShuffleDeck);

        }
 

        private void button1_Click(object sender, EventArgs e)

        {            

            deck.Shuffle();           

        }
 
 

        private void EndOfDeck(object sender, EventArgs e)

        {

            endOfDeck = true;

        }
 

        private void ShuffleDeck(object sender, EventArgs e)

        {

            endOfDeck = false;

        }
 

        private void dealButton_Click(object sender, EventArgs e)

        {

            // Keep track of statistics

            deals++;
 

            // Reset the players

            foreach (Player player in players)

            {

                // Reset all players regardless of whether they are active

                player.Reset();

            }

                        
 

            // Reset insurance

            insurance = false;
 

            // Set the buttons in the correct state

            SetButtonState(false);
 
 

            // Reset the dealer

            showDealerDownCard = false;

            dealer.Reset();
 

            // Reset the player pointer

            currentPlayer = 0;
 

            // Shuffle if we need to

            if (deck.Eod)

            {

                endOfDeck = false;
 

                // This clears the screen so it looks like the dealer picked up all the cards

                this.Refresh();
 

                // Then shuffle the deck

                Shuffle();

            }
 
 

            // Get the recommended wager from the counting system

            foreach (Player player in players)

            {

                if (player.Active) player.GetWager();

            }
 

            // Set the label type to draw all labels

            labelType = LabelType.bothHands;
 

            Card newCard = null;

            Card dealerCard = null;
 

            dealing = true;
 

			// Deal the cards

            for (int k = 0; k < 2; k++)

            {

                foreach (Player player in players)

                {

                    if (player.Active)

                    {

                        // Get a card

                        newCard = deck.Next();

                        // Put it in the player's hand

                        player.GetHands()[0].Add(newCard);

                        // And give all players the opportunity to count it

                        CountCard(newCard);

                        this.Refresh();

                    }

                }
 

                // Now give the dealer a card

                dealerCard = deck.Next();

                dealer.Hand.Add(dealerCard);
 

                // And if it is the up card, give the players the opportunity to count it

                if (k == 1)

                    CountCard(newCard);
 

                this.Refresh();

            }

            

            dealing = false;
 
 

                // If dealer has an ace showing, 

			// check to see if anybody wants insurance.

			if( dealer.Hand.Cards[0].CardValue == CardType.Ace )

			{

				// Highlight the board to indicate insurance is available

				insurance = true;		

	            SetButtonState( false );

				this.Refresh();

			}

            else if (dealer.Hand.IsBlackjack())

            {

                // Dealer blackjack

                labelType = LabelType.outcome;

                currentPlayer = players.GetUpperBound(0) + 1;
 

                // Show down card

				showDealerDownCard = true;
 

                // Let everyone count it

                this.Refresh();
 

                // Let the players count it 

                CountCard(dealer.Hand[0]);
 
 
 

                // Take the money from everybody unless they have Blackjack

                foreach (Player player in players)

                {

                    if (player.Active)

                    {

                        foreach (Hand hand in player.GetHands())

                        {

                            if (hand.IsBlackjack())

                                // If the player also had Blackjack, Push

                                player.Push(hand);

                        }

                        

                    }

                }

                this.Refresh();

                SetButtonState( true );
 

            }
 

            else

            {

                this.Refresh();
 

                // Loop through the players until we find one that doesn't have 21

                int handTotal = 0;

                do

                {

                    handTotal = CurrentPlayer.CurrentHand.Total();

                    if (handTotal == 21)

                        NextPlayer();

                } while (handTotal == 21 && CurrentPlayer != null);
 

                SetButtonState( false );

             }
 

                   
 

            // The next deal will begin with a shuffle, tell the players

            // to reset their card count now so the suggested bet for human

            // players is accurate.

            if (deck.Eod)

            {

                foreach (Player player in players)

                {

                    if (player.Active) player.ResetCount(nrofDecks);

                }

            }
 

            ////TEST CODE

            //Hand[] hander = new Hand[5];

            //hander = players[0].GetHands();

            //textBox1.Text = Convert.ToString(hander[0].Cards[0].CardValue);

            //textBox2.Text = Convert.ToString(hander[0].Cards[0].Suit);
 

            //textBox3.Text = Convert.ToString(hander[0].Cards[1].CardValue);

            //textBox4.Text = Convert.ToString(hander[0].Cards[1].Suit);
 

            ////hand = dealer.Hand;

            //textBox5.Text = Convert.ToString(dealer.Hand.Cards[0].CardValue);

            //textBox6.Text = Convert.ToString(dealer.Hand.Cards[0].Suit);
 

            //textBox7.Text = Convert.ToString(dealer.Hand.Cards[1].CardValue);

            //textBox8.Text = Convert.ToString(dealer.Hand.Cards[1].Suit);
 
 

            

        }
 

        private void btnSplit_Click(object sender, System.EventArgs e)

        {

            // Make sure we're working with a player and not the dealer

            // and that it's not an insurance round

            if (CurrentPlayer != null && !insurance)

            {

                // See if the player is able to split

                if (CurrentPlayer.Split())

                {

                    // Refresh so that the split hands show up

                    this.Refresh();
 

                    // Splitting aces is a special case...

                    if (CurrentPlayer.CurrentHand[0].CardValue == CardType.Ace)

                    {

                        // Player only gets one more card for each hand

                        NextCard();

                        NextHand();
 

                        // Then move on to the next player

                        NextPlayer();

                    }

                    else

                    {

                        // Normal split, deal another card to the current hand

                        labelType = LabelType.drawToHand;

                        NextCard();
 

                        // If they hit 21, move to the next hand automatically

                        if (CurrentPlayer.CurrentHand.Total() == 21)

                        {

                            NextHand();
 

                            // And if that hand has 21, move to the next player

                            if (CurrentPlayer.CurrentHand.Total() == 21)

                                NextPlayer();

                        }

                    }

                }

            }

        }
 

        private void btnHit_Click(object sender, System.EventArgs e)

        {

            // Make sure we're working with a player and not the dealer

            // and that it's not an insurance round

            if (CurrentPlayer != null && !insurance)

            {

                int handTotal = 0;
 

                // Give them another card

                NextCard();
 

                do

                {

                    // Now loop until we find a player that hasn't busted or dealt 21

                    handTotal = CurrentPlayer.CurrentHand.Total();

                    if (handTotal >= 21)

                    {

                        if (CurrentPlayer.LastHand())

                        {

                            // Move to the next player

                            NextPlayer();
 

                            // and get their total so the loop can continue if need be

                            if (CurrentPlayer != null)

                                handTotal = CurrentPlayer.CurrentHand.Total();

                        }

                        else

                        {

                            // The player has split, move to the next hand

                            NextHand();
 

                            // Get the hand total so the loop can continue if need be

                            handTotal = CurrentPlayer.CurrentHand.Total();

                        }

                    }

                } while (handTotal >= 21 && CurrentPlayer != null);

            }

        }
 

        private void btnStay_Click(object sender, System.EventArgs e)

        {

            int handTotal = 0;
 

            // Make sure we're working with a player and not the dealer

            // and that it's not an insurance round

            if (CurrentPlayer != null && !insurance)

            {

                if (CurrentPlayer.LastHand())

                    NextPlayer();

                else

                    // If the player has split, move to the next hand...

                    NextHand();
 

                // Make sure we didn't skip past the last player above

                if (CurrentPlayer != null)

                {

                    do

                    {

                        // Now loop until we find a player that hasn't busted or dealt 21

                        handTotal = CurrentPlayer.CurrentHand.Total();

                        if (handTotal >= 21)

                        {

                            if (CurrentPlayer.LastHand())

                            {

                                // Move to the next player

                                NextPlayer();
 

                                // and get their total so the loop can continue if need be

                                if (CurrentPlayer != null)

                                    handTotal = CurrentPlayer.CurrentHand.Total();

                            }

                            else

                            {

                                // The player has split, move to the next hand

                                NextHand();
 

                                // Get the hand total so the loop can continue if need be

                                handTotal = CurrentPlayer.CurrentHand.Total();

                            }

                        }

                    } while (handTotal >= 21 && CurrentPlayer != null);

                }

            }

        }
 

        private void btnDoubleDown_Click(object sender, System.EventArgs e)

        {

            // Make sure we're working with a player and not the dealer

            // and that it's not an insurance round

            if (CurrentPlayer != null && !insurance)

            {

                if (CurrentPlayer.DoubleDown(CurrentPlayer.CurrentHand))

                {

                    // Deal one more card

                    NextCard();
 

                    if (CurrentPlayer.LastHand())

                        // Move to the next player...

                        NextPlayer();

                    else

                        // or next hand if the player split

                        NextHand();

                }

            }

        }
 

        private void btnInsurance_Click(object sender, System.EventArgs e)

        {

            // Make sure we're working with a player and not the dealer

            // and that it's an insurance round

            if (CurrentPlayer != null && insurance)

            {

                CurrentPlayer.Insurance = true;

                NextPlayer();

            }

        }
 

        private void btnNoInsurance_Click(object sender, System.EventArgs e)

        {

            // Make sure we're working with a player and not the dealer

            // and that it's an insurance round

            if (CurrentPlayer != null && insurance)

            {

                CurrentPlayer.Insurance = false;

                NextPlayer();

            }
 

        }
 

        private void NextCard()

        {

            // Get the next card

            Card newCard = deck.Next();
 

            // Tell each of the players what the card is 

            CountCard(newCard);
 

            // Add a card to the player's hand

            CurrentPlayer.CurrentHand.Add(newCard);
 

            // and show it.

            this.Refresh();
 

            // The strategy may change with each card so highlight the correct button

            SetButtonState(false);

        }
 

        private void NextHand()

        {

            // Advance to the player's next hand (for splits only)

            CurrentPlayer.NextHand();
 

            // They always get another card on a new, split hand

            NextCard();
 

            // The strategy may change with each card so highlight the correct button

            SetButtonState(false);

        }
 
 
 
 

        private void NextPlayer()

        {

            // Make sure both of the current players hands are visible and have labels

            labelType = LabelType.bothHands;
 

            do

            {

                currentPlayer++;

                this.Refresh();
 

                // Dealer's turn

                if (CurrentPlayer == null)

                {

                    if (insurance && !dealer.Hand.IsBlackjack())

                    {

                        foreach (Player player in players)

                        {

                            if (player.Insurance)

                            {

                                player.LostInsurance();

                                player.Insurance = false;

                            }

                        }

                        // We're no longer in insurance mode

                        insurance = false;

                        currentPlayer = 0;

                 

                        this.Refresh();

                       

                    }

                    else

                    {
 

                        // Update the screen so we can see it

                        this.Refresh();
 

                        // Let the players count it if they want to

                        CountCard(dealer.Hand[0]);
 

                        // Only hit to the dealer if someone didn't bust

                        bool hitToDealer = false;
 

                        foreach (Player player in players)

                        {

                            if (player.Active)

                            {

                                foreach (Hand hand in player.GetHands())

                                {

                                    if (hand.Total() > 0 && hand.Total() <= 21 && !hand.IsBlackjack())

                                    {

                                        hitToDealer = true;

                                        break;

                                    }

                                }

                            }

                            if (hitToDealer)

                                break;

                        }
 

                        if (hitToDealer)

                        {

                            while (dealer.Total() < 17)

                            {

                                Card dealerCard = deck.Next();

                                dealer.AddCard(dealerCard);

                                this.Refresh();
 

                                // Give each player the opportunity to count the card

                                CountCard(dealerCard);

                            }

                        }
 

                        labelType = LabelType.outcome;
 

                        foreach (Player player in players)

                        {

                            if (player.Active)

                            {

                                if (insurance && dealer.Hand.IsBlackjack())

                                    player.WonInsurance();

                                else

                                    player.LostInsurance();
 

                                foreach (Hand hand in player.GetHands())

                                {

                                    switch (hand.Outcome(dealer.Hand, player.NumberOfHands))

                                    {

                                        case OutcomeType.Won:

                                            player.Won(hand);

                                            break;

                                        case OutcomeType.Lost:

                                            // Do nothing, the money was taken at the beginning of play

                                            break;

                                        case OutcomeType.Push:

                                            player.Push(hand);

                                            break;

                                        case OutcomeType.Blackjack:

                                            player.Blackjack(hand);

                                            break;

                                        default:

                                            // Hand not in play

                                            break;

                                    }

                                }
 

                            }

                        }
 

                        // Reset the form for entry

                        insurance = false;
 
 

                        

                        // The next deal will begin with a shuffle, tell the players

                        // to reset their card count now so the suggested bet for human

                        // players is accurate.

                        if (deck.Eod)

                        {

                            foreach (Player player in players)

                            {

                                if (player.Active) player.ResetCount((int)nrofDecks);

                            }

                        }
 

                        this.Refresh();

                    }

                }

                   
 

            } while (CurrentPlayer != null && CurrentPlayer.CurrentHand.Total() >= 21 && !insurance);
 

        }
 
 

        private Player CurrentPlayer

        {

            get

            {

                if (currentPlayer >= 0 &&

                    currentPlayer <= players.GetUpperBound(0) &&

                    players[currentPlayer].Active)

                {

                    return players[currentPlayer];

                }

                else

                {

                    return null;

                }

            }

        }
 
 

        private void CountCard(Card newCard)

        {

            // Tell each of the players what the new card is

            // so they can count it if they want to.

            foreach (Player player in players)

            {

                if (player.Active) player.CountCard(newCard);

            }

        }
 

        private void InitializePlayers(int numPlayers)

        {

            players = new Player[numPlayers];

            for (int i = 0; i < numPlayers; i++)

            {

                switch (i)

                {

                    case 0:  // PLAYER 1
 

                        if (ConfigurationSettings.AppSettings["player1"] != null)

                        {

                            try

                            {

                                string[] playerConfig = ConfigurationSettings.AppSettings["player1"].ToString().Split(new char[] { '|' });

                                players[i] = CreatePlayer(new Point(961, 299), 5000.00, playerConfig[0], nrofDecks);

                            }

                            catch

                            {

                                players[i] = new Player(new Point(961, 299), 5000.00, playerType.human, new HiLo((int)nrofDecks));

                                // Note that there must be a player 1

                                players[i].Active = true;

                            }

                        }

                        else

                        {

                            players[i] = new Player(new Point(961, 299),5000.00, playerType.human, new HiLo((int)nrofDecks));

                            // Note that there must be a player 1

                            players[i].Active = true;

                        }

                        break;
 

                }

            }

            

            this.Refresh();

        }
 
 
 

        private Player CreatePlayer(Point point, double bank, string type, int numDecks)

        {

            Player player = new Player(point, bank, type.ToLower() == "human" ? playerType.human : playerType.computer, new HiLo((int)nrofDecks));

            player.Active = true;

            return player;

        }
 
 
 
 

        private void Shuffle()

        {

            deck.Shuffle();

            shuffles++;
 

            // We need to tell each of the players we are shuffling in 

            // case they are counting cards.

            foreach (Player player in players)

            {

                if (player.Active) player.ResetCount((int)nrofDecks);

            }

        }
 

        private void Form1_Load(object sender, EventArgs e)

        {

            ArrayList methods = CountMethod.GetMethods();

            InitializePlayers(1);

            dealer = new Dealer(new Point(530, 120));

        }
 
 
 
 
 

        private void Form1_Paint(object sender, PaintEventArgs e)

        {

            Graphics drawingSurface = e.Graphics;

            Bitmap backgroundImage;

            backgroundImage = new Bitmap("C:\\Documents and Settings\\MFL\\Dokumenter\\Visual Studio 2008\\Projects\\Black_Jack\\Black_Jack\\images\\blackjack.gif");

            // Draw smooth, anti-aliased cards.  Comment out for slow machines

            drawingSurface.SmoothingMode = SmoothingMode.AntiAlias;
 

            // Clear the screen 

            Rectangle realClientArea = ClientRectangle;

            drawingSurface.DrawImage(backgroundImage, realClientArea);
 

            drawingSurface.ScaleTransform(realClientArea.Width / 1140.0F, realClientArea.Height / 648.0F);
 

            // Draw the background for the active player

            if (CurrentPlayer != null && dealer.Hand.Count > 0 && !dealing)

            {

                if (insurance)

                {                    

                    CurrentPlayer.DrawBackground(drawingSurface, insurance);

                }

                else

                    CurrentPlayer.DrawBackground(drawingSurface, dealer.Hand[1]);

            }
 

            // If the form has been initialized, there will be a shoe

            if (deck != null)

            {

                // Draw the dealer's hand

                dealer.DrawHand(drawingSurface, showDealerDownCard);
 

                foreach (Player player in players)

                {

                    // Draw the player's hand

                    if (player.Active) player.DrawHands(drawingSurface, labelType, dealer.Hand, player == CurrentPlayer);

                }

            }
 

            // Draw the marker to indicate the next hand will be preceded with a shuffle

            if (endOfDeck)

            {

                Bitmap markerImage = new Bitmap("C:\\Documents and Settings\\MFL\\Dokumenter\\Visual Studio 2008\\Projects\\Black_Jack\\Black_Jack\\images\\marker.gif");

                drawingSurface.DrawImage(markerImage, 840, 24);

            }
 

            drawingSurface.ResetTransform();

        }
 
 

        private void SetButtonState(bool dealEnabled)

        {

            // During an insurance round, only the insurance buttons are visible

            if (insurance)

            {

                btnHit.Visible = false;

                btnStay.Visible = false;

                btnDoubleDown.Visible = false;

                btnSplit.Visible = false;

                btnDeal.Visible = false;

                btnInsurance.Visible = true;

                btnNoInsurance.Visible = true;

            }

            else

            {

                // The opposite is true for normal play

                btnInsurance.Visible = false;

                btnNoInsurance.Visible = false;

                btnHit.Visible = true;

                btnStay.Visible = true;

                btnDoubleDown.Visible = true;

                btnSplit.Visible = true;

                btnDeal.Visible = true;

            }
 

            // This logic seems weird, but it says that we can only set the Deal button

            // to true if AutoDeal is not checked, but we can always set it to false.

            // This prevents the user from hitting the Deal button during AutoDeal.

            if (dealEnabled)

                btnDeal.Enabled = dealEnabled;

            else if (!dealEnabled)

                btnDeal.Enabled = dealEnabled;
 

            // Now enable and disable the buttons depending on whether a human or 

            // computer player is at play.

            if (CurrentPlayer != null)

            {

                if (CurrentPlayer.Type == playerType.computer)

                {

                    btnHit.Enabled = false;

                    btnStay.Enabled = false;

                    btnDoubleDown.Enabled = false;

                    btnSplit.Enabled = false;

                    btnInsurance.Enabled = false;

                    btnNoInsurance.Enabled = false;

                }

                else

                {

                    if (insurance)

                    {

                        btnInsurance.Enabled = true;

                        btnNoInsurance.Enabled = true;

                    }

                    else

                    {

                        btnHit.Enabled = true;

                        btnStay.Enabled = true;

                        btnDoubleDown.Enabled = CurrentPlayer.CanDouble(CurrentPlayer.CurrentHand);

                        btnSplit.Enabled = CurrentPlayer.CanSplit();

                    }

                }

            }
 

        }
 

        private void textBox1_TextChanged(object sender, EventArgs e)

        {
 

        }
 
 

        
 

        
 

        
 

        

        
 

        
 
 

        
 

        
 

       
 
 
 
 

    }

}
 
 

--------------------------------

Card.cs

-------------------------------

using System;

using System.Drawing;

using System.Drawing.Drawing2D;

using System.Drawing.Imaging;

using System.Windows.Forms;

using System.Reflection;

using System.Resources;

using System.Collections;

using System.Globalization;
 

namespace CardGameClassLib

{

    /// <summary>

    /// Card Class

    /// </summary>

    [Serializable()]

    public class Card

    {

        

        private Suit suit;

        private CardType cardType;

        private int value;

        private int trueValue;

        public static SizeF cardSpacing;

        public static SizeF cardSize;

        private Image image;
 

        public Card(CardType cardType, Suit suit)

        {

            this.suit = suit;

            this.cardType = cardType;

            value = ((int)suit * 13) + (int)cardType + 1;
 

            Bitmap cardImage = new Bitmap("C:\\Documents and Settings\\MFL\\Dokumenter\\Visual Studio 2008\\Projects\\Black_Jack\\Black_Jack\\images\\" +value +".gif");
 

            image = cardImage; 
 

            trueValue = (int)cardType;

            if (trueValue > 9)

                trueValue = 9;
 

        }
 
 
 

        public CardType CardValue 

        {

            get { return cardType; }

            set { cardType = value; }

        } 

         
 

        public Suit Suit

        {

            get { return suit; }

            set { suit = value; }

        }
 

        public int Value

        {

            get { return value; }

        }
 

        public int TrueValue

        {

            get { return trueValue; }

        }
 
 
 

        public void Draw(Graphics drawingSurface, Point location, bool show, bool dim, bool doubledownCard)

        {

            float opaqueness = dim ? .5F : 1;

            float rotationAngle = doubledownCard ? 45 : 0;
 

            float[][] ptsArray ={	new float[] {1, 0, 0, 0, 0},

									new float[] {0, 1, 0, 0, 0},

									new float[] {0, 0, 1, 0, 0},

									new float[] {0, 0, 0, opaqueness, 0}, 

									new float[] {0, 0, 0, 0, 1}};

            ColorMatrix clrMatrix = new ColorMatrix(ptsArray);

            ImageAttributes imgAttributes = new ImageAttributes();

            imgAttributes.SetColorMatrix(clrMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
 

            GraphicsState previousState = drawingSurface.Save();
 

            Point Pcenter = new Point(location.X + image.Width / 2, location.Y + image.Height / 2);

            drawingSurface.TranslateTransform(Pcenter.X, Pcenter.Y);

            drawingSurface.RotateTransform(rotationAngle);
 

            Bitmap backgroundImage = new Bitmap("C:\\Documents and Settings\\MFL\\Dokumenter\\Visual Studio 2008\\Projects\\Black_Jack\\Black_Jack\\images\\blackjack.gif");

            drawingSurface.DrawImage(backgroundImage, new Rectangle(-image.Width / 2, -image.Height / 2, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imgAttributes);
 

            drawingSurface.Restore(previousState);

        }

    }

}

	

---------------------------------------

CountMethodd.cs

---------------------------------------

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Collections;
 

namespace CardGameClassLib

{

    public abstract class CountMethod

    {
 

        protected int Decks;

        protected double runningTotal;

        protected int cardCount;

        protected int acesCount;

        protected int twosCount;

        protected int threesCount;

        protected int foursCount;

        protected int fivesCount;

        protected int sixesCount;

        protected int sevensCount;

        protected int eightsCount;

        protected int ninesCount;

        protected int tensCount;
 

        protected virtual double[] GetCounts() { return null; }
 
 
 

        protected CountMethod(int numberOfDecks)

        {

            Decks = numberOfDecks;

        }
 

        

        protected int SideCount(CardType cardType)

        {

            int count = 0;
 

            switch (cardType)

            {

                case CardType.Ace:

                    count = acesCount;

                    break;

                case CardType.Two:

                    count = twosCount;

                    break;

                case CardType.Three:

                    count = threesCount;

                    break;

                case CardType.Four:

                    count = foursCount;

                    break;

                case CardType.Five:

                    count = fivesCount;

                    break;

                case CardType.Six:

                    count = sixesCount;

                    break;

                case CardType.Seven:

                    count = sevensCount;

                    break;

                case CardType.Eight:

                    count = eightsCount;

                    break;

                case CardType.Nine:

                    count = ninesCount;

                    break;

                case CardType.Ten:

                    count = tensCount;

                    break;

            }
 

            return count;

        }
 
 
 
 

        public virtual double Insurance10Count()

        {

            double count = acesCount +

                            twosCount +

                            threesCount +

                            foursCount +

                            fivesCount +

                            sixesCount +

                            sevensCount +

                            eightsCount +

                            ninesCount +

                            (tensCount * -2);

            return count;

        }
 
 
 
 
 

        public virtual double GetWager(double normalBet)

        {

            double wager = 0;

            double trueCount = Count;
 

            if (trueCount > 0)

                wager = normalBet * trueCount;

            else if (trueCount == 0)

                wager = normalBet;

            else if (trueCount < 0)

                wager = normalBet * trueCount;
 

            // $10 table minimum :)  Also, round to nearest integer

            wager = (int)Math.Max(10, wager);
 

            return wager;

        }
 

        public virtual string MethodName { get { return ""; } }
 
 
 
 

        public virtual int MethodLevel { get { return 0; } }

        

        

        

        public virtual void CountCard(Card card)

        {

            runningTotal += GetCounts()[(int)card.TrueValue];

            cardCount++;
 

            // Now keep side counts for all cards

            switch (card.CardValue)

            {

                case CardType.Ace:

                    acesCount++;

                    break;

                case CardType.Two:

                    twosCount++;

                    break;

                case CardType.Three:

                    threesCount++;

                    break;

                case CardType.Four:

                    foursCount++;

                    break;

                case CardType.Five:

                    fivesCount++;

                    break;

                case CardType.Six:

                    sixesCount++;

                    break;

                case CardType.Seven:

                    sevensCount++;

                    break;

                case CardType.Eight:

                    eightsCount++;

                    break;

                case CardType.Nine:

                    ninesCount++;

                    break;

                case CardType.Ten:

                    tensCount++;

                    break;

                case CardType.Jack:

                    tensCount++;

                    break;

                case CardType.Queen:

                    tensCount++;

                    break;

                case CardType.King:

                    tensCount++;

                    break;

            }

        }
 
 
 
 
 

        public virtual void Reset(int decks)

        {

            cardCount = 0;

            runningTotal = 0;

            acesCount = 0;

            twosCount = 0;

            threesCount = 0;

            foursCount = 0;

            fivesCount = 0;

            sixesCount = 0;

            sevensCount = 0;

            eightsCount = 0;

            ninesCount = 0;

            tensCount = 0;

            Decks = decks;

        }
 
 
 
 
 

        public virtual double Count

        {

            get { return runningTotal / ((Decks * 52 - cardCount) / 52); }

        }
 

        public static ArrayList GetMethods()

        {

            ArrayList methods = new ArrayList();
 

            methods.Add("Hi-Lo");

            methods.Add("High-Low");

            methods.Add("Hi Opt I");

            methods.Add("Hi Opt II");

            methods.Add("Silver Fox");

            methods.Add("Brh I");

            methods.Add("Brh II");

            methods.Add("Canfield Expert");

            methods.Add("Canfield Master");

            methods.Add("KO");

            methods.Add("Omega II");

            methods.Add("Red Seven");

            methods.Add("Revere Adv. Plus Minus");

            methods.Add("Revere Point Count");

            methods.Add("Unb. Zen 11");

            methods.Add("Uston Adv. Plus Minus");

            methods.Add("Uston APC");

            methods.Add("Uston SS");

            methods.Add("Wong Halves");

            methods.Add("Zen Count");

            methods.Add("Hi-Lo Ace Side Count");

            methods.Add("HiOptI Ace-Seven Side Count");
 

            return methods;

        }
 
 
 
 
 
 

        public static CountMethod NewMethod(string methodName, int n)

        {

            CountMethod returnValue = null;
 

            switch (methodName.ToLower())

            {

                case ("hi-lo"):

                    returnValue = new HiLo(n);

                    break;

                case ("high-low"):

                    returnValue = new HighLow(n);

                    break;

                case ("hi opt i"):

                    returnValue = new HiOptI(n);

                    break;

                case ("hi opt ii"):

                    returnValue = new HiOptII(n);

                    break;

                case ("silver fox"):

                    returnValue = new SilverFox(n);

                    break;

                case ("brh i"):

                    returnValue = new BrhI(n);

                    break;

                case ("brh ii"):

                    returnValue = new BrhII(n);

                    break;

                case ("canfield expert"):

                    returnValue = new CanfieldExpert(n);

                    break;

                case ("canfield master"):

                    returnValue = new CanfieldMaster(n);

                    break;

                case ("ko"):

                    returnValue = new KO(n);

                    break;

                case ("omega ii"):

                    returnValue = new OmegaII(n);

                    break;

                case ("red seven"):

                    returnValue = new RedSeven(n);

                    break;

                case ("revere adv. plus minus"):

                    returnValue = new RevereAdvPlusMinus(n);

                    break;

                case ("revere point count"):

                    returnValue = new ReverePointCount(n);

                    break;

                case ("unb. zen 11"):

                    returnValue = new UnbZen11(n);

                    break;

                case ("uston adv. plus minus"):

                    returnValue = new UstonAdvPlusMinus(n);

                    break;

                case ("uston apc"):

                    returnValue = new UstonApc(n);

                    break;

                case ("uston ss"):

                    returnValue = new UstonSS(n);

                    break;

                case ("wong halves"):

                    returnValue = new WongHalves(n);

                    break;

                case ("zen count"):

                    returnValue = new ZenCount(n);

                    break;

                case ("hi-lo ace side count"):

                    returnValue = new HiLoA(n);

                    break;

                case ("hiopti ace-seven side count"):

                    returnValue = new HiOptIA7(n);

                    break;

                default:

                    returnValue = null;

                    break;

            }
 

            return returnValue;

        }

    }
 
 
 
 
 
 
 

    [Serializable()]

    public class HiLo : CountMethod

    {

        public HiLo(int n)

            : base(n)

        {

        }
 

        protected override double[] GetCounts() { return counts; }

        // Card counts                             A  2  3  4  5  6  7  8  9  T

        protected double[] counts = new double[] { 0, 0, 1, 1, 1, 1, 0, 0, 0, -1 };

        private string name = "Hi-Lo";

        private int level = 1;

        public override string MethodName { get { return name; } }

        public override int MethodLevel { get { return level; } }

    }
 

    [Serializable()]

    public class HighLow : CountMethod

    {

        public HighLow(int n)

            : base(n)

        {

        }
 

        protected override double[] GetCounts() { return counts; }

        // Card counts                             A  2  3  4  5  6  7  8  9  T

        protected double[] counts = new double[] { -1, 1, 1, 1, 1, 1, 0, 0, 0, -1 };

        private string name = "High-Low";

        private int level = 1;

        public override string MethodName { get { return name; } }

        public override int MethodLevel { get { return level; } }

    }
 

    [Serializable()]

    public class HiOptI : CountMethod

    {

        public HiOptI(int n)

            : base(n)

        {

        }
 

        protected override double[] GetCounts() { return counts; }

        // Card counts                             A  2  3  4  5  6  7  8  9  T

        protected double[] counts = new double[] { 0, 0, 1, 1, 1, 1, 0, 0, 0, -1 };

        private string name = "HiOptI";

        private int level = 1;

        public override string MethodName { get { return name; } }

        public override int MethodLevel { get { return level; } }

    }
 

    [Serializable()]

    public class HiOptII : CountMethod

    {

        public HiOptII(int n)

            : base(n)

        {

        }
 

        protected override double[] GetCounts() { return counts; }

        // Card counts                             A  2  3  4  5  6  7  8  9  T

        protected double[] counts = new double[] { 0, 1, 1, 2, 2, 1, 1, 0, 0, -2 };

        private string name = "HiOptII";

        private int level = 2;

        public override string MethodName { get { return name; } }

        public override int MethodLevel { get { return level; } }

    }
 

    [Serializable()]

    public class SilverFox : CountMethod

    {

        public SilverFox(int n)

            : base(n)

        {

        }
 

        protected override double[] GetCounts() { return counts; }

        // Card counts                             A  2  3  4  5  6  7  8  9  T

        protected double[] counts = new double[] { -1, 1, 1, 1, 1, 1, 1, 0, -1, -1 };

        private string name = "Silver Fox";

        private int level = 1;

        public override string MethodName { get { return name; } }

        public override int MethodLevel { get { return level; } }

    }
 

    [Serializable()]

    public class BrhI : CountMethod

    {

        public BrhI(int n)

            : base(n)

        {

        }
 

        protected override double[] GetCounts() { return counts; }

        // Card counts                             A  2  3  4  5  6  7  8  9  T

        protected double[] counts = new double[] { -2, 1, 2, 2, 3, 2, 1, 0, 0, -2 };

        private string name = "BrhI";

        private int level = 3;

        public override string MethodName { get { return name; } }

        public override int MethodLevel { get { return level; } }

    }
 

    [Serializable()]

    public class BrhII : CountMethod

    {

        public BrhII(int n)

            : base(n)

        {

        }
 

        protected override double[] GetCounts() { return counts; }

        // Card counts                             A  2  3  4  5  6  7  8  9  T

        protected double[] counts = new double[] { -2, 1, 1, 2, 2, 2, 1, 0, 0, -2 };

        private string name = "BrhII";

        private int level = 2;

        public override string MethodName { get { return name; } }

        public override int MethodLevel { get { return level; } }

    }
 

    [Serializable()]

    public class CanfieldExpert : CountMethod

    {

        public CanfieldExpert(int n)

            : base(n)

        {

        }
 

        protected override double[] GetCounts() { return counts; }

        // Card counts                             A  2  3  4  5  6  7  8  9  T

        protected double[] counts = new double[] { 0, 0, 1, 1, 1, 1, 1, 0, -1, -1 };

        private string name = "Canfield Expert";

        private int level = 1;

        public override string MethodName { get { return name; } }

        public override int MethodLevel { get { return level; } }

    }
 

    [Serializable()]

    public class CanfieldMaster : CountMethod

    {

        public CanfieldMaster(int n)

            : base(n)

        {

        }
 

        protected override double[] GetCounts() { return counts; }

        // Card counts                             A  2  3  4  5  6  7  8  9  T

        protected double[] counts = new double[] { 0, 1, 1, 2, 2, 2, 1, 0, -1, -2 };

        private string name = "Canfield Master";

        private int level = 2;

        public override string MethodName { get { return name; } }

        public override int MethodLevel { get { return level; } }

    }
 

    [Serializable()]

    public class KO : CountMethod

    {

        public KO(int n)

            : base(n)

        {

        }
 

        protected override double[] GetCounts() { return counts; }

        // Card counts                             A  2  3  4  5  6  7  8  9  T

        protected double[] counts = new double[] { -1, 1, 1, 1, 1, 1, 1, 0, 0, -1 };

        private string name = "KO";

        private int level = 1;

        public override string MethodName { get { return name; } }

        public override int MethodLevel { get { return level; } }

    }
 

    [Serializable()]

    public class OmegaII : CountMethod

    {

        public OmegaII(int n)

            : base(n)

        {

        }
 

        protected override double[] GetCounts() { return counts; }

        // Card counts                             A  2  3  4  5  6  7  8  9  T

        protected double[] counts = new double[] { 0, 0, 1, 1, 1, 1, 1, 0, -1, -1 };

        private string name = "Omega II";

        private int level = 1;

        public override string MethodName { get { return name; } }

        public override int MethodLevel { get { return level; } }

    }
 

    [Serializable()]

    public class RedSeven : CountMethod

    {

        public RedSeven(int n)

            : base(n)

        {

        }
 

        protected override double[] GetCounts() { return counts; }

        // Card counts                             A  2  3  4  5  6  7  8  9  T

        protected double[] counts = new double[] { -1, 1, 1, 1, 1, 1, .5, 0, 0, -1 };

        private string name = "Red Seven";

        private int level = 1;

        public override string MethodName { get { return name; } }

        public override int MethodLevel { get { return level; } }

    }
 

    [Serializable()]

    public class RevereAdvPlusMinus : CountMethod

    {

        public RevereAdvPlusMinus(int n)

            : base(n)

        {

        }
 

        protected override double[] GetCounts() { return counts; }

        // Card counts                             A  2  3  4  5  6  7  8  9  T

        protected double[] counts = new double[] { 0, 1, 1, 1, 1, 1, 0, 0, -1, -1 };

        private string name = "Revere Adv. Plus Minus";

        private int level = 1;

        public override string MethodName { get { return name; } }

        public override int MethodLevel { get { return level; } }

    }
 

    [Serializable()]

    public class ReverePointCount : CountMethod

    {

        public ReverePointCount(int n)

            : base(n)

        {

        }
 

        protected override double[] GetCounts() { return counts; }

        // Card counts                             A  2  3  4  5  6  7  8  9  T

        protected double[] counts = new double[] { -2, 1, 2, 2, 2, 2, 1, 0, 0, -2 };

        private string name = "Revere Point Count";

        private int level = 2;

        public override string MethodName { get { return name; } }

        public override int MethodLevel { get { return level; } }

    }
 

    [Serializable()]

    public class UnbZen11 : CountMethod

    {

        public UnbZen11(int n)

            : base(n)

        {

        }
 

        protected override double[] GetCounts() { return counts; }

        // Card counts                             A  2  3  4  5  6  7  8  9  T

        protected double[] counts = new double[] { -1, 1, 2, 2, 2, 2, 1, 0, 0, -2 };

        private string name = "Unb. Zen 11";

        private int level = 2;

        public override string MethodName { get { return name; } }

        public override int MethodLevel { get { return level; } }

    }
 

    [Serializable()]

    public class UstonAdvPlusMinus : CountMethod

    {

        public UstonAdvPlusMinus(int n)

            : base(n)

        {

        }
 

        protected override double[] GetCounts() { return counts; }

        // Card counts                             A  2  3  4  5  6  7  8  9  T

        protected double[] counts = new double[] { -1, 0, 1, 1, 1, 1, 1, 0, 0, -1 };

        private string name = "Uston Adv. Plus Minus";

        private int level = 1;

        public override string MethodName { get { return name; } }

        public override int MethodLevel { get { return level; } }

    }
 

    [Serializable()]

    public class UstonApc : CountMethod

    {

        public UstonApc(int n)

            : base(n)

        {

        }
 

        protected override double[] GetCounts() { return counts; }

        // Card counts                             A  2  3  4  5  6  7  8  9  T

        protected double[] counts = new double[] { 0, 1, 2, 2, 3, 2, 2, 1, -1, -3 };

        private string name = "Uston APC";

        private int level = 3;

        public override string MethodName { get { return name; } }

        public override int MethodLevel { get { return level; } }

    }
 

    [Serializable()]

    public class UstonSS : CountMethod

    {

        public UstonSS(int n)

            : base(n)

        {

        }
 

        protected override double[] GetCounts() { return counts; }

        // Card counts                             A  2  3  4  5  6  7  8  9  T

        protected double[] counts = new double[] { -2, 2, 2, 2, 3, 2, 1, 0, -1, -2 };

        private string name = "Uston SS";

        private int level = 2;

        public override string MethodName { get { return name; } }

        public override int MethodLevel { get { return level; } }

    }
 

    [Serializable()]

    public class WongHalves : CountMethod

    {

        public WongHalves(int n)

            : base(n)

        {

        }
 

        protected override double[] GetCounts() { return counts; }

        // Card counts                             A  2  3  4  5  6  7  8  9  T

        protected double[] counts = new double[] { -1, .5, 1, 1, 1.5, 1, .5, 0, -.5, -1 };

        private string name = "Wong Halves";

        private int level = 1;

        public override string MethodName { get { return name; } }

        public override int MethodLevel { get { return level; } }

    }
 

    [Serializable()]

    public class ZenCount : CountMethod

    {

        public ZenCount(int n)

            : base(n)

        {

        }
 

        protected override double[] GetCounts() { return counts; }

        // Card counts                             A  2  3  4  5  6  7  8  9  T

        protected double[] counts = new double[] { -1, 1, 1, 2, 2, 2, 1, 0, 0, -2 };

        private string name = "Zen Count";

        private int level = 2;

        public override string MethodName { get { return name; } }

        public override int MethodLevel { get { return level; } }

    }
 

    [Serializable()]

    public class HiLoA : CountMethod

    {

        // The standard HiLo method with an Ace side count

        public HiLoA(int n)

            : base(n)

        {

        }
 

        protected override double[] GetCounts() { return counts; }

        // Card counts                             A  2  3  4  5  6  7  8  9  T

        protected double[] counts = new double[] { 0, 0, 1, 1, 1, 1, 0, 0, 0, -1 };

        public override double GetWager(double normalBet)

        {

            double wager = 0;

            double trueCount = Count;

            int aceCount = base.SideCount(CardType.Ace);
 

            double aceRatio = ((cardCount / 13.0) - aceCount) / ((Decks * 52 - cardCount) / 52.0);

            trueCount += aceRatio;
 

            if (trueCount > 0)

                wager = normalBet * trueCount;

            else if (trueCount == 0)

                wager = normalBet;

            else if (trueCount < 0)

                wager = normalBet * trueCount;
 

            // $10 table minimum :)  Also, round to nearest integer

            wager = (int)Math.Max(10, wager);
 

            return wager;

        }
 

        private string name = "Hi-Lo Ace Side Count";

        private int level = 1;

        public override string MethodName { get { return name; } }

        public override int MethodLevel { get { return level; } }

    }
 

    [Serializable()]

    public class HiOptIA7 : CountMethod

    {

        public HiOptIA7(int n)

            : base(n)

        {

        }
 

        protected override double[] GetCounts() { return counts; }

        // Card counts                             A  2  3  4  5  6  7  8  9  T

        protected double[] counts = new double[] { 0, 0, 1, 1, 1, 1, 0, 0, 0, -1 };

        public override double GetWager(double normalBet)

        {

            double wager = 0;

            double trueCount = Count;

            int aceCount = base.SideCount(CardType.Ace);

            int sevenCount = base.SideCount(CardType.Seven);
 

            double aceRatio = ((cardCount / 13.0) - aceCount) / ((Decks * 52 - cardCount) / 52.0);

            double sevenRatio = ((cardCount / 13.0) - sevenCount) / ((Decks * 52 - cardCount) / 52.0);

            trueCount += aceRatio;

            trueCount += sevenRatio;
 

            if (trueCount > 0)

                wager = normalBet * trueCount;

            else if (trueCount == 0)

                wager = normalBet;

            else if (trueCount < 0)

                wager = normalBet * trueCount;
 

            // $10 table minimum :)  Also, round to nearest integer

            wager = (int)Math.Max(10, wager);
 

            return wager;

        }
 

        private string name = "Hi Opt I Ace Seven side counts";

        private int level = 1;

        public override string MethodName { get { return name; } }

        public override int MethodLevel { get { return level; } }

    }
 

}
 
 

-------------------------------------------

Dealer.cs

------------------------------------------

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Drawing;
 

namespace CardGameClassLib

{

    public class Dealer

    {

        private Hand dealerHand;

        private Point location;
 
 

        public Dealer(Point pntlocation)

        {

            // Tell the dealer where his origin point is

            location = pntlocation;
 

            // Create a hand for the dealer and locate its origin at the dealer's origin

            dealerHand = new Hand(new Point(0, 0));

        }
 

        public void Reset()

        {

            // Get a new hand for each round

            dealerHand = new Hand();

        }
 

        public void AddCard(Card card)

        {

            // Take a card

            dealerHand.Add(card);

        }
 

        public int Total()

        {

            // The dealer's total is his hand's total.  This is just a shortcut to it.

            return dealerHand.Total();

        }
 

        public Hand Hand

        {

            get { return dealerHand; }

        }
 

        public void DrawHand(Graphics drawingSurface, bool displayDownCard)

        {

            // Draw the dealer's hand on the drawing surface

            bool firstCard = true;
 

            // Not really necessary for the dealer since he only has one hand, but...

            int x = this.location.X + dealerHand.HandLocation.X;

            int y = this.location.Y + dealerHand.HandLocation.Y;
 

            // We have to check to see if the dealer has any cards because this routine

            // gets called every time the screen needs to repaint.

            if (dealerHand.Count > 0)

            {

                // We don't draw the dealer's label until it's time to show their down card

                if (displayDownCard)

                    drawingSurface.DrawString(dealerHand.Label(true), new Font("Arial", 8, FontStyle.Bold), new SolidBrush(Color.Yellow), x - 10, y - 10);
 

                // Move down and to the right

                x += (int)Card.cardSpacing.Width;

                y += (int)Card.cardSpacing.Height;
 

                // Now draw each of the dealer's cards

                foreach (Card card in dealerHand)

                {

                    if (card != null)

                    {

                        card.Draw(drawingSurface, new Point(x, y), !firstCard || displayDownCard, false, false);

                        firstCard = false;

                        x += (int)Card.cardSpacing.Width;

                        y += (int)Card.cardSpacing.Height;

                    }

                }

            }

        }

    }

}
 

-------------------------------------------

Deck.cs

-------------------------------------------

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;
 

namespace CardGameClassLib

{

    public class Deck

    {

        private const int		CARDSPERDECK = 52;

		private Card[]			cards;

		private int				numberOfDecks = 5;

        private int             deckLocation;
 

        // A delegate type for hooking up change notifications.

		public delegate void DeckEventHandler(object sender, EventArgs e);

		

		public event DeckEventHandler EndOfDeckEvent;

		public event DeckEventHandler ShuffleEvent;
 
 

        public Deck()

        {

            Init();

        }
 
 

        public void Init()

        {

            deckLocation = 0;
 

            cards = new Card[numberOfDecks * CARDSPERDECK];

            int current = 0;

            

            for (int j = 0; j < numberOfDecks; j++)

            {

                for (int y = 0; y < 4; y++)

                {

                    for (int x = 0; x < 13; x++)

                    {                       

                        cards[current++] = new Card((CardType)x, (Suit)y);

                    }

                }

            }

        }
 

        

		
 

		

        /// <summary>

        /// 

        /// </summary>

		public int NumberOfDecks 

		{

			get 

			{ 

				return numberOfDecks;	

			}

			set 

			{

				if (numberOfDecks != value) 

					numberOfDecks = value;

			}

		}
 
 

        //	End-of-Deck property

        public bool Eod

        {

            get { return (deckLocation >= cards.Length * .66); }

        }
 

        //	Beginning-of-Deck property

        public bool Bod

        {

            get { return (deckLocation == 0); }

        }
 

		public void Shuffle()

		{

			Random rand = new Random(unchecked((int)DateTime.Now.Ticks)); 
 

			for( int i = 0; i < rand.Next(10,100); i++ )

			{

				Card[] shuffledCards = new Card[ numberOfDecks * CARDSPERDECK ];

		

				Random index = new Random(unchecked((int)DateTime.Now.Ticks)); 

				int upperLimit = cards.GetUpperBound(0);
 

				for( int j = 0; j < numberOfDecks * CARDSPERDECK; j++ )

				{

					int k = index.Next(0, upperLimit);

					shuffledCards[j] = cards[k];

					cards[k] = cards[upperLimit--];

				}
 

				cards = shuffledCards;

			}

            deckLocation = 0;
 

			ShuffleEvent(this, EventArgs.Empty );

		}
 
 
 

		//	Indexer

		public Card this[int index] 

		{	

			get 

			{

				if (index < 0 || index > 52)

					throw new ArgumentOutOfRangeException();

				else

					return cards[index];

			}

		}
 

		public Card Next()

		{

			if( deckLocation < cards.GetUpperBound(0) )

			{

				if( Eod )

					EndOfDeckEvent(this, EventArgs.Empty );
 

				return cards[deckLocation++];

			}

			else

			{

				// It shouldn't come to this, but in the unlikely event that we

				// run out of cards, reshuffle the shoe.

				Shuffle();

				return cards[deckLocation++];

			}

		}
 

		

     

    }
 

}
 

------------------------------------------

Enum.cs

-----------------------------------------

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;
 

namespace CardGameClassLib

{

    public enum Suit

    {

        Clubs = 0,

        Diamonds = 1,

        Hearts = 2,

        Spades = 3

    }
 

    public enum CardType

    {

        Ace = 0,

        Two = 1,

        Three = 2,

        Four = 3,

        Five = 4,

        Six = 5,

        Seven = 6,

        Eight = 7,

        Nine = 8,

        Ten = 9,

        Jack = 10,

        Queen = 11,

        King = 12

    }
 

    public enum playerType

    {

        computer = 0,

        human = 1

    }
 

    public enum LabelType

    {

        none = 0,

        drawToHand = 1,

        bothHands = 2,

        outcome = 3

    }
 
 

    public enum OutcomeType

    {

        None = 0,

        Won = 1,

        Lost = 2,

        Push = 3,

        Blackjack = 4

    }

}
 

---------------------------------------------

Hand.cs

--------------------------------------------

using System;

using System.Collections.Generic;

using System.Collections;

using System.Linq;

using System.Text;

using System.Globalization;

using System.Drawing;
 

namespace CardGameClassLib

{

    public class Hand : IList, IEnumerable

    {

        // A hand consists of an array of cards

        private Card[] cards;

        // Indicates the next position in the cards array

        private int cardPosition;

        // How much is wagered on this hand of Blackjack

        private double wager;

        // Indicates the player doubled this hand so we can draw the last card on an angle

        private bool doubled;

        // The most cards allowed in a single hand of Blackjack is 12 so we can hard code that

        protected const int maxCardPosition = 12;

        //	How much to increase our array in response to Adds

        private const int RESIZEAMOUNT = 5;

        // Where is this hand to be drawn on the screen

        private Point location;
 

        public Hand()

        {

            // Setup an array of cards

            cards = new Card[RESIZEAMOUNT];
 

            // Flag indicates double down wager.  Last card is drawn tilted at an angle.

            doubled = false;
 

            // Reset the position within the array

            cardPosition = 0;
 

            // Reset the wager for this hand

            wager = 0;

        }
 
 

        public Hand(int size)

        {

            //	Acceptable sizes are 1 - 12

            if (size > 0 && size < 13)

                cards = new Card[size];

            else

                cards = new Card[RESIZEAMOUNT];
 

            // Flag indicates double down wager.  Last card is drawn tilted at an angle.

            doubled = false;
 

            // Reset the position within the array

            cardPosition = 0;
 

            // Reset the wager for this hand

            wager = 0;

        }
 
 

        public Hand(Point pntLocation)

        {

            // Store the location to draw the hand on the surface

            location = pntLocation;

            // Setup an array of cards

            cards = new Card[RESIZEAMOUNT];

            // Flag indicates double down wager.  Last card is drawn tilted at an angle.

            doubled = false;

            // Reset the position within the array

            cardPosition = 0;

            // Reset the wager for this hand

            wager = 0;

        }
 

        public Point HandLocation

        {

            get { return location; }

            set { location = value; }

        }
 

        public Card[] Cards 

        { 

            get { return cards; }

            set { cards = value; }

        }
 
 

        public double Wager

        {

            get { return wager; }

            set { wager = value; }

        }
 

        public bool Doubled

        {

            get { return doubled; }

            set { doubled = value; }

        }
 
 
 

        /// <summary>

        /// Determine if the hand is a pair

        /// </summary>

        public bool IsPair

        {

            get

            {

                if (cardPosition == 2)

                {

                    if (cards[0].CardValue == cards[1].CardValue)

                    {

                        return true;

                    }

                    else

                    {

                        return false;

                    }

                }

                else

                {

                    return false;

                }

            }

        }
 
 
 
 
 
 
 

        /// <summary>

        /// Determines if the hand has aces that, when valued at 11,

        /// do not make the hand exceed 21

        /// </summary>

        public bool IsSoft

        {

            get

            {

                int total = 0;

                int aceCount = 0;

                int cardCount = 0;
 

                foreach (Card card in cards)

                {

                    if (card != null)

                    {

                        cardCount++;

                        switch (card.CardValue)

                        {

                            case CardType.Ace:

                                total += 11;

                                aceCount++;

                                break;

                            case CardType.Ten:

                                total += 10;

                                break;

                            default:

                                total += card.TrueValue + 1;

                                break;

                        }

                    }

                }
 

                if (total > 21)

                {

                    foreach (Card card in cards)

                    {

                        if (card != null)

                        {

                            if (card.CardValue == CardType.Ace)

                            {

                                aceCount--;

                                total -= 10;

                            }
 

                            if (total <= 21)

                                break;
 

                        }

                    }

                }

                return aceCount > 0;

            }

        }
 
 
 
 

        public bool IsBlackjack()

        {

            return this.Total() == 21 && cardPosition == 2;

        }
 
 
 
 
 

        public int Total()

        {

            int total = 0;

            int aceCount = 0;

            int cardCount = 0;
 

            foreach (Card card in cards)

            {

                if (card != null)

                {

                    cardCount++;

                    switch (card.CardValue)

                    {

                        case CardType.Ace:

                            total += 11;

                            aceCount++;

                            break;

                        case CardType.Ten:

                            total += 10;

                            break;

                        default:

                            total += card.TrueValue + 1;

                            break;

                    }

                }

            }
 

            if (total > 21)

            {

                foreach (Card card in cards)

                {

                    if (card != null)

                    {

                        if (card.CardValue == CardType.Ace)

                        {

                            aceCount--;

                            total -= 10;

                        }
 

                        if (total <= 21)

                            break;
 

                    }

                }

            }

            return total;

        }
 
 
 
 
 

        public string Label(bool possibleBJ)

        {

            int total = 0;

            int aceCount = 0;

            int cardCount = 0;
 

            foreach (Card card in cards)

            {

                if (card != null)

                {

                    cardCount++;

                    switch (card.CardValue)

                    {

                        case CardType.Ace:

                            total += 11;

                            aceCount++;

                            break;

                        case CardType.Ten:

                            total += 10;

                            break;

                        default:

                            total += card.TrueValue + 1;

                            break;

                    }

                }

            }
 

            if (total > 21)

            {

                foreach (Card card in cards)

                {

                    if (card != null)

                    {

                        if (card.CardValue == CardType.Ace)

                        {

                            aceCount--;

                            total -= 10;

                        }
 

                        if (total <= 21)

                            break;
 

                    }

                }

            }
 
 
 

            string returnValue = "";

            if (total == 21 && cardCount == 2 && possibleBJ)

                returnValue = "Blackjack";

            else if (aceCount > 0 && cardCount > 1)

                returnValue = "soft " + total.ToString(CultureInfo.InvariantCulture);

            else if (total > 21)

                returnValue = "BUST";

            else

                returnValue = total.ToString(CultureInfo.InvariantCulture);
 

            return returnValue;

        }
 
 
 

        public OutcomeType Outcome(Hand dealerHand, int numberOfHands)

        {

            OutcomeType returnValue = OutcomeType.None;
 

            bool dealerBlackjack = dealerHand.Total() == 21 && dealerHand.Count == 2;

            if (this.Total() > 0)

            {

                if (Total() > 21)

                    returnValue = OutcomeType.Lost;

                else if (IsBlackjack() && !dealerBlackjack && numberOfHands == 1)

                    returnValue = OutcomeType.Blackjack;

                else if (dealerHand.Total() > 21)

                    returnValue = OutcomeType.Won;

                else if (Total() < dealerHand.Total())

                    returnValue = OutcomeType.Lost;

                else if (Total() > dealerHand.Total())

                    returnValue = OutcomeType.Won;

                else if (Total() == dealerHand.Total())

                    returnValue = OutcomeType.Push;

            }
 

            return returnValue;

        }
 
 
 
 
 

         //	IList

        Object IList.this[int index]

        {

            get

            {

                if (index < 0 || index > cardPosition)

                    throw new System.IndexOutOfRangeException("index");

                else

                    return cards[index];

            }
 

            set

            {

                if (index < 0 || index > cardPosition)

                    throw new System.IndexOutOfRangeException("index");

                else

                    cards[index] = (Card)value;

            }

        }
 

        public Card this[int index]

        {

            get

            {

                if (index < 0 || index > cardPosition)

                    throw new System.IndexOutOfRangeException("index");

                else

                    return cards[index];

            }
 

            set

            {

                if (index < 0 || index > cardPosition)

                    throw new System.IndexOutOfRangeException("index");

                else

                    cards[index] = (Card)value;

            }

        }
 
 

        public bool IsFixedSize

        {

            get { return false; }

        }
 
 
 

        public bool IsReadOnly

        {

            get { return false; }

        }
 
 
 
 

        

        int IList.Add(Object card)

        {

            Card crd = card as Card;
 

            if (crd == null)

                throw new InvalidCastException("You can only add Cards to a hand.");
 

            return Add(crd);

        }
 
 
 
 
 

        public int Add(Card card)

        {

            if (cardPosition == cards.Length - 1)

            {

                //	Create a new larger array and copy the 

                //	elements into it

                int newSize = cardPosition + RESIZEAMOUNT;

                Card[] tmpCards = new Card[newSize];
 

                Array.Copy(cards, 0, tmpCards, 0, cards.Length);

                cards = tmpCards;

            }
 

            //	Add the card to the array

            cards[cardPosition++] = card;
 

            //	Return the new cards index

            return cardPosition - 1;

        }
 
 
 
 
 

        bool IList.Contains(Object card)

        {

            Card crd = card as Card;
 

            if (crd == null)

                return false;

            else

                return Contains(crd);

        }
 
 
 
 

        public bool Contains(Card card)

        {

            for (int x = 0; x < cards.Length; x++)

            {

                if (cards[x].Value == card.Value)

                    return true;

            }
 

            return false;

        }
 
 
 
 

        int IList.IndexOf(Object card)

        {

            Card crd = card as Card;
 

            if (crd == null)

                return -1;

            else

                return IndexOf(crd);

        }
 
 
 
 

        public int IndexOf(Card card)

        {

            for (int x = 0; x < cards.Length; x++)

            {

                if (cards[x].Value == card.Value)

                    return x;

            }
 

            return -1;

        }
 
 
 
 

        void IList.Insert(int index, Object card)

        {

            Card crd = card as Card;
 

            if (crd == null)

                throw new InvalidCastException("You can only add Cards to a hand.");
 

            Insert(index, crd);

        }
 
 
 
 

        void Insert(int index, Card card)

        {

            if (index < 0 || index > cardPosition)

                throw new System.IndexOutOfRangeException("index");
 

            int newSize;
 

            if (cardPosition == cards.Length - 1)

                newSize = cardPosition + RESIZEAMOUNT;

            else

                newSize = cardPosition;
 

            Card[] tmpCards = new Card[newSize];
 

            Array.Copy(cards, 0, tmpCards, 0, index);

            tmpCards[index] = card;

            index++;

            Array.Copy(cards, index, tmpCards, index, cards.Length - index);
 

            cards = tmpCards;

            cardPosition++;

        }
 
 
 
 
 

        void IList.Remove(Object card)

        {

            Card crd = card as Card;
 

            if (crd != null)

                Remove(crd);

        }
 
 
 
 

        public void Remove(Card card)

        {

            int idx = this.IndexOf(card);
 

            if (idx >= 0)

            {

                this.RemoveAt(idx);

            }

        }
 
 
 

        public void RemoveAt(int index)

        {

            if (index < 0 || index > cardPosition)

                throw new System.IndexOutOfRangeException("You have specified an invalid index");

            else

            {

                Card[] aTmp = new Card[cards.Length];
 

                if (index > 0)

                    Array.Copy(cards, 0, aTmp, 0, index);
 

                int newStart = index + 1;

                if (newStart < cards.Length)

                    Array.Copy(cards, newStart, aTmp, index, cards.Length - newStart);
 

                cardPosition--;
 

                cards = aTmp;

            }

        }
 
 
 
 

        public void Clear()

        {

            cards = new Card[RESIZEAMOUNT];

            cardPosition = 0;

        }
 
 
 
 
 

        //	ICollection

        void ICollection.CopyTo(Array array, int index)

        {

            if (index < 0)

                throw new ArgumentOutOfRangeException("Index cannot be negative.");
 

            if (array == null)

                throw new ArgumentNullException();
 

            if (array.GetLowerBound(0) != 0 || array.Rank > 1)

                throw new ArgumentException("Only zero-based, single-dimensioned arrays permitted.");
 

            if (array.Length >= index || array.Length - index < cards.Length)

                throw new ArgumentException();
 

            Array.Copy(cards, 0, array, index, cards.Length);

        }
 

        public void CopyTo(Card[] array, int index)

        {

            if (index < 0)

                throw new ArgumentOutOfRangeException("Index cannot be negative.");
 

            if (array == null)

                throw new ArgumentNullException();
 

            if (array.GetLowerBound(0) != 0 || array.Rank > 1)

                throw new ArgumentException("Only zero-based, single-dimensioned arrays permitted.");
 

            if (array.Length >= index || array.Length - index < cards.Length)

                throw new ArgumentException();
 

            Array.Copy(cards, 0, array, index, cards.Length);

        }
 
 
 

        public bool IsSynchronized

        {

            get { return true; }

        }
 

        public Object SyncRoot

        {

            get { return cards.SyncRoot; }

        }
 
 

        public int Count

        {

            get { return cardPosition; }

        }
 
 
 
 
 

        //	IEnumerable

        IEnumerator IEnumerable.GetEnumerator()

        {

            return cards.GetEnumerator();

        }
 
 
 
 

        public CardEnumerator GetEnumerator()

        {

            return new CardEnumerator(cards);

        }

    }
 

    public class CardEnumerator

    {

        private IEnumerator enumerator;
 

        //	No default construction

        private CardEnumerator() { }
 

        //	Can be created only inside this assembly

        internal CardEnumerator(IEnumerable parent)

        {

            enumerator = parent.GetEnumerator();

        }
 

        public void Reset()

        {

            enumerator.Reset();

        }
 

        public Card Current

        {

            get { return (Card)enumerator.Current; }

        }
 

        public bool MoveNext()

        {

            return enumerator.MoveNext();

        }
 
 
 

    }

}
 
 

--------------------------------------------

Player.cs

--------------------------------------------

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Drawing;

using System.Globalization;
 

namespace CardGameClassLib

{

    public class Player

    {
 

        private double bank;

        private bool insurance = false;

        private bool showBank = true;

        private bool showCardCount = true;

        private bool showCardTotal = true;

        private int currentHandIndex = 0;

        private Hand[] hands;

        private int numberOfHands = 1;

        private playerType plyrType;

        private bool active = true;

        private CountMethod plyrMethod;

        private double plyrBet = 10;

        private Point location;

        private string backgroundImage;
 
 

        public Player(Point pntlocation, double dblBank, playerType type, CountMethod method)

        {

            // Since the game is limited to one split (two hands), just set them up now

            hands = new Hand[2];

            hands[0] = new Hand(new Point(0, 0));

            hands[1] = new Hand(new Point(50, 0));
 

            // Player specific variables

            location = pntlocation;

            bank = dblBank;

           

            plyrMethod = method;

            plyrType = type;

            
 

            // Start out with one hand, they may split pairs to get two

            numberOfHands = 1;

        }
 

        public void DrawBackground(Graphics drawingSurface, Card dealerCard)

        {

            Bitmap backgroundImage = new Bitmap("C:\\Documents and Settings\\MFL\\Dokumenter\\Visual Studio 2008\\Projects\\Black_Jack\\Black_Jack\\images\\player1_back_hit.gif");

   

            drawingSurface.DrawImage((backgroundImage), location);

        }
 

        public bool Active

        {

            get

            {

                return active;

            }

            set

            {

                active = value;

            }

        }
 

        public playerType Type

        {

            get { return plyrType; }

            set { plyrType = value; }

        }
 

        public Hand[] GetHands()

        {

            return hands;

        }
 

        public int NumberOfHands

        {

            get { return numberOfHands; }

        }
 

        public Hand CurrentHand

        {

            // This is just a shortcut to get to the current hand being played

            get { return hands[currentHandIndex]; }

        }
 

        public bool ShowBank

        {

            get

            {

                return showBank;

            }

            set

            {

                showBank = value;

            }

        }
 

        public bool ShowCardCount

        {

            get

            {

                return showCardCount;

            }

            set

            {

                showCardCount = value;

            }

        }
 

        public bool ShowCardTotal

        {

            get

            {

                return showCardTotal;

            }

            set

            {

                showCardTotal = value;

            }

        }
 

        public void ResetCount(int decks)

        {

            if (plyrMethod != null)

                plyrMethod.Reset(decks);

        }
 

        public void Won(Hand hand)

        {

            // Since the bet is taken from the bank at the beginning of play,

            // give back twice as much on a win.

            bank += hand.Wager * 2;

        }
 
 

        public void CountCard(Card newCard)

        {

            if (plyrMethod != null)

                plyrMethod.CountCard(newCard);

        }
 

        public void Blackjack(Hand hand)

        {

            // Since the bet is taken from the bank at the beginning of play,

            // give it back plus 1.5 times the wager.

            bank += hand.Wager + hand.Wager * 1.5;

        }
 

        public void Push(Hand hand)

        {

            // Since the bet is taken from the bank at the beginning of play,

            // give it back on a push.

            bank += hand.Wager;

        }
 

        public bool Insurance

        {

            get

            {

                return insurance;

            }

            set

            {

                insurance = value;

            }

        }
 

        public void LostInsurance()

        {

            // You can only lose your insurance bet if you made one.

            if (insurance)

                bank -= hands[0].Wager / 2;

        }
 

        public void WonInsurance()

        {

            // You can only win your insurance bet if you made one.

            if (insurance)

                bank += hands[0].Wager;

        }
 
 

        /// <summary>

        /// This version of DrawBackground is used during an insurance round

        /// </summary>

        /// <param name="drawingSurface"></param>

        public void DrawBackground(Graphics drawingSurface, bool insurance)

        {

           Bitmap cardImage = new Bitmap("C:\\Documents and Settings\\MFL\\Dokumenter\\Visual Studio 2008\\Projects\\Black_Jack\\Black_Jack\\images\\marker");
 

           drawingSurface.DrawImage(cardImage, location);

      

        }
 
 

        public void Reset()

        {

            // This method is called at the beginning of a new hand.

            hands = new Hand[2];

            hands[0] = new Hand();

            hands[1] = new Hand();
 

            // Reset variables that keep track of play

            numberOfHands = 1;

            currentHandIndex = 0;
 

            // Reset insurance

            insurance = false;

        }
 
 
 

        public bool CanDouble(Hand hand)

        {

            return (((hand.Total() >= 7 && hand.Total() <= 11) || hand.IsSoft) && hand.Count == 2);

        }
 

        public bool DoubleDown(Hand hand)

        {

            // This method determines whether a double-down is possible and, 

            // if so, doubling the bet.

            if (CanDouble(hand))

            {

                // Reduce the bank

                bank -= hand.Wager;
 

                // Double the bet

                hand.Wager *= 2;
 

                // Mark the hand as doubled so the last card is drawn at an angle

                hand.Doubled = true;
 

                // Tell the form that we doubled.  The form then moves on to the next player.

                return true;

            }

            return false;

        }
 

        public bool CanSplit()

        {

            return (hands[0].IsPair && numberOfHands == 1);

        }
 

        public bool Split()

        {

            // This method determines if a split is possible and,

            // if so, create the new hand and double the bet

            if (CanSplit())

            {

                

                // Put the second card of the first hand into the first card of the second hand

                hands[1].Add(hands[0][1]);

                // Remove the card from the first hand

                hands[0].RemoveAt(hands[0].Count);

                // Make the second hand's wager equal to the first

                hands[1].Wager = hands[0].Wager;

                // Decrement the bank accordingly

                bank -= hands[1].Wager;

                // increase the number of hands

                numberOfHands++;

                // Tell the form that the split was successful

                return true;

            }

            return false;

        }
 

        public void NextHand()

        {

            // This is just a shortcut to incrementing the hand index

            currentHandIndex++;

        }
 

        public bool LastHand()

        {

            // This is a convenient way to determine if the player has any more

            // hands to draw to.

            return currentHandIndex + 1 == numberOfHands;

        }
 

        public double TotalWager()

        {

            // The total wager for the player is the sum of all the hand's wagers

            double wager = 0;
 

            foreach (Hand hand in hands)

            {

                wager += hand.Wager;

            }
 

            return wager;

        }
 
 

        public void GetWager()

        {

            // Reset the wager to match what the user entered.

            if (plyrType == playerType.computer && plyrMethod != null)

                hands[0].Wager = plyrMethod.GetWager((double)plyrBet);

            else

                hands[0].Wager = (double)plyrBet;
 

            // Reduce the bank up front

            bank -= hands[0].Wager;

        }
 
 

        public double Bet

        {

            get { return plyrBet; }

        }
 
 

        public void DrawHands(Graphics drawingSurface, LabelType labelType, Hand dealerHand, bool currentPlayer)

        {

            // This routine is responsible for drawing the player's cards and the appropriate label

            foreach (Hand hand in hands)

            {

                // Increment the drawing position

                int x = location.X + hand.HandLocation.X;

                int y = location.Y + hand.HandLocation.Y;
 

                // Make sure there are cards in the hand to draw.

                if (hand.Count > 0)

                {

                    // Draw the appropriate label type in the upper left corner

                    switch (labelType)

                    {

                        case LabelType.none:

                            break;

                        case LabelType.bothHands:

                            if (showCardTotal)

                                drawingSurface.DrawString(hand.Label(numberOfHands == 1), new Font("Arial", 8, FontStyle.Bold), new SolidBrush(Color.Yellow), x - 10, y - 20);

                            break;

                        case LabelType.drawToHand:

                            if (hand == CurrentHand || !currentPlayer)

                                if (showCardTotal)

                                    drawingSurface.DrawString(hand.Label(numberOfHands == 1), new Font("Arial", 8, FontStyle.Bold), new SolidBrush(Color.Yellow), x - 10, y - 20);

                            break;

                        case LabelType.outcome:

                            switch (hand.Outcome(dealerHand, numberOfHands))

                            {

                                case OutcomeType.Won:

                                case OutcomeType.Blackjack:

                                    drawingSurface.DrawString("WON", new Font("Arial", 8, FontStyle.Bold), new SolidBrush(Color.LimeGreen), x - 10, y - 20);

                                    break;

                                case OutcomeType.Lost:

                                    if (insurance)

                                    {

                                        drawingSurface.DrawString("INSURED", new Font("Arial", 8, FontStyle.Bold), new SolidBrush(Color.Yellow), x - 10, y - 20);

                                    }

                                    else

                                    {

                                        drawingSurface.DrawString("LOST", new Font("Arial", 8, FontStyle.Bold), new SolidBrush(Color.Crimson), x - 10, y - 20);

                                    }

                                    break;

                                case OutcomeType.Push:

                                    drawingSurface.DrawString("PUSH", new Font("Arial", 8, FontStyle.Bold), new SolidBrush(Color.Yellow), x - 10, y - 20);

                                    break;

                            }

                            break;

                    }
 

                    // Increment the drawing position

                    x += (int)Card.cardSpacing.Width;

                    y += (int)Card.cardSpacing.Height;
 

                    // Draw the cards.

                    int cardNumber = 0;

                    foreach (Card card in hand)

                    {

                        if (card != null)

                        {

                            cardNumber++;

                            card.Draw(drawingSurface, new Point(x, y), true, currentPlayer && hand != CurrentHand, hand.Doubled && cardNumber == 3);

                            x += (int)Card.cardSpacing.Width;

                            y += (int)Card.cardSpacing.Height;

                        }

                    }

                }

            }
 

            // Draw the bet

            drawingSurface.DrawString("$" + TotalWager().ToString(CultureInfo.InvariantCulture), new Font("Arial", 8, FontStyle.Bold), new SolidBrush(Color.DarkKhaki), location.X + 110, location.Y - 20);
 

            // Draw the bank

            if (showBank)

                drawingSurface.DrawString("$" + bank.ToString(CultureInfo.InvariantCulture), new Font("Arial", 8, FontStyle.Bold), new SolidBrush(Color.DarkKhaki), location.X + 130, location.Y);
 

            // Draw the running card count

            if (plyrMethod != null && showCardCount)

            {

                //drawingSurface.DrawString( plyrMethod.MethodName, new Font("Arial",6,FontStyle.Bold), new SolidBrush(Color.DarkKhaki), location.X+140, location.Y+20 );

                drawingSurface.DrawString(plyrMethod.GetWager((double)plyrBet).ToString("F0"), new Font("Arial", 6, FontStyle.Bold), new SolidBrush(Color.DarkKhaki), location.X + 140, location.Y + 20);

                drawingSurface.DrawString(plyrMethod.Count.ToString("F1", CultureInfo.InvariantCulture), new Font("Arial", 6, FontStyle.Bold), new SolidBrush(Color.DarkKhaki), location.X + 145, location.Y + 40);

            }
 

        }
 

    }

}

Open in new window

0
Comment
Question by:Mickeys
  • 3
  • 2
5 Comments
 
LVL 6

Expert Comment

by:Chuck Yetter
ID: 24858824
First create class variables:  
Bitmap bg = null;
Bitmap copyOfBg = null;//keep a clean copy of the background.

Then in Form1() add:
copyOfBg =  new Bitmap(this.BackgroundImage);
bg = new Bitmap(this.BackgroundImage);

You want to draw on the background image,  but keep a copy of the original background image to clear the screen later.

Then in Form1_Paint():
Don't draw on e.Graphics, draw on the backgroundImage graphics:
Graphics drawingSurface = Graphics.FromImage(bg);

...(your drawing code here)...

Then set your background to bg:
 this.BackgroundImage(or whatever you are drawing to) = bg;

To clear just set this.BackgroundImage =  copyOfBg;
0
 

Author Comment

by:Mickeys
ID: 24861192
hmmm I cant get it to work. You are more than welcome to show me how in my code. I have tried and It still gets the same. My cards doesnt show up
0
 
LVL 6

Expert Comment

by:Chuck Yetter
ID: 24862612
I have Visual Studio 2005.  I managed to import the project (is it 2008?) but it has an unhandled ArgumentException at private Deck deck =  new Deck();  I can't run the app to debug the drawing problem :(

Try this to see what I am talking about above:  
Create a new Visual Studio Windows Application solution.  Set the Form1.BackgroundImage to some image file.  Add a small bitmap to the project and call it Bitmap1.bmp.  Use the code in the snippet below.  You should be able to figure out how it works.  You draw on the bitmap of the background (or a copy of it), then replace the Form1.BackgroundImage with the one you drew on.  The drawn image stays on the background until you replace it.

I'm working on a solitaire card game and had to use this method, otherwise whatever I drew on the PictureBox's Graphics object disappeared when the PictureBox refreshed/painted/etc.
using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;
 

namespace WindowsApplication1

{

    public partial class Form1 : Form

    {

        Bitmap bg = null;

        public Form1()

        {

            InitializeComponent();

            bg = new Bitmap(this.BackgroundImage);

        }
 

        private void Form1_Paint(object sender, PaintEventArgs e)

        {

            Graphics drawingSurface = Graphics.FromImage(bg);

            Bitmap bmp = new Bitmap("Bitmap1.bmp");

            drawingSurface.DrawImage(bmp, 20, 20);

            this.BackgroundImage = bg;

        }

    }

}

Open in new window

0
 

Author Comment

by:Mickeys
ID: 24866922
I did get your code above to run.....but I cant get my own to do the same.  You better run and buy VS2008 :-)


So what I did.....I removed the background picture just to get my cards out....but still it is the same. I get my cards but the picture is still a little bit of the background I have removed. I dont understand anything.
           

0
 
LVL 6

Accepted Solution

by:
Chuck Yetter earned 500 total points
ID: 24869476
In Form1_Paint() you create a new bitmap for the background.  Move this code to the form constructor or somewhere similar.  I suspect you draw your cards on the background, but then it is erased because you create a new background again when the event handler fires.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now