IEnumerator DealersTurn() { // Dealer AI if (dealer.ChanceHandValue() < 5) { winnerText.text = "Dealer has decided to swap!"; yield return(new WaitForSeconds(1f)); SwapCard(); yield return(new WaitForSeconds(1f)); } else { winnerText.text = "Dealer has decided not to swap."; yield return(new WaitForSeconds(1f)); } // Show the both hands CoverHand(); // Update hand scores. if (player.ChanceHandValue() == 30) { playerHandScore.text = "CHANCE"; } else { playerHandScore.text = player.ChanceHandValue().ToString(); } if (dealer.ChanceHandValue() == 30) { dealerHandScore.text = "CHANCE"; } else { dealerHandScore.text = dealer.ChanceHandValue().ToString(); } // Compare hand values, update round score/text. if (dealer.ChanceHandValue() > player.ChanceHandValue()) { winnerText.text = "You lose the round."; roundWonByDealer++; dealerScore.text = roundWonByDealer.ToString(); } else if (player.ChanceHandValue() > dealer.ChanceHandValue()) { winnerText.text = "You win the round."; roundWonByPlayer++; playerScore.text = roundWonByPlayer.ToString(); } else { winnerText.text = "Round Draw"; } // Reactivate Next Round button. nextRoundButton.interactable = true; }
// Swap random card between opponent and player hand public void SwapCard() { // Grey out Swap Card button swapCardButton.interactable = false; // Pick random cards from both hands to be swapped. int randomPlayer = Random.Range(0, 3); int randomDealer = Random.Range(0, 3); // Swap cards. int tempCard = player.Draw(randomPlayer); player.InsertCard(randomPlayer, dealer.Draw(randomDealer)); dealer.InsertCard(randomDealer, tempCard); // Update hand score. if (player.ChanceHandValue() == 30) { playerHandScore.text = "CHANCE"; } else { playerHandScore.text = player.ChanceHandValue().ToString(); } dealerHandScore.text = ""; FindObjectOfType <AudioManager>().Play("cardSlide6"); }