Ejemplo n.º 1
0
        //TODO: Add this method to the person class. Link controls to class directly.
        private void EmptyHand(Person targetperson, List<Card> discard)
        {
            List<Card> CurrentHand = targetperson.Hand;
            PictureBox[] CardImageDisplay = targetperson.CardImageArray;
            while (targetperson.Hand.Count > 0)
            {
                Card CardToTransfer = CurrentHand[0];
                discard.Add(CardToTransfer);
                CurrentHand.RemoveAt(0);
            }

            for (int indexcounter = 0; indexcounter < CardImageDisplay.Length; indexcounter++)
            {
                CardImageDisplay[indexcounter].Image = null;
                CardImageDisplay[indexcounter].Visible = false;
            }

            UpdatePlayerHandValue();
            UpdateDealerHandValue();
        }
Ejemplo n.º 2
0
        //TODO: Add this method to the Player class.
        private void Hit(Person targetperson)
        {
            if (btnDoubleDown.Enabled)
                btnDoubleDown.Enabled = false;

            DealCard(targetperson);

            if (GetHandValue(targetperson.Hand) > 21)
            {
                if (targetperson.IsDealer)
                    EndGame(GameResults.Win);
                else
                    EndGame(GameResults.Lose);
            }
        }
Ejemplo n.º 3
0
        /* deprecating this. moving to static class method
        private void CreateDeck()
        {
            Deck.Cards.Clear();
            DiscardPile.Clear();
            Dealer.ClearHand();
            Player1.ClearHand();
            foreach (string suit in PossibleSuits)
            {
                foreach (string value in PossibleValues)
                {
                    Deck.Add(new Card(value, suit));
                }
            }

            foreach (Card cd in Deck)
            {
                cd.ImageFileName = AssignCardImageFile(cd);
            }
        }
        */
        /* deprecating this.
        private void btnGetRandomCard_Click(object sender, EventArgs e)
        {
            Random myrand = new Random();
            int CardToGet = myrand.Next(0, Deck.Cards.Count);
            Console.WriteLine("Random card is the " + Deck[CardToGet].Value + " of " + Deck[CardToGet].Suit + ".");
            Deck.RemoveAt(CardToGet);
        }
        */
        /* deprecating this. Moving method to static deck class
        private List<Card> Shuffle(List<Card> deck)
        {
            // TODO: Create a deck class, and make this method a member of deck
            List<Card> DeckToShuffle = deck;
            List<Card> ShuffledDeck = new List<Card>();
            Random myrand = new Random();
            while (DeckToShuffle.Count > 0)
            {
                int CardToGet = myrand.Next(0, DeckToShuffle.Count);
                ShuffledDeck.Add(deck[CardToGet]);
                DeckToShuffle.RemoveAt(CardToGet);
            }
            return ShuffledDeck;
        }
        */
        /* deprecating this.
        private void btnShuffleDeck_Click(object sender, EventArgs e)
        {
            Deck = Shuffle(Deck);
        }
        */
        private void DealCard(Person targetperson)
        {
            int LastIndex = Deck.Cards.Count - 1;
            targetperson.AddCardToHand(Deck.Cards[LastIndex]);
            string filename = Deck.Cards[LastIndex].ImageFileName;
            PictureBox[] ImageArray = targetperson.CardImageArray;

            for (int indexcounter = 0; indexcounter < ImageArray.Length; indexcounter++)
            {
                if (ImageArray[indexcounter] == null || ImageArray[indexcounter].Image == null)
                {
                    if (targetperson.IsDealer && indexcounter == 0) // dealer's first card is facedown. All other cards are faceup.
                    {
                        ImageArray[indexcounter].Image = (Image)CardImageFiles.ResourceManager.GetObject("RedBackVert");
                    }
                    else
                    {
                        ImageArray[indexcounter].Image = (Image)CardImageFiles.ResourceManager.GetObject(filename);
                    }

                    ImageArray[indexcounter].Visible = true;
                    ImageArray[indexcounter].BringToFront();
                    break;
                }
            }

            Deck.Cards.RemoveAt(LastIndex);
            if (Deck.Cards.Count == 0)
            {
                Deck.Shuffle();
            }
            // UpdateDealerHandValue();
            UpdatePlayerHandValue();
        }