static void Main(string[] args) { Syringe syrige = new Syringe(); Arm arm = new Arm("张三"); Hand hand = new Hand("李四"); Ass ass = new Ass("王五"); arm.Accept(syrige); hand.Accept(syrige); ass.Accept(syrige); Console.ReadLine(); }
public void Accept(Visitor visitor) { _hand.Accept(visitor); }
public void Play() { var deck = new Deck(); deck.MakeCards(); var playerHand = new Hand(); var dealerHand = new Hand(); var firstCard = deck.Deal(); playerHand.Accept(firstCard); var secondCard = deck.Deal(); playerHand.Accept(secondCard); var firstCardForDealer = deck.Deal(); dealerHand.Accept(firstCardForDealer); var secondCardForDealer = deck.Deal(); dealerHand.Accept(secondCardForDealer); while (playerHand.TotalValue() <= 21) { Console.WriteLine(); playerHand.ShowCards(); Console.WriteLine($"For a total value of {playerHand.TotalValue()}"); Console.WriteLine(); Console.Write("(H)it or (S)tand: "); var answer = Console.ReadLine(); if (answer == "H") { var extraCard = deck.Deal(); playerHand.Accept(extraCard); } else { // Break us out of the most inner loop, in this case the `while < 21` // 13. If STAND continue on break; } } Console.WriteLine(); playerHand.ShowCards(); Console.WriteLine($"For a total value of {playerHand.TotalValue()}"); Console.WriteLine(); while (dealerHand.TotalValue() < 17) { // 15. If the dealer has busted then goto step 17 // 16. If the dealer has less than 17 // - Ask the deck for a card and place it in the dealer hand var extraCard = deck.Deal(); dealerHand.Accept(extraCard); } Console.WriteLine(); Console.WriteLine("Dealer has:"); dealerHand.ShowCards(); var computedTotalValueOfDealerHand = dealerHand.TotalValue(); Console.WriteLine($"For a total value of {computedTotalValueOfDealerHand}"); Console.WriteLine(); if (playerHand.TotalValue() > 21) { Console.WriteLine("Dealer Wins!"); } else if (dealerHand.TotalValue() > 21) { Console.WriteLine("Player Wins!"); } else if (dealerHand.TotalValue() >= playerHand.TotalValue()) { Console.WriteLine("Dealer Wins!"); } else { Console.WriteLine("Player Wins!"); } }