public static void initialDeal(int numberCardsPerPlayer, int numberPlayers, CardHand[] player, DeckOfCards shuffled_Deck) {//Deals two cards to each player in increasing order. Also, records player's names during the process. string name; for (int j = 0; j < numberCardsPerPlayer; j++) { for (int i = 0; i <= numberPlayers; i++) { if (j == 0) { if (i != numberPlayers) { Console.WriteLine("Enter Player {0}'s name:", i + 1); name = Console.ReadLine(); } else { name = "Dealer"; } player[i] = new CardHand(name); } player[i].TakeCard(shuffled_Deck.DealCard()); } } }
public static void dealerDecisions(CardHand[] player, DeckOfCards shuffled_Deck) {// Automate dealer's decisions to hit or stay. while (player[player.GetUpperBound(0)].score < 16) { player[player.GetUpperBound(0)].TakeCard(shuffled_Deck.DealCard()); } }
public static void playerDecisions(CardHand[] player, DeckOfCards shuffled_Deck) { for (int i = 0; i < player.GetUpperBound(0); i++) //The decision rests on i; no decisions for dealer. { //Print opponent's hands. Console.Clear(); for (int j = 0; j <= player.GetUpperBound(0); j++) { if (j != i) { writePlayerHand(j, false, player); } } //Go back and print i Console.WriteLine(); writePlayerHand(i, true, player); //Hit or Stay? Console.WriteLine(); string hitChoice; do { Console.WriteLine("Your current score: {0}.", player[i].score); Console.Write($"{player[i].playerName}, (H)it or (S)tay: "); hitChoice = Console.ReadLine().ToUpper(); if (hitChoice == "H") { player[i].TakeCard(shuffled_Deck.DealCard()); writePlayerHand(i, true, player); WinnerStatus(player[i].score, player[player.GetUpperBound(0)].score, false); if (player[i].score >= 21) { break; } //Exit if Blackjack or Bust } } while (hitChoice.ToUpper() == "H"); continue; } }