Beispiel #1
0
        /// <summary>
        /// Displays what the player sees
        /// </summary>
        /// <param name="cardDeck">The deck of cards the gam eis being played with</param>
        /// <param name="discard">the discard for said cards</param>
        /// <param name="random"></param>
        static (string playerName, int roundTotal, int playerBet, Player.PlayerOutcome outcome) DisplayPlayerScreen(
            List <PlayingCard> cardDeck,
            List <PlayingCard> discard,
            Random random,
            Player player,
            Dealer dealer)//,
        //List<(string playerName, int roundTotal, int playerBet, Player.PlayerOutcome outcome)> playerRoundInfo
        {
            // PlayingCard drawnCard;
            //drawnCard = DrawCard(random, cardDeck, discard);
            bool turnEnd       = false;
            bool validResponse = false;
            int  userResponse;
            int  playerBet = 0;
            int  playerCardsTotal;

            (string playerName, int roundTotal, int playerBet, Player.PlayerOutcome outcome)roundOutcome;
            roundOutcome.playerName = player.Name;
            roundOutcome.roundTotal = 0;
            roundOutcome.playerBet  = 0;
            roundOutcome.outcome    = Player.PlayerOutcome.none;

            //List<PlayingCard> playerCards = new List<PlayingCard>();

            player.Cards.Add(DrawCard(random, cardDeck, discard));
            player.Cards.Add(DrawCard(random, cardDeck, discard));

            DisplayScreenHeader($"{player.Name}'s Turn!");
            DisplayContinuePrompt("continue");

            do
            {
                bool couldParse;

                DisplayScreenHeader(player.Name);

                Console.WriteLine($"\tYou have ${player.Money}");
                Console.Write("\tHow much would you like to bet? $");

                couldParse = int.TryParse(Console.ReadLine(), out playerBet);

                if (couldParse)
                {
                    validResponse = true;
                }
                else
                {
                    DisplayErrorMessage("Please enter an integer [ex. 1, 56]");
                    DisplayContinuePrompt("try again");
                }

                if (playerBet > player.Money || playerBet == 0)
                {
                    validResponse = false;
                    DisplayErrorMessage("You can\'t bet more than you have, and you can\'t bet zero. You have to bet something.");
                }
            } while (!validResponse);

            player.Money -= playerBet;
            //player.RoundBet = playerBet;
            roundOutcome.playerBet = playerBet;

            do
            {
                Console.Clear();

                playerCardsTotal = GetCardValueTotal(player.Cards);

                if (playerCardsTotal > 21)
                {
                    foreach (PlayingCard card in player.Cards)
                    {
                        if (card.CardRank == PlayingCard.Rank.Ace)
                        {
                            card.CardValue -= 10;
                        }
                    }
                }

                DisplayScreenHeader(player.Name);

                Console.WriteLine($"\t{player.Name}'s bet: ${playerBet}");

                Console.WriteLine($"\tDealer's Cards: {dealer.Cards[0].CardRank} of {dealer.Cards[0].CardSuit}, ???");

                WriteAllCards(player.Name, player.Cards);

                Console.WriteLine($"\n\tCurrent total: {playerCardsTotal}");

                if (playerCardsTotal < 21)
                {
                    userResponse = ConsoleHelper.MultipleChoice(false, 2, 5, 0, "Hit", "Stay");
                    switch (userResponse)
                    {
                    case 0:
                        player.Cards.Add(DrawCard(random, cardDeck, discard));
                        break;

                    case 1:
                        Console.WriteLine($"\n\tYou stopped at: {playerCardsTotal}");
                        DisplayContinuePrompt("progress to the next player");
                        roundOutcome.outcome = Player.PlayerOutcome.pass;
                        turnEnd = true;
                        break;

                    default:
                        DisplayErrorMessage("Faulty Input");
                        break;
                    }
                }
                else if (playerCardsTotal > 21)
                {
                    Console.WriteLine("\nBust!");
                    DisplayContinuePrompt("continue");
                    roundOutcome.outcome = Player.PlayerOutcome.bust;
                    turnEnd = true;
                }
                else if ((playerCardsTotal == 21) && (player.Cards.Count == 2))
                {
                    Console.WriteLine("\nBlackjack!");
                    DisplayContinuePrompt("continue");
                    roundOutcome.outcome = Player.PlayerOutcome.blackjack;
                    turnEnd = true;
                }
            } while (!turnEnd);

            //player.RoundTotal += playerCardsTotal;

            roundOutcome.roundTotal = playerCardsTotal;

            // DisplayContinuePrompt("continue");

            return(roundOutcome);
        }
Beispiel #2
0
        /// <summary>
        /// The initial method for displaying the playable game
        /// </summary>
        /// <param name="random">teh Random object</param>
        /// <param name="cardDeckInfo">The text file for the cards</param>
        ///// <param name="modifiableRules">the changable rules</param>
        ///// <param name="players">the List of players from the player menu</param>
        static void DisplayGame(
            Random random,
            string cardDeckInfo /*,
                                 * (int numberDecks, int startingMoney, Dealer.BettingStyle bettingStyle, int numberRounds) modifiableRules*/,
            string gameIntro)
        {
            List <PlayingCard> cardDeck = BuildCardDeck(cardDeckInfo);
            // ------------------------------------------------------------------
            // Making a temporary card decks in order to add multiple decks
            // List<PlayingCard> cardDeckTemp = new List<PlayingCard>();
            List <PlayingCard> discard = new List <PlayingCard>();
            //List<PlayingCard> dealerCards = new List<PlayingCard>();
            List <Player> players = new List <Player>();

            List <(string playerName, int roundTotal, int playerBet, Player.PlayerOutcome outcome)> playerRoundInfo = new List <(string playerName, int roundTotal, int playerBet, Player.PlayerOutcome outcome)>();

            (string name, int dealerTotal, Player.PlayerOutcome outcome)dealerOutcome;

            Dealer dealer = new Dealer();

            //int numberDecks = 1;
            int startingMoney = 500;
            int numberRounds  = 5;
            //Dealer.BettingStyle bettingStyle = Dealer.BettingStyle.everyManForHimself;

            Player player1 = new Player("Player 1", startingMoney /*, 0, 0*/);
            Player player2 = new Player("Player 2", startingMoney /*, 0, 0*/);

            players.Add(player1);
            players.Add(player2);

            //PlayingCard drawnCard;

            //bool gameOver = false;

            //// -------------------------------
            //// Build card deck according to the numberDecks
            //if (modifiableRules.numberDecks > 1)
            //{
            //    for (int deck = 0; deck < modifiableRules.numberDecks - 1; deck++)
            //    {
            //        cardDeckTemp = BuildCardDeck(cardDeckInfo);
            //        cardDeck.AddRange(cardDeckTemp);
            //    }
            //}

            DisplayScreenHeader("Blackjack");

            // -------------------------------------------------------------------------
            // asking the user if they would like to see their modifiable rules, to be sure.
            //AskAboutDisplayModifiedRules(modifiableRules);

            DisplayGameIntro(gameIntro);

            for (int round = 0; round < numberRounds; round++)
            {
                dealer.Cards.Add(DrawCard(random, cardDeck, discard));
                dealer.Cards.Add(DrawCard(random, cardDeck, discard));

                DisplayScreenHeader($"Round {round + 1}");
                DisplayContinuePrompt("start");

                foreach (Player player in players)
                {
                    (string playerName, int roundTotal, int playerBet, Player.PlayerOutcome outcome)playerOutcome;
                    playerOutcome = DisplayPlayerScreen(cardDeck, discard, random, player, dealer);
                    playerRoundInfo.Add(playerOutcome);
                }

                dealerOutcome = DisplayDealerScreen(players, dealer, cardDeck, discard, random, playerRoundInfo);

                DisplayRoundOutcome(playerRoundInfo, dealerOutcome, players, numberRounds);
                //DisplayContinuePrompt("this is only here so i can set a breakpoint");

                playerRoundInfo.Clear();

                ClearAllHands(players, dealer);
            }

            //DisplayPlayerScreen(cardDeck, discard, random, player1, dealerCards);

            DisplayContinuePrompt("exit");
        }