Ejemplo n.º 1
0
        /// <summary>
        /// Constructor takes the player object (player who makes the bet)
        /// </summary>
        /// <param name="p"></param>
        public MakeBetForm( Player p )
        {
            InitializeComponent();

            player = p;
            this.labelPlayerName.Text = p.Name;
        }
Ejemplo n.º 2
0
 /// <summary>
 /// The method is invoked after pressing "Add" (in PM_ADD mode) or "OK" (in PM_EDIT mode)
 /// </summary>
 private void buttonAddPlayerClick(object sender, EventArgs e)
 {
     // try parsin text in the "money" field
     try
     {
         // adding
         if (windowMode == PlayerMode.PM_ADD)
         {
             player = new Player( this.textBoxPlayerName.Text,
                                     int.Parse(this.textBoxPlayerMoney.Text));
         }
         // editing
         else
         {
             player.Name = this.textBoxPlayerName.Text;
             player.Money = int.Parse(this.textBoxPlayerMoney.Text);
         }
         // if everything's OK then we close the form with DialogResult Ok
         DialogResult = DialogResult.OK;
     }
     // if somethings's wrong
     catch (FormatException)
     {
         MessageBox.Show( "Wrong number format (the money field must contain only digits)" );
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Parameterized constructor
 /// </summary>
 /// <param name="p"><see cref="Player"/> object</param>
 /// <param name="shuffleNo">The number of shuffle in stats</param>
 public BlackjackResult( Player p, int shuffleNo )
 {
     player = p;
     shuffles.Add( shuffleNo );
     results.Add( p.PlayResult );
     stakes.Add( p.Stake );
 }
Ejemplo n.º 4
0
 public void AddPlayer(Player player, int seat)
 {
     if (_players[seat] != null)
     {
         throw new Exception("can't sit on top of another player");
     }
     _players[seat] = player;
 }
Ejemplo n.º 5
0
        public void blackjack_win()
        {
            int starting_bet = 10;
            int final_bet = 20;
            Player p = new Player();
            p.Player_Bet = starting_bet;
            p.blackjack_win();

            int actual = p.Player_Bet;
            Assert.AreEqual(final_bet, actual, "Blackjack Win!");
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Method adds the info about a new shuffle
        /// </summary>
        /// <param name="p"><see cref="Player"/> object</param>
        /// <param name="shuffleNo">The shuffe number</param>
        public void AddShuffleResult( Player p, int shuffleNo )
        {
            int nPlayer = gameResults.FindIndex( g => g.player.Name == p.Name );

            if (nPlayer >= 0)
            {
                gameResults[nPlayer].shuffles.Add( shuffleNo );
                gameResults[nPlayer].results.Add( p.PlayResult );
                gameResults[nPlayer].stakes.Add( p.Stake );
            }
        }
Ejemplo n.º 7
0
        public void blackjack_loss()
        {
            int starting_bet = 10;
            int final_bet = 0;
            Player p = new Player();
            p.bets[0] = starting_bet;
            p.Player_Bet = starting_bet;
            p.loss();

            int actual = p.Player_Bet;
            Assert.AreEqual(final_bet, actual, "Blackjack loss!");
        }
Ejemplo n.º 8
0
 private static List<Player> MakePlayers(int playerCount, Dealer dealer)
 {
     //set up the players
     var Players = new List<Player>(playerCount);
     for (int i = 1; i <= playerCount; i++)
     {
         var Player = new Player("Player " + i.ToString());
         Players.Add(Player);
         Player.GiveCard(dealer.TakeCard());
         Player.GiveCard(dealer.TakeCard());
     }
     return Players;
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Parameterized constructor
        /// </summary>
        /// <param name="pm">Window mode (PM_ADD is default)</param>
        /// <param name="p"><see cref="Player"/> object</param>
        public AddPlayerForm( PlayerMode pm = PlayerMode.PM_ADD, Player p = null)
        {
            InitializeComponent();

            windowMode = pm;

            if (pm == PlayerMode.PM_EDIT)
            {
                windowMode = PlayerMode.PM_EDIT;
                this.buttonAddPlayer.Text = "OK";
                player = p;

                this.textBoxPlayerName.Text = p.Name;
                this.textBoxPlayerMoney.Text = p.Money.ToString();
            }
        }
Ejemplo n.º 10
0
        public void PlayHand(Shoe shoe, Player[] players, Player dealer)
        {
            Card dealersTopCard = SeedTable(players, dealer, shoe);

            bool outstanding = false;

            if (!dealer.Hand.IsBlackjack)
            {
                foreach (Player player in players)
                {
                    if (player.Hand.IsBlackjack)
                        continue;
                    outstanding |= PlayHand(player, dealersTopCard, shoe);
                }
                if (outstanding)
                    PlayHand(dealer, dealersTopCard, shoe);
            }
            Payout(players, dealer);
        }
Ejemplo n.º 11
0
        private static void Main(string[] args)
        {
            Trace.Listeners.Add(new ConsoleTraceListener());

            var table = new Table();
            Player[] players = {
                new Player("Book Guy 1", new ByTheBookStrategy()),
                new Player("Book Guy 2", new ByTheBookStrategy()),
                //new Player("Bad guy 1", new ImbicileStrategy()),
                //new Player("Mad man", new RandomStrategy()),
            };
            var dealer = new Player("Dealer", new DealerStrategy());
            var shoe = new Shoe(7);
            for (var i = 0; i < 10000; i++)
            {
                if(shoe.NeedsNewShoe())
                    shoe = new Shoe(7);
                table.PlayHand(shoe, players, dealer);
            }
            ReportStats(players, dealer);
            Console.Read();
        }
Ejemplo n.º 12
0
        public void calculate_win2()
        {
            //
            Card c1 = new Card(7, "C7");
            Card c2 = new Card(10, "DH");

            Player p = new Player();
            p.add_card(c1);
            p.add_card(c2);
            int starting_bet = 10;
            int final_bet = 0;
            p.Player_Bet = starting_bet;
            p.bets[0] = 10;

            Dealer d = new Dealer();
            d.Hand_Value = 18;

            //act
            p.calculate_win(d.Hand_Value);
            int actual = p.Player_Bet;

            //Assert
            Assert.AreEqual(final_bet, actual, "Dealer wins!");
        }
Ejemplo n.º 13
0
        //Adds player to table
        public int add_Player(Player player)
        {
            Boolean found = false;
            int found_i = -1;

            //loops through the table for the first open spot
            for (int i = 0; i < 5; i++)
            {
                if (table[i] == null && found == false) // Spot found and inserts player into table at the current iterration
                {
                    table[i] = player;
                    found = true;
                    found_i = i;
                }
            }

            //Once the search for open spot is done, if a spot isn't found lets the user know the table is full
            if (found == false)
            {
                Console.WriteLine("Sorry " + player.get_Name() + ", this table is full.");
            }

            return found_i;
        }
Ejemplo n.º 14
0
        Card SeedTable(Player[] players, Player dealer, Shoe shoe)
        {
            players.ForEach(x => x.TakeCard(shoe.GetNextCard()));
            dealer.TakeCard(shoe.GetNextCard());
            players.ForEach(x => x.TakeCard(shoe.GetNextCard()));

            Card dealerTopCard = shoe.GetNextCard();
            dealer.TakeCard(dealerTopCard);

            return dealerTopCard;
        }
Ejemplo n.º 15
0
        public void calculate_win5()
        {
            //
            Card c1 = new Card(7, "/C");
            Card c2 = new Card(10, "DH");
            Card c3 = new Card(6, "6D");

            Player p = new Player();
            p.add_card(c1);
            p.add_card(c2);
            p.add_card(c3);
            int starting_bet = 10;
            int final_bet = 0;
            p.Player_Bet = starting_bet;
            p.bets[0] = starting_bet;

            Dealer d = new Dealer();
            d.Hand_Value = 22;

            //act
            p.calculate_win(d.Hand_Value);
            int actual = p.Player_Bet;

            //Assert
            Assert.AreEqual(final_bet, actual, "Dealer and player bust!");
        }
Ejemplo n.º 16
0
        public static void Serialize(Stream s, Player p)
        {
            //Entry:
            //NICK0MONEY
            byte [] data;
            //Serializing with UTF strings
            UTF8Encoding utf = new UTF8Encoding();
            data = utf.GetBytes( p.nick );
            s.Write( data, 0, data.Length );
            s.WriteByte( 0 );
            data = BitConverter.GetBytes( p.money );
            s.Write( data, 0, data.Length ); //Should be 8

            //Write Statistics
            data = BitConverter.GetBytes( p.blackjacks );
            s.Write( data, 0, data.Length ); //Should be 8
            data = BitConverter.GetBytes( p.hands );
            s.Write( data, 0, data.Length ); //Should be 8
            data = BitConverter.GetBytes( p.wins );
            s.Write( data, 0, data.Length ); //Should be 8
            data = BitConverter.GetBytes( p.ties );
            s.Write( data, 0, data.Length ); //Should be 8
            data = BitConverter.GetBytes( p.highestMoney );
            s.Write( data, 0, data.Length ); //Should be 8
            data = BitConverter.GetBytes( p.busts );
            s.Write( data, 0, data.Length ); //Should be 8
            data = BitConverter.GetBytes( p.splits );
            s.Write( data, 0, data.Length ); //Should be 8
            data = BitConverter.GetBytes( p.dds );
            s.Write( data, 0, data.Length ); //Should be 8
            data = BitConverter.GetBytes( p.surrenders );
            s.Write( data, 0, data.Length ); //Should be 8
            data = BitConverter.GetBytes( p.moneyResets );
            s.Write( data, 0, data.Length ); //Should be 8
        }
Ejemplo n.º 17
0
 bool PlayHand(Player player, Card dealerTopCard, Shoe shoe)
 {
     PlayAction play = player.Play(player.Hand, dealerTopCard);
     if (play == PlayAction.Stay)
     {
         return true;
     }
     if (play == PlayAction.Hit)
     {
         Card card = shoe.GetNextCard();
         bool bust = player.TakeCard(card);
         if (bust)
             return false;
         return PlayHand(player, dealerTopCard, shoe);
     }
     if (play == PlayAction.Double)
     {
         if (player.Hand.Count() != 2)
             throw new Exception("only double on first");
         var bust = player.TakeCard(shoe.GetNextCard());
         if (bust)
             return false;
         return true;
     }
     throw new InvalidOperationException("shouldn't be here");
 }
Ejemplo n.º 18
0
        public void DrawHands(Graphics drawingSurface, Player.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:
                        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 )
                            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 Hand.OutcomeType.Won:
                           case Hand.OutcomeType.Blackjack:
                               drawingSurface.DrawString("WON", new Font("Arial",8,FontStyle.Bold), new SolidBrush(Color.LimeGreen), x-10, y-20 );
                               break;
                           case Hand.OutcomeType.Lost:
                               drawingSurface.DrawString("LOST", new Font("Arial",8,FontStyle.Bold), new SolidBrush(Color.Crimson), x-10, y-20 );
                               break;
                           case Hand.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
                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 )
                    {
                        //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.Value).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 );
                }

            }
Ejemplo n.º 19
0
        /// <summary>
        /// Deserializes a player from a stream.
        /// </summary>
        /// <param name="s">The stream to extract the player from.</param>
        /// <returns>The player found, or null if EOF</returns>
        public static Player Deserialize(Stream s)
        {
            Player p = new Player();
            LinkedList<byte> nameMaker = new LinkedList<byte>();
            UTF8Encoding utf = new UTF8Encoding();

            int nextByte = s.ReadByte();
            if ( nextByte == -1 )
                return null;

            //Read in all the bytes until 0 byte.
            while ( nextByte > 0 ) {
                nameMaker.AddLast( (byte)nextByte );
                nextByte = s.ReadByte();
            }

            //Make sure we keep UTF8 compat
            byte[] convert = new byte[nameMaker.Count];
            nameMaker.CopyTo( convert, 0 );
            p.nick = utf.GetString( convert );

            //Read the money
            convert = new byte[88];
            s.Read( convert, 0, 88 );
            p.money = BitConverter.ToUInt64( convert, 0 );

            //Read the stats
            p.blackjacks = BitConverter.ToUInt64( convert, 8 );
            p.hands = BitConverter.ToUInt64( convert, 16 );
            p.wins = BitConverter.ToUInt64( convert, 24 );
            p.ties = BitConverter.ToUInt64( convert, 32 );
            p.highestMoney = BitConverter.ToUInt64( convert, 40 );
            p.busts = BitConverter.ToUInt64( convert, 48 );
            p.splits = BitConverter.ToUInt64( convert, 56 );
            p.dds = BitConverter.ToUInt64( convert, 64 );
            p.surrenders = BitConverter.ToUInt64( convert, 72 );
            p.moneyResets = BitConverter.ToUInt64( convert, 80 );

            return p;
        }
Ejemplo n.º 20
0
 public static void ReportStats(Player[] players, Player dealer)
 {
     players.Where(x => null != x).ToArray().ForEach(x => Console.Out.WriteLine(x.ToString()));
     //new TraceLogger().WriteLine(dealer.ToString());
     Console.Out.WriteLine(dealer.ToString());
 }
Ejemplo n.º 21
0
        public void split_logic2()
        {
            Card c1 = new Card(7, "7C");
            Card c2 = new Card(7, "DH");
            Player p = new Player();
            p.add_card(c1);
            p.add_card(c2);
            p.Player_Money = 0;
            p.bets[0] = 10;
            p.Player_Bet = 10;
            int expected_money = 0;
            int expected_total = 10;
            bool expected = false;

            //Act
            bool actual = p.split_logic();
            int actual_money = p.Player_Money;
            int actual_total = p.Player_Bet;

            Assert.AreEqual(expected_money, actual_money, "Player money should be 10");
            Assert.AreEqual(expected_total, actual_total, "Total player bet should be 10");
            Assert.AreEqual(expected, actual, "Player should not have another hand");
        }
Ejemplo n.º 22
0
        public void hit_logic3()
        {
            Card c1 = new Card(7, "7C");
            Card c2 = new Card(10, "DH");
            Card c3 = new Card(2, "2C");
            Player p = new Player();
            p.add_card(c1);
            p.add_card(c2);
            p.add_card(c3);
            bool expected = true;

            bool actual = p.hit_logic();

            Assert.AreEqual(expected, actual, "Player does not bust on 19");
        }
Ejemplo n.º 23
0
        void Payout(Player[] players, Player dealer)
        {
            var tmp = new List<Player>(players);

            var sb = new StringBuilder();
            foreach (var card in dealer.Hand)
            {
                sb.AppendFormat("{0} - {1}\n", card.CardFace, card.Suit);
            }
            logger.WriteLine("\n\nDEALER ({1}) \n{0} ", sb, dealer.Hand.Final);

            foreach (var player in players)
            {
                logger.WriteLine("Player: {0}({2}) \n{1} ", player.Name,
                    player.ToStringOfHand(), player.Hand.Final);
            }
            if (dealer.Hand.IsBlackjack)
            {
                logger.WriteLine("dealer got blackjack");
                var ties = tmp.Where(x => x.Hand.IsBlackjack).ToArray();
                foreach (var player in ties)
                {
                    logger.WriteLine("loss from dealer bj");
                    player.Payout(0);
                    tmp.Remove(player);
                }
                var losers = tmp.Except(ties);

                losers.ForEach(x => x.Payout(-1));
                dealer.Payout(1);
                return;
            }

            var busted = tmp.Where(x => x.Hand.IsBusted).ToArray();
            if (busted.Any())
            {
                foreach (var player in busted)
                {
                    player.Payout(-1);
                    tmp.Remove(player);
                }
            }

            if (dealer.Hand.IsBusted)
            {
                logger.WriteLine("Dealer busted");
                var winners = tmp.Where(x => !x.Hand.IsBusted).ToArray();
                foreach (var player in winners)
                {
                    player.Payout(1);
                    tmp.Remove(player);
                }

                dealer.Payout(-1);
            }
            else
            {
                var winners = tmp.Where(x => x.Hand.Final > dealer.Hand.Final && !x.Hand.IsBusted).ToArray();

                foreach (var player in winners)
                {
                    player.Payout(1);
                    tmp.Remove(player);
                }
                var ties = tmp.Where(x => x.Hand.Final == dealer.Hand.Final && !x.Hand.IsBusted).ToArray();
                foreach (var player in ties)
                {
                    player.Payout(0);
                    tmp.Remove(player);
                }
                var losers = tmp.Where(x => !x.Hand.IsBusted);
                losers.ForEach(x => x.Payout(-1));
            }
            dealer.Reset();
        }
Ejemplo n.º 24
0
        private void button3_Click(object sender, EventArgs e)
        {
            //create Blackjack table/cards
            gameTable1.create_Deck(1);
            gameTable1.shuffle_Deck();

            this.menuItem5.Enabled = true;
            this.button5.Visible = true;
            this.button6.Visible = true;
            this.button7.Visible = true;
            this.button8.Visible = true;
            this.button9.Visible = true;
            this.button11.Visible = true;

            this.button3.Visible = false;
            this.button4.Visible = false;

            this.richTextBox1.Visible = true;
            this.richTextBox2.Visible = true;

            if (tempName.ShowDialog() == DialogResult.OK)
            {
                MessageBox.Show("To start select the bet amount by clicking the Chips and then click Bet!");
                Player one = new Player(tempName.InputResult, 1);

                MainForm.gameTable1.add_Player(one);

                textBox1.Text = one.get_Name();
                textBox1.Visible = true;

                textBox2.Visible = true;
                textBox3.Visible = true;
                textBox4.Visible = true;
                textBox5.Visible = true;

                textBox1.TextAlign = ContentAlignment.MiddleCenter;
                textBox2.TextAlign = ContentAlignment.MiddleCenter;
                textBox3.TextAlign = ContentAlignment.MiddleCenter;
                textBox4.TextAlign = ContentAlignment.MiddleCenter;
                textBox5.TextAlign = ContentAlignment.MiddleCenter;
                textBox6.TextAlign = ContentAlignment.MiddleCenter;
            }

            this.pictureBox2.Enabled = true;
            this.pictureBox3.Enabled = true;
            this.pictureBox4.Enabled = true;
            this.pictureBox5.Enabled = true;
        }
Ejemplo n.º 25
0
        private void Client_DataReceived(object receivedObject)
        {
            if (receivedObject is NetworkObjects.PlayerJoined)
            {
                NetworkObjects.PlayerJoined newPlayerMsg = receivedObject as NetworkObjects.PlayerJoined;
                Player newPlayer = new Player(newPlayerMsg.Name, 1);

                int id = MainForm.gameTable1.add_Player(newPlayer);

                if (id != -1)
                {
                    if (id == 0)
                        SetLabelText(textBox1, newPlayerMsg.Name);
                    else if (id == 1)
                        SetLabelText(textBox2, newPlayerMsg.Name);
                    else if (id == 2)
                        SetLabelText(textBox3, newPlayerMsg.Name);
                    else if (id == 3)
                        SetLabelText(textBox4, newPlayerMsg.Name);
                    else if (id == 4)
                        SetLabelText(textBox5, newPlayerMsg.Name);
                }

                //MessageBox.Show(newPlayerMsg.Name + " joined the game");
            }
            else if (receivedObject is NetworkObjects.JoinGameResponse)
            {
                NetworkObjects.JoinGameResponse joinResponseMsg = receivedObject as NetworkObjects.JoinGameResponse;
                if(joinResponseMsg.Success)
                {
                    //create Blackjack table/cards
                    OnJoinGameSuccess();
                }
            }
            else if (receivedObject is NetworkObjects.PlayerListing)
            {
                NetworkObjects.PlayerListing playerListingMsg = receivedObject as NetworkObjects.PlayerListing;

                int i = 0;
                foreach(NetworkObjects.PlayerListing.Player player in playerListingMsg.Players)
                {
                    if (i == 0)
                        SetLabelText(textBox1, player.Name);
                    else if (i == 1)
                        SetLabelText(textBox2, player.Name);
                    else if (i == 2)
                        SetLabelText(textBox3, player.Name);
                    else if (i == 3)
                        SetLabelText(textBox4, player.Name);
                    else if (i == 4)
                        SetLabelText(textBox5, player.Name);

                    i++;
                }
            }
        }
Ejemplo n.º 26
0
        // Join active game
        private void button4_Click(object sender, EventArgs e)
        {
            this.button3.Visible = false;
            this.button4.Visible = false;

            InputName input = new InputName(this);
            if (input.ShowDialog() == DialogResult.OK)
            {
                Player one = new Player(input.InputResult, 1);
                MainForm.gameTable1.add_Player(one);

                this.labelJoiningGame.Visible = true;
                NetworkObjects.JoinGame joinGameMsg = new NetworkObjects.JoinGame();
                joinGameMsg.Name = input.InputResult;
                client.Send(joinGameMsg);
            }

            /*
            this.button5.Visible = true;
            this.button6.Visible = true;
            this.button7.Visible = true;
            this.button8.Visible = true;
            this.button9.Visible = true;

            this.richTextBox1.Visible = true;
            this.richTextBox2.Visible = true;
            */
        }
Ejemplo n.º 27
0
        public void double_down_logic2()
        {
            Card c1 = new Card(7, "7C");
            Card c2 = new Card(10, "DH");
            Card c3 = new Card(4, "4C");
            Player p = new Player();
            string expected_status = "21";
            p.add_card(c1);
            p.add_card(c2);
            p.add_card(c3);
            p.nr_of_hands++;

            p.hand[1] = new List<Card>();
            p.hand[1].Add(c1);
            p.hand[1].Add(c2);
            bool expected = true;

            bool actual = p.double_down_logic();
            string actual_status = p.Hand_Status;

            Assert.AreEqual(expected_status, actual_status, "Player should have 21");
            Assert.AreEqual(expected, actual, "Player should have another hand");
        }
Ejemplo n.º 28
0
        public void hit_logic2()
        {
            Card c1 = new Card(7, "7C");
            Card c2 = new Card(10, "DH");
            Card c3 = new Card(4, "4C");
            Player p = new Player();
            p.add_card(c1);
            p.add_card(c2);
            p.add_card(c3);
            bool expected = false;

            bool actual = p.hit_logic();

            Assert.AreEqual(expected, actual, "Player stops on 21");
        }
Ejemplo n.º 29
0
        static void Main(string[] args)
        {
            Boolean playAgain = true;
            IParticipant player = new Player();
            Dealer dealer = new Dealer();

            Console.Write("Enter Player name: ");
            player.Name = Console.ReadLine();
            Console.WriteLine();

            while (playAgain)
            {
                Boolean bust = false;
                dealer.DealerShow();
                Console.WriteLine();

                int playerSum = player.Play();
                Console.WriteLine();

                int dealerSum = 0;

                if (playerSum <= 21)
                {
                    dealerSum = dealer.Play();
                    Console.WriteLine();
                }
                else
                {
                    Console.WriteLine("Bust! You lose.");
                    bust = true;
                }

                if (!bust)
                {
                    if (dealerSum < playerSum || dealerSum > 21)
                    {
                        if (playerSum == 21)
                        {
                            Console.WriteLine("Blackjack!");
                        }
                        Console.WriteLine("Congrats! You beat the dealer.");
                    }
                    else if (dealerSum == playerSum)
                    {
                        Console.WriteLine("You neither win nor lose.");
                    }
                    else
                    {
                        Console.WriteLine("Sorry, you lose.");
                    }
                }

                Console.WriteLine();
                Console.WriteLine("Hit y to play again. Any other key to exit.");
                String play = Console.ReadLine();
                if (play.Equals("y") || play.Equals("Y"))
                    playAgain = true;
                else
                    playAgain = false;

                Console.Clear();
            }
        }
Ejemplo n.º 30
0
 private void PlayHand(Player player)
 {
     var play = player.Play(player.Hand, _dealer.Hand.First());
     if (play == PlayAction.Stay)
     {
         return;
     }
     if (play == PlayAction.Hit)
     {
         var c = Deal();
         var bust = player.TakeCard(c);
         if (!bust)
         {
             PlayHand(player);
         }
     }
     else if (play == PlayAction.Double)
     {
         if (player.Hand.Count() != 2)
         {
             throw new Exception("only double on first");
         }
         player.TakeCard(Deal());
     }
 }