Beispiel #1
0
 private static Dealer MakeDealer(int deckCount)
 {
     //set up the dealer
     var Dealer = new Dealer(deckCount);
     Dealer.Shuffle();
     return Dealer;
 }
Beispiel #2
0
 public BlackjackTable()
 {
     game_Id = 666;
     round_Count = 0;
     deck = new List<Card>();
     table = new Player[5];
     dealer = new Dealer("Dealer", 888);
     min_Bet = 1;
     test = new Form();
 }
        int s_id; //save id rowguid for current game being saved or loaded

        #endregion Fields

        #region Constructors

        private Bj_interaction()
        {
            player_column = 0;
            move_visibility = false;
            done_button_visibility = false;
            deal_button_visibility = false;
            bets_placed = 0;
            players = new Players();
            deck = new CardDeck();
            dealer = new Dealer();
        }
Beispiel #4
0
 public BlackjackActionResult Play(BlackjackAction action, Dealer dealer)
 {
     //perform the action specified for this player
     switch (action)
     {
         case BlackjackAction.Hit:
             GiveCard(dealer.TakeCard());
             break;
     }
     LastAction = action;
     return Bust ? BlackjackActionResult.Bust : BlackjackActionResult.Ok;
 }
Beispiel #5
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;
 }
Beispiel #6
0
        public void dealer_blackjack2()
        {
            //arrange
            Dealer d = new Dealer();
            d.add_card(1);
            d.add_card(9);

            bool expected = false;

            //act
            bool actual = d.dealer_blackjack();

            // assert
            Assert.AreEqual(expected, actual, "Wrong!");
        }
Beispiel #7
0
        public void dealer_logic_false1()
        {
            //arrange
            Dealer d = new Dealer();
            d.add_card(1);
            d.add_card(6);

            bool expected = false;

            //act
            bool actual = d.logic();

            // assert
            Assert.AreEqual(expected, actual, "Wrong!");
        }
Beispiel #8
0
        private void StartGame()
        {
            lblMsg.Text           = "";
            btnHit.Enabled        = true;
            btnStand.Enabled      = true;
            lblCustomerPt.Visible = true;
            lblDealerPt.Visible   = true;

            btnHit.BackColor   = Color.LimeGreen;
            btnStand.BackColor = Color.LimeGreen;

            deck     = Deck.GetDeck();
            dealer   = Dealer.GetDealer();
            customer = Customer.GetCustomer();

            for (int i = 0; i < 2; i++) //Two cards must be dealed in the beginning
            {
                DealCards(i, deck, dealer);
                DealCards(i, deck, customer);
            }

            ControlForCustomer();   //Check if customer is blackjack
        }
Beispiel #9
0
        private static PlayerOutcome GetPlayerOutcome(Player player, Dealer dealer)
        {
            var dealerSum = dealer.Sum;

            if (dealer.HasUnusedAceCard)
            {
                dealerSum = dealer.AcedSum;
            }

            var playerSum = player.Sum;

            if (player.HasUnusedAceCard)
            {
                playerSum = player.AcedSum;
            }

            if (playerSum <= BlackjackThreshold && playerSum > dealerSum)
            {
                return(PlayerOutcome.Win);
            }

            return(PlayerOutcome.Lost);
        }
Beispiel #10
0
        public void calculate_win1()
        {
            //
            Card c1 = new Card(8, "C8");
            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 = 20;
            p.Player_Bet = starting_bet;
            p.bets[0] = 10;

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

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

            //Assert
            Assert.AreEqual(final_bet, actual, "Player wins!");
        }
Beispiel #11
0
        public void DealerLoop(Dealer dealer, Deck deck)
        {
            bool dealerHitting = true;

            while (dealerHitting)
            {
                if (dealer.AddCards() < 17)
                {
                    dealer.DealSelf(deck);
                    bool dealerBusted = dealer.CheckForBust(this);
                    if (dealerBusted)
                    {
                        Console.WriteLine("The dealer busted!");
                        dealerHitting = false;
                        gameOver      = true;
                    }
                }
                else
                {
                    dealerHitting = false;
                }
                dealer.DisplayHand();
            }
        }
Beispiel #12
0
        /// <summary>
        /// Initialize Deck, deal the player and dealer hands, and display them.
        /// </summary>
        static void InitializeHands()
        {
            deck.Initialize();

            player.Hand          = deck.DealHand();
            Dealer.HiddenCards   = deck.DealHand();
            Dealer.RevealedCards = new List <Card>();

            // If hand contains two aces, make one Hard.
            if (player.Hand[0].Face == Face.Ace && player.Hand[1].Face == Face.Ace)
            {
                player.Hand[1].Value = 1;
            }

            if (Dealer.HiddenCards[0].Face == Face.Ace && Dealer.HiddenCards[1].Face == Face.Ace)
            {
                Dealer.HiddenCards[1].Value = 1;
            }

            Dealer.RevealCard();

            player.WriteHand();
            Dealer.WriteHand();
        }
Beispiel #13
0
        public BlackjackResult GetResult(Dealer dealer)
        {
            //return the final result for this player
            if(Bust)
            {
                return BlackjackResult.Lose;
            }
            if(dealer.Bust)
            {
                return BlackjackResult.Win;
            }
            int PlayerScore = GetScore();
            int DealerScore = dealer.GetScore();

            if(PlayerScore < DealerScore)
            {
                return BlackjackResult.Lose;
            }
            if(PlayerScore > DealerScore)
            {
                return BlackjackResult.Win;
            }
            return BlackjackResult.Draw;
        }
Beispiel #14
0
        static void Main(string[] args)
        {
            Console.OutputEncoding = System.Text.Encoding.UTF8;
            Console.WriteLine("Нажмите любую кнопку, чтобы начать игру");
            Console.ReadKey();

            Player player = new Player(1000);

            while (true)
            {
                Queue <Card> deck   = new Queue <Card>(Card.RandomDeck());
                Dealer       dealer = new Dealer(new List <Card>()
                {
                    deck.Dequeue(), deck.Dequeue()
                }, player, deck);
                Console.Clear();
                Console.WriteLine("Ваша ставка(денег на счету: " + player.money + "): ");
                int bet;
                while (true)
                {
                    if (int.TryParse(Console.ReadLine(), out bet) && bet > 0)
                    {
                        if (bet > player.money)
                        {
                            Console.WriteLine("У вас не хватает денег для такой ставки, попробуйте еще раз");
                        }
                        else
                        {
                            break;
                        }
                    }
                    else
                    {
                        Console.WriteLine("Вы ввели некорректное число");
                    }
                }

                player.money -= bet;
                player.NewGame(new Game(bet, new List <Card> {
                    deck.Dequeue(), deck.Dequeue()
                }));
                while (player.HasActiveGames())
                {
                    Game game = player.active_game;
                    PrintUserInformation(player);
                    PrintDealerInformation(dealer);
                    Actions action = GetAction(player, game);
                    if (action == Actions.Hit)
                    {
                        game.AddCart(deck.Dequeue());
                        PrintUserInformation(player);
                        if (game.status == Game.Statuses.TooMuch)
                        {
                            player.NextGame();
                        }
                    }
                    if (action == Actions.Quit)
                    {
                        player.NextGame();
                    }
                    if (action == Actions.Double)
                    {
                        player.money -= game.bet;
                        game.bet     *= 2;
                        game.AddCart(deck.Dequeue());
                        player.NextGame();
                    }
                    if (action == Actions.Split)
                    {
                        player.NewGame(new Game(new List <Card> {
                            game.cards[1]
                        }));
                        game.cards.RemoveAt(1);
                    }
                }
                dealer.Play();
                PrintUserInformation(player);
                PrintDealerInformation(dealer);
                Console.WriteLine("Итог раунда:");
                for (int i = 0; i < player.games.Count; i++)
                {
                    Game game = player.games[i];
                    int  score = game.GetScore(), dealerScore = dealer.GetScore();
                    Console.WriteLine("Рука #" + (i + 1) + ":");
                    if (game.status == Game.Statuses.Quit && dealer.status != Game.Statuses.TooMuch)
                    {
                        if (score > dealerScore)
                        {
                            Console.WriteLine("У вас больше, вы выиграли!");
                            player.money += game.bet * 2;
                        }
                        else if (score < dealerScore)
                        {
                            Console.WriteLine("У вас меньше, вы проиграли!");
                        }
                        else
                        {
                            Console.WriteLine("Ничья!");
                            player.money += game.bet;
                        }
                    }
                    if (game.status == Game.Statuses.Quit && dealer.status == Game.Statuses.TooMuch)
                    {
                        Console.WriteLine("У дилера перебор, вы выиграли!");
                        player.money += game.bet * 2;
                    }
                    if (game.status == Game.Statuses.TooMuch && dealer.status == Game.Statuses.Quit)
                    {
                        Console.WriteLine("У вас перебор!");
                    }
                    if (game.status == Game.Statuses.TooMuch && dealer.status == Game.Statuses.TooMuch)
                    {
                        Console.WriteLine("У вас и у дилера перебор, ничья!");
                        player.money += game.bet;
                    }
                }
                player.games = new List <Game>();
                Console.ReadKey();
            }
        }
Beispiel #15
0
 static void PrintDealerInformation(Dealer dealer)
 {
     Console.WriteLine("Карты дилера:");
     PrintCards(dealer.cards, (dealer.IsHidden() ? 1 : 0));
     Console.WriteLine("Очки дилера: " + (dealer.IsHidden() ? "x" : dealer.GetScore().ToString()));
 }
Beispiel #16
0
        // How we start the game
        static void StartRound()
        {
            Clear();

            if (!TakeBet())
            {
                EndRound(RoundResult.INVALID_BET);
                return;
            }
            Clear();

            StartHands();
            Actions();

            Dealer.ShowCard();

            Clear();
            player.WriteHand();
            Dealer.WriteHand();

            player.HandsCompleted++;

            if (player.Hand.Count == 0)
            {
                EndRound(RoundResult.FOLD);
                return;
            }
            else if (player.GetHandValue() > 21)
            {
                EndRound(RoundResult.PLAYER_BUST);
                return;
            }

            while (Dealer.GetHandValue() <= 16)
            {
                Dealer.RevealedCards.Add(deck.DrawCard());

                Clear();
                player.WriteHand();
                Dealer.WriteHand();
            }


            if (player.GetHandValue() > Dealer.GetHandValue())
            {
                player.Wins++;
                if (Casino.IsHandBlackjack(player.Hand))
                {
                    EndRound(RoundResult.PLAYER_BLACKJACK);
                }
                else
                {
                    EndRound(RoundResult.PLAYER_WIN);
                }
            }
            else if (Dealer.GetHandValue() > 21)
            {
                player.Wins++;
                EndRound(RoundResult.PLAYER_WIN);
            }
            else if (Dealer.GetHandValue() > player.GetHandValue())
            {
                EndRound(RoundResult.DEALER_WIN);
            }
            else
            {
                EndRound(RoundResult.PUSH);
            }
        }
Beispiel #17
0
        static void Main(string[] args)
        {
            do
            {
                // Start game
                Console.WriteLine("Welcome to Blackjack!");
                //shuffle deck
                var deck = new Deck();
                deck.Shuffle();
                //deal cards
                var  dealer     = new Dealer();
                Hand playerHand = new Hand();
                Hand compHand   = new Hand();
                //player gets cards
                dealer.Deal(deck, playerHand);
                int playerScore = playerHand.newHand[0].Value + playerHand.newHand[1].Value;
                Console.WriteLine($"Player hand: {playerHand.newHand[0].Suit} {playerHand.newHand[0].Face} {playerHand.newHand[1].Suit} {playerHand.newHand[1].Face}");
                Console.WriteLine($"Player score: {playerScore}");
                //dealer gets cards
                dealer.Deal(deck, compHand);
                int compScore = compHand.newHand[0].Value + compHand.newHand[1].Value;
                Console.WriteLine($"Dealer hand: {compHand.newHand[0].Suit} {compHand.newHand[0].Face} {compHand.newHand[1].Suit} {compHand.newHand[1].Face}");
                Console.WriteLine($"Dealer score: {compScore}");
                Console.WriteLine($"Number of cards left: {deck.cards.Count()}");
                //does everyone have 21? tie game
                if (compScore == 21 && playerScore == 21)
                {
                    Console.WriteLine("Both players have 21! Tie!");
                }
                //does dealer have 21? dealer win
                else if (compScore == 21)
                {
                    Console.WriteLine("Blackjack for the Dealer! 21!");
                }
                //does player have 21? player win
                else if (playerScore == 21)
                {
                    Console.WriteLine("Blackjack for you! 21! You win!");
                }
                else
                {
                    //class Player.Hit(), Stay() if 21 autostay, if score > 21 switch Ace to 1
                    var user = new Player();
                    Console.Write("(H)it or (S)tay: ");
                    string input    = Console.ReadLine();
                    var    userPlay = user.CheckInput(input, deck, playerHand);
                    if (userPlay == true)
                    {
                        Console.WriteLine("Computer turn!");
                        var dealerPlay = dealer.Play(deck, compHand);
                        if (dealerPlay == true)
                        {
                            //resolve scores
                            Console.WriteLine("scores are vs");
                        }
                        else
                        {
                            Console.WriteLine("You win! Dealer busted.");
                        }
                    }
                    else
                    {
                        Console.WriteLine("You busted! Over 21");
                    }

                    Console.Write("Player hand: ");
                    for (int i = 0; i < playerHand.newHand.Count(); i++)
                    {
                        Console.Write($"{playerHand.newHand[i].Suit} {playerHand.newHand[i].Face} ");
                    }
                    Console.WriteLine($"Player score: {playerScore}");
                }

                Console.WriteLine("Play again? y/n");
                restart = Convert.ToChar(Console.ReadLine());
            } while (restart == 'y');
        }
Beispiel #18
0
 private void Start()
 {
     Dealer.DrawTwoCardsToAll(GameDeck, Player);
 }
Beispiel #19
0
 private void DealerAct()
 {
     Dealer.Play(GameDeck);
 }
Beispiel #20
0
        public void Play()
        {
            Console.WriteLine("\nGame starting...");

            // Make bet
            Console.WriteLine($"Your chips: {Player.Chips.Value}");
            Console.WriteLine("Enter your bet:");
            string input = Console.ReadLine();

            Player.MakeBet(Int32.Parse(input));


            // Deal cards
            Player.Hand.AddToHand(Deck.Deal(2));
            Dealer.Hand.AddToHand(Deck.Deal(1));

            // Show Dealer hand
            Console.WriteLine($"The Dealer has {Dealer.Score}");

            // Loop for Player
            while (!Player.IsTurnComplete)
            {
                Console.WriteLine($"Your score is {Player.Score}");

                if (Player.IsBust)
                {
                    break;
                }

                Console.WriteLine("Do you want to [h]it or [s]tand?");
                var ans = Console.ReadLine();
                if (ans == "h")
                {
                    Player.Hit();
                }
                else
                {
                    Player.Stand();
                    Console.WriteLine($"You stand on {Player.Score}");
                }
            }

            // Loop for Dealer
            while (!Dealer.IsTurnComplete && !Player.IsBust)
            {
                Console.WriteLine($"The Dealer is on {Dealer.Score}");

                if (Dealer.IsBust)
                {
                    break;
                }

                if (Dealer.Score < 17)
                {
                    Dealer.Hit();
                }
                else
                {
                    Dealer.Stand();
                }
            }

            // Evaluate Winner
            if (Player.IsBust)
            {
                Console.WriteLine("Bust - You lose.");
                Player.LoseBet();
                Console.WriteLine($"Your chips: {Player.Chips.Value}");

                return;
            }

            if (Dealer.IsBust)
            {
                Console.WriteLine("Dealer bust - You win!");
                Player.WinBet();
                Console.WriteLine($"Your chips: {Player.Chips.Value}");

                return;
            }

            if (Player.Score > Dealer.Score)
            {
                Console.WriteLine($"Your score of {Player.Score} beats the Dealer's {Dealer.Score} - You win!");
                Player.WinBet();
                Console.WriteLine($"Your chips: {Player.Chips.Value}");

                return;
            }
            else if (Dealer.Score == Player.Score)
            {
                Console.WriteLine("Push!");

                return;
            }
            else
            {
                Console.WriteLine($"The Dealer's score of {Dealer.Score} beats your {Player.Score} - You lose.");
                Player.LoseBet();
                Console.WriteLine($"Your chips: {Player.Chips.Value}");

                return;
            }

            // Log chips
        }
 internal static void Double(Hand playerHand, Dealer dealer, GameDeck gameDeck)
 {
     dealer.DrawCardToHand(gameDeck, playerHand);
     playerHand.Bet *= 2;
     playerHand.Flag = HandState.Stand;
 }
Beispiel #22
0
        /// <summary>
        /// Ask user for action and perform that action until they stand, double, or bust.
        /// </summary>
        static void TakeActions()
        {
            string action;

            do
            {
                Console.Clear();
                player.WriteHand();
                Dealer.WriteHand();

                Console.Write("Enter Action (? for help): ");
                Console.ForegroundColor = ConsoleColor.Cyan;
                action = Console.ReadLine();
                Casino.ResetColor();

                switch (action.ToUpper())
                {
                case "HIT":
                    player.Hand.Add(deck.DrawCard());
                    break;

                case "STAND":
                    break;

                case "SURRENDER":
                    player.Hand.Clear();
                    break;

                case "DOUBLE":
                    if (player.Chips <= player.Bet)
                    {
                        player.AddBet(player.Chips);
                    }
                    else
                    {
                        player.AddBet(player.Bet);
                    }
                    player.Hand.Add(deck.DrawCard());
                    break;

                default:
                    Console.WriteLine("Valid Moves:");
                    Console.WriteLine("Hit, Stand, Surrender, Double");
                    Console.WriteLine("Press any key to continue.");
                    Console.ReadKey();
                    break;
                }

                if (player.GetHandValue() > 21)
                {
                    foreach (Card card in player.Hand)
                    {
                        if (card.Value == 11) // Only a soft ace can have a value of 11
                        {
                            card.Value = 1;
                            break;
                        }
                    }
                }
            } while (!action.ToUpper().Equals("STAND") && !action.ToUpper().Equals("DOUBLE") &&
                     !action.ToUpper().Equals("SURRENDER") && player.GetHandValue() <= 21);
        }
Beispiel #23
0
 public Round(Dealer dealer, Player[] players, Game.Game game)
 {
     this.Dealer  = dealer;
     this.Players = players;
     this.Game    = game;
 }
Beispiel #24
0
        /// <summary>
        /// Initializes player turn to true. Gives user a breakdown of the hands and scores, and asks for first reaction. Contains the rest of the logic for every possible outcome.
        /// </summary>
        /// <param name="player"></param>
        /// <param name="dealer"></param>
        /// <param name="deck"></param>
        /// <param name="rnd"></param>
        /// <param name="playerHand"></param>
        /// <param name="dealerHand"></param>
        public void PlayGame(Player player, Dealer dealer, Deck deck, Random rnd, List <Card> playerHand, List <Card> dealerHand)
        {
            var playerTurn = true;

            Console.WriteLine(String.Format("Your hand:\n\n{0} of {1}\n{2} of {3}\n\nThe Dealer's hand:\n\n{4} of {5}\nHidden", player.Hand[0].Name, player.Hand[0].Suit, player.Hand[1].Name, player.Hand[1].Suit, dealer.Hand[0].Name, dealer.Hand[0].Suit, dealer.Hand[1].Name, dealer.Hand[1].Suit));
            Console.WriteLine(String.Format("\nNumber of cards in deck: {0}\n", deck.Cards.Count));
            Console.WriteLine(String.Format("\nYour Score: {0}\nDealer Score: Hidden\n", player.Score, dealer.Score));
            Console.WriteLine("Would you like to:\n\n1: Hit\n2: Stay\n");
            player.PlayerInput = Console.ReadLine();

            while (player.Score <= 21 && dealer.Score <= 21)
            {
                while (player.Score <= 21 && playerTurn)
                {
                    // takes in user input, and if user picks hit, new random card is removed from deck and placed into player hand, then it asks for next input. Continues while it's the player's turn.
                    if (player.PlayerInput == "1")
                    {
                        var rndNum  = rnd.Next(deck.Cards.Count);
                        var rndCard = deck.Cards[rndNum];
                        playerHand.Add(rndCard);
                        player.Score += rndCard.Value;
                        deck.Cards.Remove(rndCard);
                        Console.WriteLine(String.Format("\nYou have been dealt a {0} of {1}\nYour score is: {2}", rndCard.Name, rndCard.Suit, player.Score));
                        Console.WriteLine(String.Format("\nNumber of cards in deck: {0}", deck.Cards.Count));
                        Console.WriteLine("Would you like to:\n\n1: Hit\n2: Stay\n");
                        player.PlayerInput = Console.ReadLine();
                    }
                    else if (player.PlayerInput == "2")
                    {
                        Console.WriteLine("\nYou stay");
                        Console.ReadLine();
                        playerTurn = false;
                    }
                }
                if (player.Score > 21)
                {
                    for (int i = 0; i < playerHand.Count; i++)
                    {
                        if (playerHand[i].Name == "Ace")
                        {
                            playerHand[i].Value = 1;
                        }
                        else
                        {
                            PlayerLose();
                        }
                    }
                }
                else
                {
                    playerTurn = false;
                }
                // while it's the dealer's turn, contains logic for all different outcomes of the game
                while (!playerTurn && dealer.Score <= 17 || player.Score > dealer.Score && (dealer.Score >= 17))
                {
                    var rndNum  = rnd.Next(deck.Cards.Count);
                    var rndCard = deck.Cards[rndNum];

                    dealerHand.Add(rndCard);
                    deck.Cards.Remove(rndCard);
                    dealer.Score += rndCard.Value;
                    dealer.Hand   = dealerHand;
                    Console.WriteLine(String.Format("\nThe dealer has been dealt a {0} of {1}\nHis score is: {2}", rndCard.Name, rndCard.Suit, dealer.Score));
                    Console.ReadLine();

                    if (dealer.Score > 21)
                    {
                        for (int i = 0; i < dealerHand.Count; i++)
                        {
                            if (dealerHand[i].Name == "Ace")
                            {
                                dealerHand[i].Value = 1;
                            }
                            else
                            {
                                PlayerWin();
                            }
                        }
                    }
                    else if (dealer.Score > 21 && player.Score <= 21)
                    {
                        PlayerWin();
                    }
                    else if (dealer.Score <= 21 && player.Score > 21)
                    {
                        PlayerLose();
                    }
                    else if (dealer.Score >= 17 && player.Score >= 17 && (dealer.Score == player.Score))
                    {
                        PlayerLose();
                    }
                }
                if (player.Score <= 21 && (dealer.Score >= player.Score && dealer.Score <= 21))
                {
                    PlayerLose();
                }
                else if (player.Score <= 21 && (dealer.Score <= 21 && dealer.Score == player.Score))
                {
                    PlayerLose();
                }
                else if (player.Score > 21)
                {
                    PlayerLose();
                }
                else if (dealer.Score > 17 && dealer.Score <= 21 && (dealer.Score >= player.Score))
                {
                    PlayerLose();
                }
                else if (dealer.Score >= 17 && dealer.Score <= 21 && player.Score <= 21 && (dealer.Score > player.Score))
                {
                    PlayerLose();
                }
            }
        }
        public void Finish(Dealer dealer)
        {
            foreach (Hand hand in Hands)
            {
                if (hand.Score == 21)
                {
                    if (hand.Cards.Count == 2)
                    {
                        if (dealer.Score == 21)
                        {
                            if (dealer.Cards.Count != 2)
                            {
                                double prize = (double)hand.Bet * 1.5;
                                Hands[0].Bet = 0;
                                Money       += (int)prize;
                                WriteFinishMessage(hand, dealer);
                            }
                            else
                            {
                                Money   += hand.Bet;
                                hand.Bet = 0;
                                WriteFinishMessage(hand, dealer);
                            }
                        }
                        else
                        {
                            double prize = (double)hand.Bet * 1.5;
                            Hands[0].Bet = 0;
                            Money       += (int)prize;
                            WriteFinishMessage(hand, dealer);
                        }
                    }
                    else
                    {
                        if (dealer.Score == 21)
                        {
                            Money   += hand.Bet;
                            hand.Bet = 0;
                            WriteFinishMessage(hand, dealer);
                        }
                        else
                        {
                            double prize = (double)hand.Bet * 1.5;
                            Hands[0].Bet = 0;
                            Money       += (int)prize;
                            WriteFinishMessage(hand, dealer);
                        }
                    }
                }
                else if (hand.Score > 21)
                {
                    hand.Bet = 0;
                    WriteFinishMessage(hand, dealer);
                }
                else
                {
                    if (dealer.Score > hand.Score && dealer.Score <= 21)
                    {
                        hand.Bet = 0;
                        WriteFinishMessage(hand, dealer);
                    }
                    else if (dealer.Score > 21)
                    {
                        double prize = (double)hand.Bet * 1.5;
                        Hands[0].Bet = 0;
                        Money       += (int)prize;
                        WriteFinishMessage(hand, dealer);
                    }
                    else if (dealer.Score < hand.Score)
                    {
                        double prize = (double)hand.Bet * 1.5;
                        Hands[0].Bet = 0;
                        Money       += (int)prize;
                        WriteFinishMessage(hand, dealer);
                    }
                    else if (dealer.Score == hand.Score)
                    {
                        Money   += hand.Bet;
                        hand.Bet = 0;
                        WriteFinishMessage(hand, dealer);
                    }
                }

                hand.Score = 0;
                hand.Cards.Clear();
            }
            if (Hands.Count == 2)
            {
                Hands.RemoveAt(1);
            }
        }
 public abstract void GetInsurance(Dealer dealer);
Beispiel #27
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();
            }
        }
Beispiel #28
0
 public Game()
 {
     Deck   = new Deck();
     Player = new Player(Deck, 200);
     Dealer = new Dealer(Deck);
 }
Beispiel #29
0
 public void Reset()
 {
     Player.Reset();
     Dealer.Reset();
 }
Beispiel #30
0
        static void Main(string[] args)
        {
            Console.WriteLine("★☆★☆★☆★☆★☆ブラックジャックへようこそ!★☆★☆★☆★☆★☆");
            Console.WriteLine("ゲームを開始します。");
            Console.WriteLine();

            Player player = new Player();
            Dealer dealer = new Dealer();

            ArrayList playingCards = Playingcards();

            string cardName;

            for (int i = 1; i <= 2; i++)
            {
                cardName = RandomCard(playingCards);            //ランダムにカードを引く
                Console.WriteLine($"あなたの引いたカードは{cardName}です。"); //出力する
                Console.WriteLine();
                player.Hiku(PointPlayer(cardName));             //カードを引く

                playingCards.Remove(cardName);                  //引く際にガードの重複はないようにする
            }

            cardName = RandomCard(playingCards);
            Console.WriteLine($"ディーナーの引いたカードは{cardName}です。");
            Console.WriteLine();
            dealer.Hiku(CardPoint(cardName));
            playingCards.Remove(cardName);
            cardName = RandomCard(playingCards);

            Console.WriteLine("ディーナーの2枚目のカードは分かりません。");
            Console.WriteLine();
            dealer.Hiku(CardPoint(cardName));
            dealer.SecondCard(cardName);
            playingCards.Remove(cardName);

            Console.WriteLine($"あなたの現在の得点は{player.GetPoints()}。");
            if (player.GetPoints() == 21)
            {
                Console.WriteLine("*☆,°*:.☆*☆,°*:.☆BLACKJACK!*☆,°*:.☆*☆,°*:.☆");
            }

            while (player.GetPoints() < 21) //プレイヤー21点まで引くか引かないかを聞く
            {
                Console.WriteLine("カードを引きますか?引く場合はYを、引かない場合はNを入力してください。");
                string input = Console.ReadLine();

                if (!(input == "Y" || input == "N"))
                {
                    Console.WriteLine("引く場合はYを、引かない場合はNを入力してください。");
                }

                else if (input == "Y")
                {
                    cardName = RandomCard(playingCards);
                    Console.WriteLine($"あなたの引いたカードは{cardName}です。");
                    player.Hiku(PointPlayer(cardName));
                    playingCards.Remove(cardName);
                    Console.WriteLine($"あなたの得点は{player.GetPoints()}です。");
                    Console.WriteLine();
                }

                else //引かない場合
                {
                    break;
                }
            }


            if (player.GetPoints() < 21)        //プレイヤーの点数が21より小さい、ディーラーがカードを引く
            {
                while (dealer.GetPoints() < 17) //ディーラーが17点まで引き続ける
                {
                    cardName = RandomCard(playingCards);
                    Console.WriteLine($"ディーナーの引いたカードは{cardName}です。");
                    dealer.Hiku(CardPoint(cardName));
                    playingCards.Remove(cardName);
                }
            }
            else if (player.GetPoints() > 21)
            {
                Console.WriteLine("!!!!!!!バースト!!!!!!!");
            }


            Console.WriteLine();
            Console.WriteLine($"ディーナーの2枚目のカードは{dealer.GetSecondCard()}です。");
            Console.WriteLine($"あなたの得点は{player.GetPoints()}です。");
            Console.WriteLine($"ディーナーの得点は{dealer.GetPoints()}です。");
            Console.WriteLine();
            Console.WriteLine("★☆★☆★☆★☆★☆★結果★☆★☆★☆★☆★☆★");
            WhoWin(player.GetPoints(), dealer.GetPoints());
            Console.WriteLine("★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆");
            Console.WriteLine("★★★ブラックジャック終了!また遊んでね!★★★");
        }
Beispiel #31
0
 public Game(Player player, Dealer dealer)
 {
     this.player = player;
     this.dealer = dealer;
     Shoe shoe = new Shoe(MAX_NUM_OF_DECKS);
 }
Beispiel #32
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!");
        }
Beispiel #33
0
 public void ResetGameDeck()
 {
     Dealer.ResetGameDeck(GameDeck);
 }
Beispiel #34
0
 public GameLoop(Player player, Dealer dealer, List <Card> playerHand, List <Card> dealerHand)
 {
 }
Beispiel #35
0
 //===== CONSTRUCTOR
 public Game()
 {
     Players = new List <Player>();
     Dealer  = new Dealer("", 0);
     Bets    = new Dictionary <Player, int>();
 }
Beispiel #36
0
        public static void PlayGame()
        {
            // Instantiate using optional argument constructor
            Dealer dealer = new Dealer();
            // Instantiate with named argument for player
            Player player = new Player(name: "Player");
            // Instantiate the deck
            Deck deck = new Deck();

            // Get player name
            Console.Write("Enter your name: ");
            player.Name = Console.ReadLine();

            bool playing = true;

            while (playing)
            {
                // Update games played and reset lost booleans
                ConsoleKey key;
                player.GamesPlayed++;
                player.Lost = false;
                dealer.Lost = false;

                // Deal initial cards
                player.Draw(deck);
                dealer.Draw(deck);
                player.Draw(deck);
                dealer.Draw(deck);

                Message(player.ToString());
                Message(dealer.ToString());

                // Allow player the choice to hit or stay
                bool playerChoice = true;
                while (playerChoice)
                {
                    Message("1: Hit \n2: Stay");
                    // Console.ReadKey(true) hides the key press in console
                    key = Console.ReadKey(true).Key;
                    // Player choice
                    if (key == ConsoleKey.D1)
                    {
                        player.Draw(deck);
                    }
                    else if (key == ConsoleKey.D2)
                    {
                        playerChoice = false;
                    }
                    // Check if player busted but has an ace
                    player.CheckForAce();
                    // Check if player busts, inverted to reduce nesting
                    if (player.SumHand() <= 21)
                    {
                        continue;
                    }
                    player.Bust();
                    playerChoice = false;
                }

                // Dealer draws until hand value < 17
                // No need to do this is player busts
                if (!player.Lost)
                {
                    while (dealer.SumHand() < 17)
                    {
                        dealer.Draw(deck);
                        // Check if dealer busted but has an ace
                        dealer.CheckForAce();
                        // Check if dealer busts
                        if (dealer.SumHand() <= 21)
                        {
                            continue;
                        }
                        dealer.Bust();
                    }
                }

                Message(player.ToString());
                Message(dealer.ToString());

                // Win/Lose Conditions
                if (player.Lost)
                {
                    dealer.Winner();
                }
                else if (dealer.Lost)
                {
                    player.Winner();
                }
                else if (player.SumHand() == dealer.SumHand())
                {
                    Message("Tie.");
                }
                else if (player.SumHand() > dealer.SumHand())
                {
                    player.Winner();
                }
                else
                {
                    dealer.Winner();
                }

                // Discard hands
                foreach (Card card in player.Hand)
                {
                    deck.Discard(card);
                }
                foreach (Card card in dealer.Hand)
                {
                    deck.Discard(card);
                }
                player.Hand = new List <Card>();
                dealer.Hand = new List <Card>();

                // Play again or exit
                Message("Press any key to play again or press 0 to exit. \n");
                key = Console.ReadKey(true).Key;
                Console.Clear();
                if (key == ConsoleKey.D0)
                {
                    playing = false;
                }
            }
        }
 internal static void Hit(Hand playerHand, Dealer dealer, GameDeck gameDeck)
 {
     dealer.DrawCardToHand(gameDeck, playerHand);
 }
Beispiel #38
0
        // Ask user for action and perform that action until they stay, double, or bust
        static void Actions()
        {
            string action;

            do
            {
                Clear();
                player.WriteHand();
                Dealer.WriteHand();

                Write("Enter Action (? for help): ");
                action = ReadLine();
                Casino.ColorReset();


                switch (action.ToUpper())
                {
                case "HIT":
                    player.Hand.Add(deck.DrawCard());
                    break;

                case "STAY":
                    break;

                case "FOLD":
                    player.Hand.Clear();
                    break;

                case "DOUBLE":
                    if (player.Chips <= player.Bet)
                    {
                        player.AddBet(player.Chips);
                    }
                    else
                    {
                        player.AddBet(player.Bet);
                    }
                    player.Hand.Add(deck.DrawCard());
                    break;

                default:
                    WriteLine("Valid Moves:");
                    WriteLine("Hit, Stay, Fold, Double");
                    WriteLine("Press any key to continue.");
                    ReadKey();
                    break;
                }

                if (player.GetHandValue() > 21)
                {
                    foreach (Card card in player.Hand)
                    {
                        if (card.Value == 11) // Only a soft ace can have a value of 11
                        {
                            card.Value = 1;
                            break;
                        }
                    }
                }
            } while (!action.ToUpper().Equals("STAY") && !action.ToUpper().Equals("DOUBLE") &&
                     !action.ToUpper().Equals("FOLD") && player.GetHandValue() <= 21);
        }
Beispiel #39
0
 public BlackJackEngine()
 {
     _player = new Player();
     _dealer = new Dealer();
     _deck   = new Deck();
 }
Beispiel #40
0
        public void dealer_logic_true4()
        {
            //arrange
            Dealer d = new Dealer();
            d.add_card(2);
            d.add_card(3);
            d.add_card(5);
            d.add_card(4);

            bool expected = true;

            //act
            bool actual = d.logic();

            // assert
            Assert.AreEqual(expected, actual, "Wrong!");
        }
Beispiel #41
0
        /// <summary>
        /// Handles everything for the round.
        /// </summary>
        static void StartRound()
        {
            Console.Clear();

            if (!TakeBet())
            {
                EndRound(RoundResult.INVALID_BET);
                return;
            }
            Console.Clear();

            InitializeHands();
            TakeActions();

            Dealer.RevealCard();

            Console.Clear();
            player.WriteHand();
            Dealer.WriteHand();

            player.HandsCompleted++;

            if (player.Hand.Count == 0)
            {
                EndRound(RoundResult.SURRENDER);
                return;
            }
            else if (player.GetHandValue() > 21)
            {
                EndRound(RoundResult.PLAYER_BUST);
                return;
            }

            while (Dealer.GetHandValue() <= 16)
            {
                Thread.Sleep(1000);
                Dealer.RevealedCards.Add(deck.DrawCard());

                Console.Clear();
                player.WriteHand();
                Dealer.WriteHand();
            }


            if (player.GetHandValue() > Dealer.GetHandValue())
            {
                player.Wins++;
                if (Casino.IsHandBlackjack(player.Hand))
                {
                    EndRound(RoundResult.PLAYER_BLACKJACK);
                }
                else
                {
                    EndRound(RoundResult.PLAYER_WIN);
                }
            }
            else if (Dealer.GetHandValue() > 21)
            {
                player.Wins++;
                EndRound(RoundResult.PLAYER_WIN);
            }
            else if (Dealer.GetHandValue() > player.GetHandValue())
            {
                EndRound(RoundResult.DEALER_WIN);
            }
            else
            {
                EndRound(RoundResult.PUSH);
            }
        }
Beispiel #42
0
 public void AddDealer(Dealer dealer)
 {
     _dealersList.Add(dealer);
 }