private void decisionToContinuePlayingBlackjackOnePlayer() { InputOutput IO = new InputOutput(); while (true) { String playAgain = IO.obtainInputFromTheUser("Do you want to continue playing? Enter Y or N");; if (playAgain == "Y" || playAgain == "y") { player1Blackjack(); dealerBlackjack(); checkForTheWinnerOnePlayer(); decisionToContinuePlayingBlackjackOnePlayer(); } else if (playAgain == "N" || playAgain == "n") { Console.WriteLine("Thank you for playing Blackjack"); System.Environment.Exit(1); } else { IO.dislpayOutputToTheUser("Invalid entry, Try again"); continue; } } }
private String retrieveThePlayersNames(InputOutput IO) { String numberOfPlayers = IO.obtainInputFromTheUser("How many player do you have? Enter 1 or 2"); if (numberOfPlayers == "1") { player1Name = IO.obtainInputFromTheUser("Enter the name for Player 1: "); } else { player1Name = IO.obtainInputFromTheUser("Enter the name for player 1: "); player2Name = IO.obtainInputFromTheUser("Enter the name for player 2: "); } return(numberOfPlayers); }
private void player1Blackjack() { InputOutput IO = new InputOutput(); while (true) { int cardOne = retrieveOneCard(); player1UnicodeSuit = (char)decodeTheSuitOfTheCard(cardOne); player1FaceValue = Convert.ToString(decodeTheFaceOfTheCard(cardOne)); player1Card1Value = decodeTheValueOfTheCard(cardOne); IO.dislpayOutputToTheUser("First card for " + player1Name + " is a: " + player1FaceValue + " of " + player1UnicodeSuit + "'s\n"); Thread.Sleep(milliseconds); int cardTwo = retrieveOneCard(); player1UnicodeSuit = (char)decodeTheSuitOfTheCard(cardTwo); player1FaceValue = decodeTheFaceOfTheCard(cardTwo); player1Card2Value = decodeTheValueOfTheCard(cardTwo); IO.dislpayOutputToTheUser("Second card for " + player1Name + " is a: " + player1FaceValue + " of " + player1UnicodeSuit + "'s\n"); Thread.Sleep(milliseconds); player1Hand = player1Card1Value + player1Card2Value; // add the cards to create the hand IO.dislpayOutputToTheUser(player1Name + "'s hand value is: " + player1Hand + "\n"); Thread.Sleep(milliseconds); if (player1Hand > 21) // checks for an Ace on first two cards, if the hand it greater than 21 it subtracts 10 { player1Hand -= 10; } if (player1Hand == 21) // check for blackjack, if so player wins and breaks { IO.dislpayOutputToTheUser("BlackJack you win!!!\n"); Thread.Sleep(milliseconds); break; } while (player1Hand < 21) // if hand is less than 21 ask player to hit or stay { String player1Answer = IO.obtainInputFromTheUser(player1Name + ", Do you want to hit? Y or N\n"); if (player1Answer == "Y" || player1Answer == "y") // if player hits { getAnotherCard = retrieveOneCard(); player1UnicodeSuit = (char)decodeTheSuitOfTheCard(getAnotherCard); player1FaceValue = decodeTheFaceOfTheCard(getAnotherCard); getAnotherCard = decodeTheValueOfTheCard(getAnotherCard); checkForAcePlayer1(getAnotherCard); Thread.Sleep(milliseconds); IO.dislpayOutputToTheUser(player1Name + " you were dealt " + player1FaceValue + " of " + player1UnicodeSuit + "'s\n"); Thread.Sleep(milliseconds); IO.dislpayOutputToTheUser(player1Name + "'s hand value is " + player1Hand + "\n"); Thread.Sleep(milliseconds); if (player1Hand > 21) // over 21 is a bust and game is over for the player { IO.dislpayOutputToTheUser(player1Name + " you busted\n"); Thread.Sleep(milliseconds); } else { continue; } } else if (player1Answer == "N" || player1Answer == "n") // player does not want another card { IO.dislpayOutputToTheUser("You decided to stay. " + player1Name + "'s hand value is: " + player1Hand + "\n"); Thread.Sleep(milliseconds); break; } else { IO.dislpayOutputToTheUser("Incorrect input, try again\n"); // invalid entry try again continue; } } break; } }