コード例 #1
0
        private void playAmountOfGames(int amount)
        {
            sw.Start();

            for (int i = 0; i < amount; i++)
            {
                Game.Player1.Hand.Add(Game.Deck.DealCard());
                Game.Player2.Hand.Add(Game.Deck.DealCard());
                Game.Player1.Hand.Add(Game.Deck.DealCard());
                Game.Player2.Hand.Add(Game.Deck.DealCard());
                Game.TableCards.Add(Game.Deck.DealCard());
                Game.TableCards.Add(Game.Deck.DealCard());
                Game.TableCards.Add(Game.Deck.DealCard());
                Game.TableCards.Add(Game.Deck.DealCard());
                Game.TableCards.Add(Game.Deck.DealCard());

                Game.DecideWinner();
                gameCount++;

                counters[(int)Game.Player1.BestHand.PokerCombination - 1]++;
                counters[(int)Game.Player2.BestHand.PokerCombination - 1]++;

                Game.Reset();
            }

            lbl_GameCount.Content = gameCount;
            lbl_HandCount.Content = gameCount * 2;

            sw.Stop();
        }
コード例 #2
0
        private void btn_Table_Click(object sender, RoutedEventArgs e)
        {
            if (img_Flop1.Source == null)
            {
                logLine += "The flop: ";

                current = Game.Deck.DealCard();
                Game.TableCards.Add(current);
                logLine         += current.ToString() + ", ";
                img_Flop1.Source = new BitmapImage(new Uri(current.ImagePath(), UriKind.Relative));

                current = Game.Deck.DealCard();
                Game.TableCards.Add(current);
                logLine         += current.ToString() + ", ";
                img_Flop2.Source = new BitmapImage(new Uri(current.ImagePath(), UriKind.Relative));

                current = Game.Deck.DealCard();
                Game.TableCards.Add(current);
                logLine         += current.ToString() + ".";
                img_Flop3.Source = new BitmapImage(new Uri(current.ImagePath(), UriKind.Relative));

                txt_Log.Text += logLine + Environment.NewLine;
                logLine       = "";

                btn_Table.Content = "Turn";
            }
            else if (img_Turn.Source == null)
            {
                logLine += "The turn: ";

                current = Game.Deck.DealCard();
                Game.TableCards.Add(current);
                logLine        += current.ToString() + ".";
                img_Turn.Source = new BitmapImage(new Uri(current.ImagePath(), UriKind.Relative));

                txt_Log.Text += logLine + Environment.NewLine;
                logLine       = "";

                btn_Table.Content = "River";
            }
            else
            {
                logLine += "The river: ";

                current = Game.Deck.DealCard();
                Game.TableCards.Add(current);
                logLine         += current.ToString() + ".";
                img_River.Source = new BitmapImage(new Uri(current.ImagePath(), UriKind.Relative));

                txt_Log.Text += logLine + Environment.NewLine;
                logLine       = "";

                if (cbx_Hide.IsChecked == true)
                {
                    img_P2C1.Source = new BitmapImage(new Uri(Game.Player2.Hand[0].ImagePath(), UriKind.Relative));
                    img_P2C2.Source = new BitmapImage(new Uri(Game.Player2.Hand[1].ImagePath(), UriKind.Relative));
                }

                try
                {
                    Game.DecideWinner();

                    txt_Log.Text += Game.Player1.Name + " has " + PokerHelp.PokerCombinationToString(Game.Player1.BestHand.PokerCombination) + Environment.NewLine;
                    txt_Log.Text += Game.Player2.Name + " has " + PokerHelp.PokerCombinationToString(Game.Player2.BestHand.PokerCombination) + Environment.NewLine;

                    if (Game.Player1.Won && !Game.Player2.Won)
                    {
                        txt_Log.Text += Game.Player1.Name + " wins!" + Environment.NewLine;
                    }
                    else if (Game.Player2.Won && !Game.Player1.Won)
                    {
                        txt_Log.Text += Game.Player2.Name + " wins!" + Environment.NewLine;
                    }
                    else if (Game.Player1.Won && Game.Player2.Won)
                    {
                        txt_Log.Text += "Split pot!" + Environment.NewLine;
                    }
                    else
                    {
                        throw new Exception("Impossible winsituation");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }

                lbl_PointsP1.Content = Game.Player1.Points;
                lbl_PointsP2.Content = Game.Player2.Points;

                handCount++;
                lbl_HandCount.Content = handCount;

                txt_Log.Text += "--------------------------------------------------------------------------------------------------------" + Environment.NewLine;

                btn_Table.IsEnabled   = false;
                btn_Restart.IsEnabled = true;
                cbx_Hide.IsEnabled    = true;
            }
        }
コード例 #3
0
ファイル: AutoPlay.xaml.cs プロジェクト: BenVandenberk/Poker
        private void btn_Run_Click(object sender, RoutedEventArgs e)
        {
            disableRadioButtons();
            btn_Menu.IsEnabled = false;
            int checkedRbtn = getChecked();

            stop = false;
            sw.Reset();

            sw.Start();

            gameCount             = 0;
            lbl_GameCount.Content = gameCount;

            img_P1C1.Source  = null;
            img_P1C2.Source  = null;
            img_P2C1.Source  = null;
            img_P2C2.Source  = null;
            img_Flop1.Source = null;
            img_Flop2.Source = null;
            img_Flop3.Source = null;
            img_Turn.Source  = null;
            img_River.Source = null;

            while (!stop)
            {
                Game.Player1.Hand.Add(Game.Deck.DealCard());
                Game.Player2.Hand.Add(Game.Deck.DealCard());
                Game.Player1.Hand.Add(Game.Deck.DealCard());
                Game.Player2.Hand.Add(Game.Deck.DealCard());
                Game.TableCards.Add(Game.Deck.DealCard());
                Game.TableCards.Add(Game.Deck.DealCard());
                Game.TableCards.Add(Game.Deck.DealCard());
                Game.TableCards.Add(Game.Deck.DealCard());
                Game.TableCards.Add(Game.Deck.DealCard());

                try
                {
                    Game.DecideWinner();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }

                gameCount++;

                if ((int)Game.Player1.BestHand.PokerCombination == checkedRbtn || (int)Game.Player2.BestHand.PokerCombination == checkedRbtn)
                {
                    stop = true;
                    lbl_GameCount.Content = gameCount;
                    lbl_HandCount.Content = gameCount * 2;
                    lbl_PointsP1.Content  = Game.Player1.Points;
                    lbl_PointsP2.Content  = Game.Player2.Points;

                    sw.Stop();
                    lbl_Time.Content = sw.ElapsedMilliseconds / 1000.0 + " s";

                    img_P1C1.Source = new BitmapImage(new Uri(Game.Player1.Hand[0].ImagePath(), UriKind.Relative));
                    img_P1C2.Source = new BitmapImage(new Uri(Game.Player1.Hand[1].ImagePath(), UriKind.Relative));
                    img_P2C1.Source = new BitmapImage(new Uri(Game.Player2.Hand[0].ImagePath(), UriKind.Relative));
                    img_P2C2.Source = new BitmapImage(new Uri(Game.Player2.Hand[1].ImagePath(), UriKind.Relative));

                    img_Flop1.Source = new BitmapImage(new Uri(Game.TableCards[0].ImagePath(), UriKind.Relative));
                    img_Flop2.Source = new BitmapImage(new Uri(Game.TableCards[1].ImagePath(), UriKind.Relative));
                    img_Flop3.Source = new BitmapImage(new Uri(Game.TableCards[2].ImagePath(), UriKind.Relative));
                    img_Turn.Source  = new BitmapImage(new Uri(Game.TableCards[3].ImagePath(), UriKind.Relative));
                    img_River.Source = new BitmapImage(new Uri(Game.TableCards[4].ImagePath(), UriKind.Relative));

                    txt_Log.Text += "///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////" + Environment.NewLine;
                    txt_Log.Text += "---------------------------------------------BINGO!-----------------------------------------------------" + Environment.NewLine;
                    txt_Log.Text += "///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////" + Environment.NewLine;

                    txt_Log.Text += String.Format("The flop: {0}, {1}, {2}.", Game.TableCards[0], Game.TableCards[1], Game.TableCards[2]) + Environment.NewLine;
                    txt_Log.Text += String.Format("The turn: {0}.", Game.TableCards[3]) + Environment.NewLine;
                    txt_Log.Text += String.Format("The river: {0}.", Game.TableCards[4]) + Environment.NewLine;
                    txt_Log.Text += Game.Player1.Name + " has " + PokerHelp.PokerCombinationToString(Game.Player1.BestHand.PokerCombination) + Environment.NewLine;
                    txt_Log.Text += Game.Player2.Name + " has " + PokerHelp.PokerCombinationToString(Game.Player2.BestHand.PokerCombination) + Environment.NewLine;
                    if (Game.Player1.Won && !Game.Player2.Won)
                    {
                        txt_Log.Text += Game.Player1.Name + " wins!" + Environment.NewLine;
                    }
                    else if (Game.Player2.Won && !Game.Player1.Won)
                    {
                        txt_Log.Text += Game.Player2.Name + " wins!" + Environment.NewLine;
                    }
                    else if (Game.Player1.Won && Game.Player2.Won)
                    {
                        txt_Log.Text += "Split pot!" + Environment.NewLine;
                    }
                    txt_Log.Text += Environment.NewLine;
                }
                else
                {
                    Game.Reset();
                }
            }

            Game.Reset();
            enableRadioButtons();
            btn_Menu.IsEnabled = true;
        }