public bool NewGame(Dealer a_dealer, Player a_player)
        {
            a_dealer.AddCard(a_player, true);
            a_dealer.AddCard(a_dealer, true);
            a_dealer.AddCard(a_player, true);

            return(true);
        }
Exemple #2
0
        public void TestDealer17()
        {
            Deck   deck   = new Deck();
            Dealer dealer = new Dealer();

            dealer.AddCard(new Card(Rank.KING, Suit.HEART));
            dealer.AddCard(new Card(Rank.SEVEN, Suit.CLUB));
            dealer.Deal(deck);
            Assert.IsTrue(dealer.CardsinHand == 2);
        }
Exemple #3
0
        public void Test_DoNotNeedDraw()
        {
            var dealer = new Dealer(1, "MurabitoA");

            // 手札のカードを手動で設定する。
            // テストがランダム処理の影響を受けるのを防ぐため。
#pragma warning disable CS0612 // 型またはメンバーが古い形式です
            dealer.AddCard(new Card(Suit.Diamond, CardNumber.King));
            dealer.AddCard(new Card(Suit.Diamond, CardNumber.King));
#pragma warning restore CS0612 // 型またはメンバーが古い形式です
            Assert.Equal(false, dealer.NeedDraw);
        }
Exemple #4
0
        public void Test_TotalValue()
        {
            var dealer = new Dealer(1, "MurabitoA");

            // 手札のカードを手動で設定する。
            // テストがランダム処理の影響を受けるのを防ぐため。
#pragma warning disable CS0612 // 型またはメンバーが古い形式です
            dealer.AddCard(new Card(Suit.Club, CardNumber.Ace));
            dealer.AddCard(new Card(Suit.Diamond, CardNumber.King));
            dealer.AddCard(new Card(Suit.Heart, CardNumber.Queen));
#pragma warning restore CS0612 // 型またはメンバーが古い形式です

            Assert.Equal(21, dealer.TotalValue);
        }
Exemple #5
0
        public void Test_NoNeedDraw()
        {
            var policy = new DealerTurnPolicy();
            var dealer = new Dealer(1, "Dealer");

            // 手札のカードを手動で設定する。
            // テストがランダム処理の影響を受けるのを防ぐため。
#pragma warning disable CS0612 // 型またはメンバーが古い形式です
            dealer.AddCard(new Card(Suit.Club, CardNumber.Ace));
            dealer.AddCard(new Card(Suit.Club, CardNumber.Six));
            dealer.AddCard(new Card(Suit.Club, CardNumber.Ten));
#pragma warning restore CS0612 // 型またはメンバーが古い形式です

            Assert.False(policy.NeedDraw(dealer));
        }
        private void btnPlantar_Click(object sender, RoutedEventArgs e)
        {
            btnEmpezar.IsEnabled = false;
            btnPlantar.IsEnabled = false;
            Card cartaD = myDealer.Hand[1];

            txtDealer.Text += cartaD.Suit.ToString() + cartaD.Symbol + "\n";
            while (Value(myDealer.Hand) < Value(myPlayer.Hand))
            {
                myDealer.AddCard(myDealer.Deal());
                txtDealer.Text = "";
                foreach (Card card in myDealer.Hand)
                {
                    txtDealer.Text += card.Suit.ToString() + card.Symbol.ToString() + "\n";
                }
            }
            if (Value(myDealer.Hand) >= Value(myPlayer.Hand) && Value(myDealer.Hand) <= 21)
            {
                txtResultado.Text    = "Gana la casa";
                contadorP            = contadorP + 1;
                contadorJ            = contadorJ + 1;
                imgMaster.Visibility = Visibility.Visible;
            }
            else
            {
                txtResultado.Text = "Gana el jugador";
                contadorG         = contadorG + 1;
                contadorJ         = contadorJ + 1;
            }
            txtPartidasJ.Text     = contadorJ.ToString();
            txtPartidasG.Text     = contadorG.ToString();
            txtPartidasP.Text     = contadorP.ToString();
            btnReinicio.IsEnabled = true;
        }
            ///<summary> Deals a card to the Player with id "id".</summary>
            ///<param name="id"> A valid PlayerID</param>
            ///<returns> int value representing the card, 0-51 </returns>
            public int DealCardToPlayer(int id)
            {
                Dealer p    = _idToDealer[id];
                int    card = _deck.NextCard;

                p.AddCard(card);
                return(card);
            }
Exemple #8
0
        public void Test5CardsUnder21Win()
        {
            Player player = new Player();
            Deck deck = new Deck();
            Dealer dealer = new Dealer();
            player.AddCard(new Card(Rank.TWO, Suit.DIAMOND));
            player.AddCard(new Card(Rank.TWO, Suit.SPADE));
            player.AddCard(new Card(Rank.ACE, Suit.SPADE));
            player.AddCard(new Card(Rank.FOUR, Suit.SPADE));
            player.AddCard(new Card(Rank.ACE, Suit.HEART));

            dealer.AddCard(new Card(Rank.TEN, Suit.HEART));
            dealer.AddCard(new Card(Rank.TEN, Suit.SPADE));

            BlackJackGame game = new BlackJackGame(deck, player, dealer);
            game.CheckScores();
            Assert.IsTrue(game.Status == GameState.WIN);
        }
Exemple #9
0
        public void TestWin21()
        {
            Player player = new Player();
            Deck   deck   = new Deck();
            Dealer dealer = new Dealer();

            BlackJackGame game = new BlackJackGame(deck, player, dealer);

            dealer.AddCard(new Card(Rank.TEN, Suit.HEART));
            dealer.AddCard(new Card(Rank.EIGHT, Suit.SPADE));

            player.AddCard(new Card(Rank.ACE, Suit.DIAMOND));
            player.AddCard(new Card(Rank.JACK, Suit.SPADE));

            game.CheckScores();
            game.RestartGame();
            Assert.AreEqual(105, game.Player.Money);
        }
Exemple #10
0
        public void TestLose()
        {
            Player player = new Player();
            Dealer dealer = new Dealer();
            Deck   deck   = new Deck();

            player.AddCard(new Card(Rank.NINE, Suit.DIAMOND));
            player.AddCard(new Card(Rank.TEN, Suit.SPADE));

            dealer.AddCard(new Card(Rank.TEN, Suit.CLUB));
            dealer.AddCard(new Card(Rank.TEN, Suit.HEART));

            BlackJackGame game = new BlackJackGame(deck, player, dealer);

            game.Decision = true;
            game.CheckScores();

            Assert.IsTrue(game.Status == GameState.LOSE);
        }
Exemple #11
0
        public void TestBetWin()
        {
            Player player = new Player();
            Deck   deck   = new Deck();
            Dealer dealer = new Dealer();

            BlackJackGame game = new BlackJackGame(deck, player, dealer);

            player.AddCard(new Card(Rank.ACE, Suit.DIAMOND));
            player.AddCard(new Card(Rank.NINE, Suit.SPADE));

            dealer.AddCard(new Card(Rank.TEN, Suit.HEART));
            dealer.AddCard(new Card(Rank.EIGHT, Suit.SPADE));

            game.Decision = true;
            game.CheckScores();
            game.RestartGame();
            Assert.IsTrue(game.Player.Money == 100);
        }
Exemple #12
0
 public Table()
 {
     m_Players = new List <Player>();
     m_Dealer  = new Dealer();
     m_Dealer.Join(this);
     for (int i = 0; i < CARD_MAX; i++)
     {
         m_Cards[i] = new Card(i, m_Dealer);
         m_Dealer.AddCard(m_Cards[i]);
     }
 }
Exemple #13
0
        private void BtnStop_Click(object sender, RoutedEventArgs e)
        {
            txtDealerHand.Text = "";

            foreach (Card c in dealer.Hand)
            {
                txtDealerHand.Text += c.Symbol + c.Suit + "\n";
            }

            while (Check(dealer.Hand) < Check(player.Hand))
            {
                Card c = dealer.Deal();
                dealer.AddCard(c);

                App.Current.Dispatcher.Invoke((Action) delegate
                {
                    txtDealerHand.Text += c.Symbol + c.Suit + "\n";
                    DealerScore.Content = Check(dealer.Hand);
                });
            }
            int DealerValue = Check(dealer.Hand);

            DealerScore.Content = DealerValue;
            int handValue = Check(player.Hand);

            lblNew.Content = handValue;
            if (DealerValue > 21)
            {
                btnAdd.IsEnabled  = false;
                btnStop.IsEnabled = false;
                MessageBox.Show("El jugador gana");
            }
            if (handValue > DealerValue && handValue <= 21)
            {
                btnAdd.IsEnabled  = false;
                btnStop.IsEnabled = false;
                MessageBox.Show("El jugador gana");
            }
            else
            {
                if (handValue == DealerValue)
                {
                    btnAdd.IsEnabled  = false;
                    btnStop.IsEnabled = false;
                    MessageBox.Show("Draw");
                }
                else
                {
                    btnAdd.IsEnabled  = false;
                    btnStop.IsEnabled = false;
                    MessageBox.Show("La casa gana");
                }
            }
        }
Exemple #14
0
        public void TestBetLose()
        {
            Player player = new Player();
            Deck deck = new Deck();
            Dealer dealer = new Dealer();

            BlackJackGame game = new BlackJackGame(deck, player, dealer);

            player.AddCard(new Card(Rank.TEN, Suit.DIAMOND));
            player.AddCard(new Card(Rank.FOUR, Suit.SPADE));

            dealer.AddCard(new Card(Rank.TEN, Suit.HEART));
            dealer.AddCard(new Card(Rank.EIGHT, Suit.SPADE));

            game.Decision = true;
            game.CheckScores();
            game.RestartGame ();

            Assert.IsTrue(game.Player.Money == 80);
        }
Exemple #15
0
        public void Test5CardsUnder21Win()
        {
            Player player = new Player();
            Deck   deck   = new Deck();
            Dealer dealer = new Dealer();

            player.AddCard(new Card(Rank.TWO, Suit.DIAMOND));
            player.AddCard(new Card(Rank.TWO, Suit.SPADE));
            player.AddCard(new Card(Rank.ACE, Suit.SPADE));
            player.AddCard(new Card(Rank.FOUR, Suit.SPADE));
            player.AddCard(new Card(Rank.ACE, Suit.HEART));

            dealer.AddCard(new Card(Rank.TEN, Suit.HEART));
            dealer.AddCard(new Card(Rank.TEN, Suit.SPADE));

            BlackJackGame game = new BlackJackGame(deck, player, dealer);

            game.CheckScores();
            Assert.IsTrue(game.Status == GameState.WIN);
        }
Exemple #16
0
        public void Test_Judgement_WinPlayer()
        {
            var judgement = new JudgementPolicy();

#pragma warning disable CS0612 // 型またはメンバーが古い形式です
            var player = new Player(1, "Winner Player");
            player.AddCard(new Card(Suit.Club, CardNumber.Ace));
            player.AddCard(new Card(Suit.Club, CardNumber.Eight));
            player.AddCard(new Card(Suit.Club, CardNumber.Two));
#pragma warning restore CS0612 // 型またはメンバーが古い形式です

#pragma warning disable CS0612 // 型またはメンバーが古い形式です
            var dealer = new Dealer(1, "Loser Dealer");
            dealer.AddCard(new Card(Suit.Club, CardNumber.Four));
            dealer.AddCard(new Card(Suit.Club, CardNumber.Six));
            dealer.AddCard(new Card(Suit.Club, CardNumber.Jack));
#pragma warning restore CS0612 // 型またはメンバーが古い形式です

            var winner = judgement.Judge(dealer, player);

            Assert.Equal(winner, player);
        }
Exemple #17
0
        public void DealerDraw(bool hidden = false)
        {
            if (Dealer.HighValue >= 17) //Dont draw more cards
            {
                SetWinner();
                return;
            }
            Card drawnCard = Deck.Draw();

            drawnCard.IsHidden = hidden; //Card hidden?

            Dealer.AddCard(drawnCard);
        }
Exemple #18
0
            /// <returns>a card if the dealer hits, -1 if dealer stands</returns>
            public int DealerTakeTurn()
            {
                Dealer dealer    = _idToDealer[_dealerID];
                int    handValue = DetermineHandValue(dealer.Hand);

                if (handValue >= 16 || handValue == -1)
                {
                    return(-1);
                }
                int card = _deck.NextCard;

                dealer.AddCard(card);
                return(card);
            }
    private void DealCard(Player player)
    {
        Card card = player.SelectedCard;

        card.transform.SetParent(dealer.transform);

        Hashtable args = new Hashtable();

        args.Add("Player", player);

        dealer.AddCard(card);
        dealer.ShiftCards();
        Utility.DelayedCallWithArgs(gameObject, gameObject, "OnDealAnimationComplete", args, dealer.GetDeckSize());
    }
Exemple #20
0
            ///<summary>Deals a card to the Player with id "id".</summary>
            ///<param name="id">A valid PlayerID</param>
            ///<exception>throws System.Exception if the player to hit has already busted</exception>
            ///<returns>a tuple between the card, 0-51, and a bool representing if the card is faceup </returns>
            public System.Tuple <int, bool> DealCardToPlayer(int id)
            {
                Dealer p = _idToDealer[id];

                if (DetermineHandValue(p.Hand) > 21)
                {
                    throw new System.Exception("We should not be dealing cards to player's who have already busted");
                }
                int  card   = _deck.NextCard;
                bool faceup = true;

                if (p.Hand.Count == 0)
                {
                    faceup = false;
                }
                p.AddCard(card);
                return(System.Tuple.Create(card, faceup));
            }
        public int RobarCartas(TextBox bloque, int numCarta, int valorCartas, int valorCartaP)
        {
            MessageBox.Show("El Dealer roba 1 carta");
            d.AddCard(d.Deal());
            bloque.Text = d.Hand[numCarta, 0];

            int valorCard = Int16.Parse(d.Hand[numCarta, 1]);

            txtValor2.Text = (valorCartas + valorCard).ToString();
            valorCartas    = Int16.Parse(txtValor2.Text);

            valorCartas    = revisar(valorCartas, d.Hand);
            txtValor2.Text = valorCartas.ToString();

            if (valorCartas == 21)
            {
                MessageBox.Show("Has perdido, el Dealer hiso 21");
                valorCartas      = 0;
                txtRondasP.Text  = (Int16.Parse(txtRondasP.Text) + 1).ToString();
                btnNew.IsEnabled = true;
                btnAdd.IsEnabled = false;
                btnPtr.IsEnabled = false;
            }
            else if (valorCartas >= valorCartaP && valorCartas < 21)
            {
                MessageBox.Show("Has perdido, el Delaer saco una mejor mano que tu");
                valorCartas      = 0;
                txtRondasP.Text  = (Int16.Parse(txtRondasP.Text) + 1).ToString();
                btnNew.IsEnabled = true;
                btnAdd.IsEnabled = false;
                btnPtr.IsEnabled = false;
            }
            else if (valorCartas > 21)
            {
                MessageBox.Show("Has ganado, el Dealer se paso de 21");
                valorCartas      = 0;
                txtRondasG.Text  = (Int16.Parse(txtRondasG.Text) + 1).ToString();
                btnNew.IsEnabled = true;
                btnAdd.IsEnabled = false;
                btnPtr.IsEnabled = false;
            }
            return(valorCartas);
        }
Exemple #22
0
 public void NewHand(int bet)
 {
     Dealer.Clear();
     CurrentHand = 0;
     if (Hands.Count > 1)
     {
         Hands.RemoveRange(1, Hands.Count - 1);
     }
     foreach (Hand hand in Hands)
     {
         hand.Clear();
         hand.BetSize = bet;
         Money       -= hand.BetSize;
     }
     Deck.ResetDeck();
     Dealer.AddCard(Deck.Draw());
     foreach (Hand hand in Hands)
     {
         hand.AddCard(Deck.Draw());
         hand.AddCard(Deck.Draw());
     }
 }
Exemple #23
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            btnSave.Visibility = Visibility.Hidden;
            btnCard.Visibility = Visibility.Hidden;
            int pointsPlayer = p.Check(p.Hand);
            int pointsDealer = d.Check(d.Hand);

            if (pointsDealer > pointsPlayer && pointsDealer > 16)
            {
                txtResultsDealer.Text = "";
                foreach (Card c in d.Hand)
                {
                    txtResultsDealer.Text += c.Symbol + c.Suit + "  ";
                }
                MessageBox.Show("Dealer win");
                defeat += 1;
            }
            else
            {
                while (pointsDealer < pointsPlayer)
                {
                    d.Confirm(d.Deck);
                    Card j = d.Deal();
                    d.AddCard(j);
                    txtResultsDealer.Text = "";
                    pointsDealer         += j.Score;

                    if (pointsDealer > 21)
                    {
                        foreach (Card i in d.Hand)
                        {
                            txtResultsDealer.Text += i.Symbol + i.Suit + "  ";
                            if (i.Symbol == "A")
                            {
                                i.Score = 1;
                            }
                        }
                    }
                    pointsDealer = d.Check(d.Hand);
                    if (pointsDealer > 21)
                    {
                        MessageBox.Show("You win");
                        victories += 1;
                    }
                }
                while (pointsDealer < 17)
                {
                    d.Confirm(d.Deck);
                    Card z = d.Deal();
                    d.AddCard(z);
                    txtResultsDealer.Text = "";
                    pointsDealer         += z.Score;
                    foreach (Card c in d.Hand)
                    {
                        txtResultsDealer.Text += c.Symbol + c.Suit + "  ";
                        if (pointsDealer > 21)
                        {
                            foreach (Card i in d.Hand)
                            {
                                if (i.Symbol == "A")
                                {
                                    i.Score = 1;
                                }
                            }
                        }
                    }
                    pointsDealer = d.Check(d.Hand);
                    if (pointsDealer > 21)
                    {
                        MessageBox.Show("You win");
                        victories += 1;
                    }
                }
                if (pointsDealer < 22)
                {
                    txtResultsDealer.Text = "";
                    foreach (Card c in d.Hand)
                    {
                        txtResultsDealer.Text += c.Symbol + c.Suit + "  ";
                    }
                    if (pointsDealer == pointsPlayer)
                    {
                        MessageBox.Show("Tie");
                        tie += 1;
                    }
                    else
                    {
                        MessageBox.Show("You lose");
                        defeat += 1;
                    }
                }
            }
            btnNewGame.Visibility = Visibility.Visible;
            btnFinish.Visibility  = Visibility.Visible;
        }
Exemple #24
0
        public void TestWin21()
        {
            Player player = new Player();
            Deck deck = new Deck();
            Dealer dealer = new Dealer();

            BlackJackGame game = new BlackJackGame(deck, player, dealer);

            dealer.AddCard(new Card(Rank.TEN, Suit.HEART));
            dealer.AddCard(new Card(Rank.EIGHT, Suit.SPADE));

            player.AddCard(new Card(Rank.ACE, Suit.DIAMOND));
            player.AddCard(new Card(Rank.JACK, Suit.SPADE));

            game.CheckScores();
            game.RestartGame();
            Assert.AreEqual(105, game.Player.Money);
        }
Exemple #25
0
 public void TestDealer17()
 {
     Deck deck = new Deck();
     Dealer dealer = new Dealer();
     dealer.AddCard(new Card(Rank.KING, Suit.HEART));
     dealer.AddCard(new Card(Rank.SEVEN, Suit.CLUB));
     dealer.Deal(deck);
     Assert.IsTrue (dealer.CardsinHand == 2);
 }
Exemple #26
0
        public void TestWin()
        {
            Player player = new Player();
            Dealer dealer = new Dealer();
            Deck deck = new Deck();
            player.AddCard(new Card(Rank.TEN, Suit.DIAMOND));
            player.AddCard(new Card(Rank.TEN, Suit.SPADE));

            dealer.AddCard(new Card(Rank.TEN, Suit.CLUB));
            dealer.AddCard(new Card(Rank.NINE, Suit.SPADE));

            BlackJackGame game = new BlackJackGame(deck, player, dealer);
            game.Decision = true;
            game.CheckScores();

            Assert.IsTrue(game.Status == GameState.WIN);
        }
Exemple #27
0
 public void DealerDraw()
 {
     Dealer.AddCard(Deck.Draw());
 }