private void dealClick(object sender, RoutedEventArgs e)
        {
            try
            {
                pack = new Pack();

                for (int handNum = 0; handNum < NumHands; handNum++)
                {
                    hands[handNum] = new Hand();
                    for (int numCards = 0; numCards < Hand.HandSize; numCards++)
                    {
                        PlayingCard cardDealt = pack.DealCardFromPack();
                        hands[handNum].AddCardToHand(cardDealt);
                    }
                }

                north.Text = hands[0].ToString();
                south.Text = hands[1].ToString();
                east.Text = hands[2].ToString();
                west.Text = hands[3].ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Beispiel #2
0
        private void dealClick(object sender, RoutedEventArgs e)
        {
            try
            {
                pack = new Pack();

                for (int handNum = 0; handNum < NumHands; handNum++)
                {
                    hands[handNum] = new Hand();
                    for (int numCards = 0; numCards < Hand.HandSize; numCards++)
                    {
                        PlayingCard cardDealt = pack.DealCardFromPack();
                        hands[handNum].AddCardToHand(cardDealt);
                    }
                }
                north.Text = hands[0].ToString();
                south.Text = hands[1].ToString();
                east.Text  = hands[2].ToString();
                west.Text  = hands[3].ToString();
            }
            catch (Exception ex)
            {
                MessageDialog msg = new MessageDialog(ex.Message, "Error");
                msg.ShowAsync();
            }
        }
        private void dealClick(object sender, RoutedEventArgs e)                    /*This statement simply creates a new pack of cards. You saw earlier that this class contains a two-
                                                                                     * dimensional array holding the cards in the pack, and the constructor populates this array with
                                                                                     * the details of each card. You now need to create four hands of cards from this pack.*/
        {
            try
            {                                                                       /*This for loop creates four hands from the pack of cards and stores them in an array called hands.
                                                                                     * Each hand is initially empty, so you need to deal the cards from the pack to each hand.*/
                pack = new Pack();
                for (int handNum = 0; handNum < NumHands; handNum++)
                {                                                                   /*The inner for loop populates each hand by using the DealCardFromPack method to retrieve a
                                                                                     * card at random from the pack and the AddCardToHand method to add this card to a hand. */
                    hands[handNum] = new Hand();
                    for (int numCards = 0; numCards < Hand.HandSize; numCards++)
                    {
                        PlayingCard cardDealt = pack.DealCardFromPack();
                        hands[handNum].AddCardToHand(cardDealt);
                    }
                }

                north.Text = hands[0].ToString();
                south.Text = hands[1].ToString();
                east.Text  = hands[2].ToString();
                west.Text  = hands[3].ToString();
            }
            catch (Exception ex)
            {
                MessageDialog msg = new MessageDialog(ex.Message, "Error");
                msg.ShowAsync();
            }
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            const int NumHands = 4;

            Pack         pack  = new Pack();
            IList <Hand> hands = new List <Hand>();

            for (int handNum = 0; handNum < NumHands; handNum++)
            {
                hands.Add(new Hand());
                for (int numCards = 0; numCards < Hand.HandSize; numCards++)
                {
                    PlayingCard cardDealt = pack.DealCardFromPack();
                    hands.ElementAt(handNum).AddCardToHand(cardDealt);
                }
            }


            for (int handNum = 0; handNum < NumHands; handNum++)
            {
                Console.WriteLine($"Hand {handNum + 1}: " + Environment.NewLine + hands.ElementAt(handNum));
                Console.WriteLine("===============================================");
            }


            Console.ReadKey();
        }
        private void dealClick(object sender, RoutedEventArgs e)
        {
            try
            {
                pack = new Pack();

                for (int handNum = 0; handNum < NumHands; handNum++)
                {
                    hands[handNum] = new Hand();
                    for (int numCards = 0; numCards < Hand.HandSize; numCards++)
                    {
                        PlayingCard cardDealt = pack.DealCardFromPack();
                        hands[handNum].AddCardToHand(cardDealt);
                    }
                }
                north.Text = hands[0].ToString();
                south.Text = hands[0].ToString();
                east.Text = hands[0].ToString();
                west.Text = hands[0].ToString();
            }
            catch (Exception ex)
            {
                MessageDialog msg = new MessageDialog(ex.Message, "Error");
                msg.ShowAsync();
            }
        }
        private async void Button_OnClick(object sender, RoutedEventArgs e)
        {
            try
            {
                _pack = new Pack();

                for (int handNum = 0; handNum < NumHands; ++handNum)
                {
                    _hands[handNum] = new Hand();

                    for (int cardNum = 0; cardNum < Hand.HandSize; ++cardNum)
                    {
                        PlayingCard cardDealt = _pack.DealCardFromPack();
                        _hands[handNum].AddCardToHand(cardDealt);
                    }
                }

                North.Text = _hands[(int)Suit.Clubs].ToString();
                South.Text = _hands[(int)Suit.Diamonds].ToString();
                Ease.Text  = _hands[(int)Suit.Hearts].ToString();
                West.Text  = _hands[(int)Suit.Spades].ToString();
            }
            catch (Exception exception)
            {
                MessageDialog messageDialog = new MessageDialog(exception.Message, "Error");
                _ = await messageDialog.ShowAsync();
            }
        }
Beispiel #7
0
        private void DealClick(object sender, RoutedEventArgs e)
        {
            try
            {
                _pack = new Pack();

                for (int handNum = 0; handNum < NumHands; handNum++)
                {
                    _hands[handNum] = new Hand();
                    for (int numCards = 0; numCards < Hand.HandSize; numCards++)
                    {
                        PlayingCard cardDealt = _pack.DealCardFromPack();
                        _hands[handNum].AddCardToHand(cardDealt);
                    }
                }

                north.Text = _hands[0].ToString();
                south.Text = _hands[1].ToString();
                east.Text  = _hands[2].ToString();
                west.Text  = _hands[3].ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Beispiel #8
0
 /// <summary>
 /// Empties the hand and redeals from the provided pack
 /// </summary>
 /// <param name="pack"></param>
 public void DealFromPack(Pack pack)
 {
     cards.Clear();
     for (int j = 0; j < HandSize; j++)
     {
         PlayingCard card = pack.DealCardFromPack();
         AddCardToHand(card);
     }
 }