// Method for handling gameplay. static void Play() { // Dealer and player get 2 cards at the beginning of the game. dealerCard.Add(Card.GenerateCard()); dealerCard.Add(Card.GenerateCard()); playerCard.Add(Card.GenerateCard()); playerCard.Add(Card.GenerateCard()); Console.WriteLine($"Dealer got {dealerCard[0]} and {dealerCard[1]} "); Console.WriteLine($"You got {playerCard[0]} and {playerCard[1]}"); while (!gameOver) { Console.WriteLine($"\nDealer value: {Dealer.value = EvaluateValue("dealer")}"); Console.WriteLine($"Player value: {Player.value = EvaluateValue("player")}\n"); if (Player.value == 21) { Console.WriteLine("\nPlayer BlackJack!!"); gameOver = true; } else if (Dealer.value == 21) { Console.WriteLine("\nDealer BlackJack!!"); gameOver = true; } else if (Player.value > 21) { Console.WriteLine("\nPlayer busted!"); gameOver = true; } else if (Dealer.value > 21) { Console.WriteLine("\nDealer Busted!"); gameOver = true; } if (playerTurn && !gameOver) { player.PlayerTurn(); } if (!playerTurn && !gameOver) { dealer.DealerTurn(); } } }
// override the base's class method. // Generate a new random card and add it to the list. public override void Hit() { GamePlay.dealerCard.Add(Card.GenerateCard()); Card.ShowCard("dealer"); }