private void ProcessTurn_d(Player player, List <Card> hand) { computer.AppendText(player.hand[0].Number.ToString() + " , " + player.hand[1].Number.ToString() + Environment.NewLine); dtotal.AppendText("( " + player.Total().ToString() + " )"); if (player.Total() == 21 && player.hand.Count == 2) { return; } else { List <string> newHand = new List <string>(); foreach (Card card in player.hand) { newHand.Add(card.Number.ToString()); } while (player.Total() < 19) { Thread.Sleep(1000); Card randomCard = deck.RandomCard(); player.hand.Add(randomCard); newHand.Add(randomCard.Number.ToString()); computer.AppendText(string.Join(" , ", newHand) + Environment.NewLine); dtotal.Clear(); dtotal.AppendText("( " + player.Total().ToString() + " )"); } if (player.Total() > 21) { return; } } }
public static void Hit(Players players, Deck deck, List <string> newHand) { Card randomCard = deck.RandomCard(); players.hand.Add(randomCard); newHand.Add(randomCard.Face.ToString()); }
public static void PlayerAction(Players player, List <Card> hand) { if (!player.Dealer) { Console.WriteLine("How much do you wanna bet? "); int bet = int.Parse(Console.ReadLine()); List <string> newHand = new List <string>(); Console.WriteLine("(H)it or (S)tand?"); ConsoleKeyInfo choice = Console.ReadKey(true); if (choice.Key == ConsoleKey.S) { return; } else if (choice.Key == ConsoleKey.H) { Card randomCard = deck.RandomCard(); player.hand.Add(deck.RandomCard()); foreach (var card in player.hand) { newHand.Add(card.Face.ToString()); } } else { Console.WriteLine("Wrong key, try again..."); PlayerAction(player, player.hand); } Console.WriteLine("You got:" + string.Join(", ", newHand) + "(" + player.Total() + ")"); if (player.Total() > 21) { return; } else { PlayerAction(player, hand); } } else { Console.WriteLine("Dealer has:" + player.hand[0].Face.ToString() + ", " + player.hand[1].Face.ToString() + "(" + player.Total() + ")"); if (player.Total() == 21 && player.hand.Count == 2) { return; } else { List <string> newHand = new List <string>(); foreach (Card card in player.hand) { newHand.Add(card.Face.ToString()); } while (player.Total() < 17) { Hit(player, deck, newHand); Console.WriteLine("Dealer got:" + string.Join(", ", newHand) + "(" + player.Total() + ")\n"); } if (player.Total() > 21) { return; } } } }