private void btnDeal_Click(object sender, EventArgs e) { //add a card to the players hand and redraw mPlayer.AddCard(mDeck.Deal()); Invalidate(); //redraw //if player is bust, calculate money won or lost if (mPlayer.getScore() > 21) { EndRound(); } }
// StartDeal begins the first draws of game. // static void StartDeal(){ // Player Javier = new Player("Javier"); // Dealer D = new Dealer(); // Deck NewDeck = new Deck(); // NewDeck.Deal(); // Javier.Hit(NewDeck); // D.Hit(NewDeck); // Javier.Hit(NewDeck); // D.Hit(NewDeck); // D.Showupcard(); // if(Javier.handvalue == 21){ // Javier.money += Javier.bet * 2; // Console.WriteLine("BLACKJACK! WINNER WINNER CHICKEN DINNER!"); // } // } static void Main(string[] args) { Player Javier = new Player("Javier"); Dealer D = new Dealer(); int TotalDecks = 2; Deck NewDeck = new Deck(TotalDecks); NewDeck.Deal(); // Javier.Hit(NewDeck); // D.Hit(NewDeck); // Javier.Hit(NewDeck); // D.Hit(NewDeck); // D.Showupcard(); // if(Javier.handvalue == 21){ // Javier.money += Javier.bet * 2; // Console.WriteLine("BLACKJACK! WINNER WINNER CHICKEN DINNER!"); // } // Javier.Hit(NewDeck); // Javier.Hit(NewDeck); // Javier.Hit(NewDeck); // Javier.Hit(NewDeck); // Javier.Hit(NewDeck); // Class Constructor will not tansfer over. Need to user database. // Console.WriteLine(p1.hand); // p1.Draw(NewDeck); // p1.Discard(); // foreach (var card in p1.hand){ // Console.WriteLine("p1 hand: " + card.stringVal + card.suit); // } int newcount = 0; foreach (var card in NewDeck.cards) { newcount++; Console.WriteLine(card.stringVal + card.suit); } // Console.WriteLine(newcount); }
static void Main(string[] args) { // Intro Console.WriteLine("BLACKJACK"); Console.WriteLine(); int playerWins = 0; int dealerWins = 0; // Game Loop (Round) do { // Reshuffle deck every round Deck d = new Deck(); d.Shuffle(); BJHand player = new BJHand(d, 2); BJHand dealer = new BJHand(d, 2); // Turn "Loop" // Player (then dealer), player continues until Bust or Stand bool stand = false; bool bust = false; while (!stand && !bust) { Console.WriteLine("Player"); Console.WriteLine(player.ToString()); stand = !willHit(); Console.WriteLine(); if (!stand) { player.AddCard(d.Deal()); } bust = player.Score > 21; } // Dealer bool bustD = false; bool standD = false; if (!bust) { while (!standD && !bustD) { //Console.WriteLine("Dealer"); //Console.WriteLine(dealer.ToString()); if (dealer.Score <= 16) { dealer.AddCard(d.Deal()); } else { standD = true; } bustD = dealer.Score > 21; } } // Player Score and Hand Console.WriteLine("Player Score: " + player.Score.ToString() + (bust ? " (Bust)" : "")); Console.WriteLine(player.ToString()); // Dealer Score and Hand Console.WriteLine("Dealer Score: " + dealer.Score.ToString() + (bustD ? " (Bust)" : "")); Console.WriteLine(dealer.ToString()); // Announce winner if (bust || (!bustD && dealer.Score > player.Score)) { Console.WriteLine("The Dealer has won!"); dealerWins++; } else if (bustD || player.Score > dealer.Score) { Console.WriteLine("The Player has won!"); playerWins++; } else { Console.WriteLine("It's a draw!"); } // Show running round score Console.WriteLine("Player/Dealer Wins: " + playerWins.ToString() + "/" + dealerWins.ToString()); // Another game? } while (playAgain()); // Exit Console.Write("Press any key to exit > "); Console.ReadKey(); }
public void DrawFrom(Deck currentDeck) { hand.Add(currentDeck.Deal()); }
static void PlayOneTurn() { deck.Deal(playerOne, dealer); do { int choice = 0; if (!playerOne.Stay) { Console.WriteLine("Dealer has: {0}", dealer.ShowHiddenHand()); Console.WriteLine("{0} you have: {1}", playerOne.Name, playerOne.ShowHand()); Console.WriteLine("1-Hit / 2-Stay"); do { if (!int.TryParse(Console.ReadLine(), out choice)) { Console.WriteLine("Choose 1 or 2"); } else if (choice != 1 && choice != 2) { Console.WriteLine("Choose 1 or 2"); } if (choice == 2) { playerOne.Stay = true; } } while (choice != 1 && choice != 2); // choose if you hit or stay } if (!playerOne.Stay) { playerOne.Hit(deck); } if (playerOne.GetHandWeigth() > BlackJackPlayer.BlackJack) { playerOne.Stay = true; } if (dealer.GetHandWeigth() < BlackJackPlayer.DealerMaxHit) { dealer.Hit(deck); } else { dealer.Stay = true; } } while (!dealer.Stay || !playerOne.Stay); Console.WriteLine("Dealer has: {0} / score: {1}", dealer.ShowHand(), dealer.GetHandWeigth()); Console.WriteLine("{0} you have: {1} / score: {2}", playerOne.Name, playerOne.ShowHand(), playerOne.GetHandWeigth()); if (playerOne.GetHandWeigth() > BlackJackPlayer.BlackJack) { if (playerOne.GetHandWeigth() < dealer.GetHandWeigth()) //win { EndTurn(Win); } else if (playerOne.GetHandWeigth() == dealer.GetHandWeigth()) //draw { EndTurn(Draw); } else if (playerOne.GetHandWeigth() > dealer.GetHandWeigth()) //lost { EndTurn(Lost); } } //if hand above 21 else if (dealer.GetHandWeigth() > BlackJackPlayer.BlackJack) //win { EndTurn(Win); } else { if (playerOne.GetHandWeigth() > dealer.GetHandWeigth()) //win { EndTurn(Win); } else if (playerOne.GetHandWeigth() == dealer.GetHandWeigth()) //draw { EndTurn(Draw); } else if (playerOne.GetHandWeigth() < dealer.GetHandWeigth()) //lost { EndTurn(Lost); } } dealer.ClearHand(); playerOne.ClearHand(); playerOne.Stay = false; dealer.Stay = false; deck = new Deck(); }
// static void StartDeal(){ // Player Javier = new Player("Javier"); // Dealer D = new Dealer(); // Deck NewDeck = new Deck(); // NewDeck.Deal(); static void Main(string[] args) { Console.ResetColor(); Player player = new Player(); Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Green; Console.Write("Please enter your name: "); player.name = Console.ReadLine(); Dealer dealer = new Dealer(); Console.Write("Please enter a name for the dealer: "); dealer.name = Console.ReadLine(); Console.WriteLine("How many deck do you want to play?: "); string test = Console.ReadLine(); int test1 = Int32.Parse(test); Deck NewDeck = new Deck(test1); NewDeck.Deal(); player.Hit(NewDeck); dealer.Hit(NewDeck); player.Hit(NewDeck); dealer.Hit(NewDeck); dealer.Showupcard(); if (player.handvalue == 21) { player.money += player.bet * 2; Console.WriteLine("BLACKJACK! WINNER WINNER CHICKEN DINNER!"); return; } Console.Write("Hit or Stick? "); string choice = Console.ReadLine(); if (choice.ToUpper() == "HIT") { player.Hit(NewDeck); } if (choice.ToUpper() == "STICK") { dealer.Hit(NewDeck); if (dealer.handvalue < 17 || dealer.handvalue < 21) { dealer.Hit(NewDeck); } if (dealer.handvalue > 21) { Console.WriteLine("Play Again (Y/N): "); string play = Console.ReadLine(); if (play.ToUpper() == "Y") { player.Discard(); dealer.Discard(); NewDeck.Reset(test1); return; } } } if (player.handvalue > 21) { Console.WriteLine("You Bust!"); Console.WriteLine("Play Again (Y/N): "); string play = Console.ReadLine(); if (play.ToUpper() == "Y") { player.Discard(); dealer.Discard(); NewDeck.Reset(test1); } } else if (player.handvalue < 21) { Console.Write("Hit or Stick? "); string choice1 = Console.ReadLine(); if (choice1.ToUpper() == "HIT") { player.Hit(NewDeck); } if (player.handvalue > 21) { Console.WriteLine("You Bust!"); Console.WriteLine("Play Again (Y/N): "); string play = Console.ReadLine(); if (play.ToUpper() == "Y") { player.Discard(); dealer.Discard(); NewDeck.Reset(test1); } } } // Class Constructor will not tansfer over. Need to user database. // int newcount = 0; // foreach (var card in NewDeck.cards){ // newcount++; // Console.WriteLine(card.stringVal + card.suit); // } // Console.WriteLine(newcount); }