static void Main(string[] args) { Console.Title = "BlackJack Game"; Player player = new Player(); Dealer dealer = new Dealer(); Deck deck = new Deck(); Console.WriteLine("A new deck has been opened...Let's Play BlackJack!"); deck.Shuffle(); Console.WriteLine("\nDeck Shuffled"); player.AddACard(deck.DealCard()); player.AddACard(deck.DealCard()); Console.WriteLine("\nPlayer Hand is " + player.GetValue()); player.PrintHand(); var dcard2 = deck.DealCard(); dealer.AddACard(deck.DealCard()); dealer.AddACard(dcard2); Console.WriteLine("\nDealer is showing: " + dcard2.Value + "\n" + dcard2.FaceValue + " of " + dcard2.Suit + "\n"); Dealer.EvaluateScores(player.GetValue(), dealer.GetValue()); if (dealer.GetValue() != 21 && player.GetValue() != 21) { Player.PHitOrStay(player, dealer, deck); Dealer.DHitOrStay(player, dealer, deck); } Console.ReadLine(); }
public static void DHitOrStay(Player p, Dealer d, Deck k) { Dealer.EvaluateScores(p.GetValue(), d.GetValue()); while (d.GetValue() < 17) { d.AddACard(k.DealCard()); } }
public Card draw(Deck deck) { Card myCard = deck.DealCard(); this.Hand.Add(myCard); Console.WriteLine($"{this.Name} draw a Card..."); this.CalculateScore(); this.checkIfBust(); this.showCards(); return(myCard); }
public static void PHitOrStay(Player p, Dealer d, Deck k) { if (p.GetValue() < 21 && d.GetValue() != 21) { Console.Write("\nHit or Stay? "); string phitorStay = ""; phitorStay = (Console.ReadLine()); if (phitorStay.Equals("Stay", StringComparison.CurrentCultureIgnoreCase)) { Console.WriteLine("\nPlayer stays, the game has ended."); Console.WriteLine("\nPlayer's hand was: " + p.GetValue()); Dealer.DHitOrStay(p, d, k); Console.WriteLine("Dealer's hand was: " + d.GetValue()); if (d.GetValue() > 21) { Console.WriteLine("Dealer Busts...\nPlayer Wins"); } else if (p.GetValue() > d.GetValue()) { Console.WriteLine("Player Wins"); } else if (p.GetValue() < d.GetValue()) { Console.WriteLine("Dealer Wins"); } else { Console.WriteLine("The game is a push"); } } else if (phitorStay.Equals("Hit", StringComparison.CurrentCultureIgnoreCase)) { p.AddACard(k.DealCard()); p.CheckForAce(); Console.WriteLine("\nPlayer hit, the hand is now: " + p.GetValue()); p.PrintHand(); //Console.WriteLine("\nThe card total is now: " + p.GetValue()); if (p.GetValue() < 21) { Player.PHitOrStay(p, d, k); { Dealer.EvaluateScores(p.GetValue(), d.GetValue()); } } else { Console.WriteLine("\nPlayer Busted!!!"); } } } }
//Player Action Buttons*********************************************************************************************** public void ButtonDeal_Click(object sender, RoutedEventArgs e) { deck.Shuffle(); //reset count of cards for next game playerCount = 0; dealerCount = 0; //reset winner playerWin = false; dealerWin = false; gamedraw = false; //Clear Table PlayerCards.Children.Clear(); DealerCards.Children.Clear(); TextBlock_Draw.Visibility = Visibility.Collapsed; TextBlock_PlayerLoses.Visibility = Visibility.Collapsed; TextBlock_PlayerWins.Visibility = Visibility.Collapsed; //Deal Cards //deal face down card for dealer dealHiddenCard = deck.DealCard(); dealerCount = dealerCount + dealHiddenCard.rank; Image hiddenCardImage = new Image(); BitmapImage bci = new BitmapImage(); bci.BeginInit(); bci.UriSource = new Uri(@"C:\Users\banihi2\source\repos\BlackJack\BlackJack\Images\" + "blue_back.png", UriKind.Relative); bci.EndInit(); hiddenCardImage.Source = bci; ResizeImage(hiddenCardImage, 80, 160); DealerCards.Children.Add(hiddenCardImage); DealPlayer(); DealDealer(); DealPlayer(); }
public void PlayGame() { ConsoleInput.GetPlayerName(); Deck deck1 = new Deck(); deck1.Shuffle(); for (int i = 0; i < 52; i++) { Console.WriteLine("{0, -19}", deck1.DealCard()); if ((i + 1) % 4 == 0) { Console.WriteLine(); } } Console.ReadLine(); }
static void Main(string[] args) { //init Deck deck = new Deck(); Dealer dealer = new Dealer(); Console.WriteLine("\t\t\tWelcome To BlackJack Game!!!\n\n"); Console.Write("How much money do you want to place? $"); double money = Convert.ToDouble(Console.ReadLine()); Console.WriteLine(); Player player = new Player(money); string wantContinue; do { Console.Clear(); deck.Shuffle(); player.ClearHandCards(); dealer.ClearHandCards(); Console.WriteLine("Your current blance: ${0}", player.Blance); // if a bet is not between 2-500 or the bet is more than balance, reprompt to the player again. do { if (player.Blance < 2) { Console.WriteLine("You don't have enough money! Minimum bet is $2\n"); Console.WriteLine("Thanks for playing! Goodbye!\n"); return; } Console.Write("How much would you like to bet? ($2 - $500) $"); player.Bet = Convert.ToDouble(Console.ReadLine()); if (player.Bet < 2 || player.Bet > 500) { Console.WriteLine("The general limits are from $2 to $500.\n"); } else if ((player.Bet > player.Blance) && (2 < player.Bet && player.Bet <= 500)) { Console.WriteLine("You don't have enough $$ to bet. Please lower down your bet :)\n"); } } while(player.Bet < 2 || player.Bet > 500 || (player.Bet > player.Blance) && (2 < player.Bet && player.Bet <= 500)); Console.WriteLine("Bet: ${0}\n", player.Bet); // player and dealer draw 2 cards from deck for (int i = 0; i < 2; i++) { player.DrawCard(deck.DealCard()); dealer.DrawCard(deck.DealCard()); } player.ShowCards(); // show one card to player dealer.ShowOneCard(); string hitOrStand; do { Console.WriteLine("\nHit(h) or Stand(s)"); hitOrStand = Console.ReadLine(); Console.WriteLine(); // if player type hit, player will draw a card from the deck. if (hitOrStand.ToLower() == "h") { player.DrawCard(deck.DealCard()); if (player.Score > 21) { PrintWhoWin("L", player, dealer); break; } else { player.ShowCards(); dealer.ShowOneCard(); } } // if player type stand, dealer will draw cards until the point is 17 or more. else if (hitOrStand.ToLower() == "s") { while (dealer.Score < 17) { dealer.DrawCard(deck.DealCard()); } if (dealer.Score > 21) { PrintWhoWin("W", player, dealer); } else { // Compare with player to see who's winner if (dealer.Score > player.Score) { PrintWhoWin("L", player, dealer); } else { if (dealer.Score == player.Score) { PrintWhoWin("T", player, dealer); } else { PrintWhoWin("W", player, dealer); } } } break; } else { Console.WriteLine("Invailed input!"); } } while (hitOrStand.ToLower() != "s"); Console.WriteLine("Wanna Continue? (y/n)"); wantContinue = Console.ReadLine(); if (wantContinue.ToLower() != "n" && wantContinue.ToLower() != "y") { Console.WriteLine("Invailed input!"); return; } } while (wantContinue.ToLower() != "n"); Console.WriteLine("Thanks for playing! Goodbye!\n"); }
public void Start() { MainDeck = new Deck(); Dealer = new Hand(2, "Dealer"); Player = new Hand(2, "Player"); Console.Clear(); for (int i = 0; i < 2; i++) { MainDeck.DealCard(Dealer); MainDeck.DealCard(Player); } Console.WriteLine("-- Initial hands --"); //1st card is secret Console.WriteLine("Dealer initial card: " + Dealer.Data[0]); Console.WriteLine("Player cards: " + Player.Data[0] + ", " + Player.Data[1]); Console.WriteLine("-- Start player turn --"); while (Player.TotalPoints < 21) { Console.WriteLine("You have " + Player.TotalPoints + " points, hit? (y/n)"); if (Console.ReadKey(true).Key == ConsoleKey.Y) { MainDeck.DealCard(Player); PrintCards(Player); } else break; if (Player.TotalPoints == 21) { Console.WriteLine("You have 21 points, you win!"); break; } if (Player.TotalPoints > 21) { Console.WriteLine("You have " + Player.TotalPoints + " points, you lose!"); break; } } if (Player.TotalPoints < 21) { Console.WriteLine("-- Start dealer turn --"); if (Dealer.TotalPoints > 21) { Console.WriteLine("You win, dealer has more than 21 points."); } PrintCards(Dealer); if (Dealer.TotalPoints > Player.TotalPoints && Dealer.TotalPoints < 21) Console.WriteLine("Dealer wins, more points than you."); if (Dealer.TotalPoints == 21) Console.WriteLine("Dealer wins with 21 points."); while (Dealer.TotalPoints <= Player.TotalPoints) { MainDeck.DealCard(Dealer); PrintCards(Dealer); if (Dealer.TotalPoints == 21) { Console.WriteLine("Dealer wins with 21 points."); break; } if (Dealer.TotalPoints > 21) { Console.WriteLine("You win, dealer has over 21 points."); break; } if (Dealer.TotalPoints > Player.TotalPoints) { Console.WriteLine("Dealer wins, higher points than you."); break; } } } Console.WriteLine("-- Play again? (y/n) --"); if (Console.ReadKey(true).Key == ConsoleKey.Y) Start(); }
static void Main(string[] args) { var keepPlaying = true; while (keepPlaying) { Deck _deck = new Deck(); Player _player = new Player(); Dealer _dealer = new Dealer(); Hand playerHand = new Hand(); Hand dealerHand = new Hand(); playerHand.AddCard(_deck.DealCard()); dealerHand.AddCard(_deck.DealCard()); playerHand.AddCard(_deck.DealCard()); dealerHand.AddCard(_deck.DealCard()); _player.AddHand(playerHand); _dealer.AddHand(dealerHand); while (playerHand.TotalValue() <= 21) { Console.WriteLine(); Console.WriteLine("---------------------"); Console.WriteLine($"Hand Value: {playerHand.TotalValue()}"); playerHand.ShowHand(); Console.WriteLine("---------------------"); Console.WriteLine(); Console.Write("(H)it or (S)tand: "); var answer = Console.ReadLine(); if (answer == "H") { playerHand.AddCard(_deck.DealCard()); } else { break; } } Console.WriteLine(); Console.WriteLine("---------------------"); Console.WriteLine($"Hand Value: {playerHand.TotalValue()}"); playerHand.ShowHand(); Console.WriteLine("---------------------"); Console.WriteLine(); while (dealerHand.TotalValue() < 17) { dealerHand.AddCard(_deck.DealCard()); } Console.WriteLine(); Console.WriteLine("---------------------"); Console.WriteLine($"Dealer's Hand Value: {dealerHand.TotalValue()}"); dealerHand.ShowHand(); Console.WriteLine("---------------------"); 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!"); } Console.Write("Play again? (Y/N): "); var playAgainString = Console.ReadLine(); keepPlaying = (playAgainString == "Y" || playAgainString == "y"); } Console.WriteLine(); Console.WriteLine("Thanks for playing"); }