static void ShowResults(BJHand player, BJHand dealer) { Console.WriteLine("Player's hand: \n" + player.ToString()); Console.WriteLine("Dealer's hand: \n" + dealer.ToString()); Console.WriteLine("Player's score: " + player.Score.ToString()); Console.WriteLine("Dealer's score: " + dealer.Score.ToString()); }
public void TestingIsBusted() { Deck d = new Deck(); BJHand newHand = new BJHand(d, 15); Assert.IsTrue(newHand.IsBusted); }
private BlackjackLogic() { Player = new BJPlayer(); DealerHand = new BJHand(); round_replay = new RoundReplay(); NewGame(); }
public static void HandClassTesting() { Console.WriteLine("TESTING THE HAND CLASS."); Deck d = new Deck(); Hand h = new Hand(d, 2); Console.WriteLine("Created a hand of 2 cards, lets see them. \n"); Console.WriteLine(h.ToString()); Console.WriteLine("Let's get rid of one card from the last one drawn. \n"); h.Discard(1); Console.WriteLine("Let's see the final one. \n"); Console.WriteLine(h.GetCard(0).ToString()); Console.WriteLine("Let's add two. \n"); h.AddCard(new Card(2, 2)); h.AddCard(new Card(4, 2)); Console.WriteLine("Let's see them again. \n"); Console.WriteLine(h.ToString()); Console.WriteLine("Let's get the second card by index and then get the index of the card. \n"); Card c1 = h.GetCard(1); Console.WriteLine("Index of second card, should be 1 and is: " + h.IndexOf(c1)); Console.WriteLine("Now let's get the index of it by it's value and suit. \n"); Console.WriteLine("Index should be 1 and is: " + h.IndexOf(c1.Value, c1.Suit)); Console.WriteLine("Does the hand contain the card we've been checking? " + (h.HasCard(c1) ? "Yes" : "No")); Console.WriteLine("Can we find it by it's value and suit? " + (h.HasCard(c1.Value, c1.Suit) ? "Yes" : "No")); Console.WriteLine("TESTING COMPLETE."); /* * ^^^^^ * HAND CLASS TESTING * * BLACKJACK HAND CLASS TESTING * v v v v v */ Console.WriteLine("TESTING BLACKJACK HAND."); Deck d2 = new Deck(); d2.Shuffle(); BJHand bjHand = new BJHand(d2, 3); for (int i = 0; i < 8; i++) { Console.WriteLine("///////"); Console.WriteLine("Showing results of the hand: " + bjHand.ToString()); Console.WriteLine("Showing score of the hand: " + bjHand.Score + ", is it a bust? " + bjHand.IsBusted); Console.WriteLine("Emptying hand and filling it."); Console.WriteLine("///////"); // Emptying hand. bjHand.Discard(0); bjHand.Discard(0); bjHand.Discard(0); bjHand.AddCard(d2.Draw()); bjHand.AddCard(d2.Draw()); bjHand.AddCard(d2.Draw()); } Console.WriteLine("TESTING COMPLETE."); }
public void SetUpAllTests() { d = new Deck(); d.NewDeck(); hand1 = new Hand(); hand2 = new Hand(d, 5); hand3 = new BJHand(); hand4 = new BJHand(d, 5); }
static void BJHandTestIsBusted() { BJHand h1 = new BJHand(); h1.AddCard(new Card(11, 12)); h1.AddCard(new Card(11, 12)); h1.AddCard(new Card(11, 12)); Console.WriteLine("Testing Is Busted"); Console.WriteLine("Two aces in hand. Expecting true. " + h1.IsBusted()); }
public void HandSetups() { def = new Hand(); defD = new Deck(); sixC = new BJHand(defD, 6); aC = new Card(1, 1); qH = new Card(12, 3); d2 = new Card(2, 2); randC = new Card(3, 3); BJDef = new BJHand(); BJDefD = new BJHand(defD, 5); }
static void BJHandTestHasAce() { BJHand h1 = new BJHand(); Console.WriteLine("Testing Has Ace"); h1.AddCard(new Card(3, 4)); h1.AddCard(new Card(11, 12)); Console.WriteLine("No aces in hand. Expecting false. " + h1.HasAce()); h1.AddCard(new Card(1, 1)); Console.WriteLine("One ace in the hand. Expecting true. " + h1.HasAce()); }
private static void TestBJHandConstructor() { Console.WriteLine("Test BJHand constructor"); Console.WriteLine(); Console.WriteLine("Creating a BJHand with 2 cards..."); Deck d = new Deck(); BJHand bjHand = new BJHand(d, 2); Console.WriteLine("Expect: BJHand has 2 cards"); Console.WriteLine("Result: BJHand has " + bjHand.NumCards.ToString() + " cards"); Console.WriteLine(); }
static void BJHandTestScore() { BJHand h1 = new BJHand(); h1.AddCard(new Card(11, 12)); h1.AddCard(new Card(11, 12)); Console.WriteLine("Testing Score"); Console.WriteLine("Two Jacks in Hand. Expecting 20. " + h1.Score); h1.AddCard(new Card(1, 2)); h1.AddCard(new Card(1, 2)); Console.WriteLine("Testing Score"); Console.WriteLine("Two Aces in Hand. Expecting 22. " + h1.Score); }
private void dealButton_Click(object sender, EventArgs e) { deck = new Deck(); player = new BJHand(); dealer = new BJHand(); deck.Shuffle(); player.Add(deck.Deal()); dealer.Add(deck.Deal()); player.Add(deck.Deal()); dealer.Add(deck.Deal()); LoadPlayerHand(); LoadDealerHand(); }
public void TestBJHand() { Hand hand = new BJHand(); Card card = new Card(CardSuit.DIAMONDS, CardValue.FIVE); hand.TakeCard(card); card = new Card(CardSuit.SPADES, CardValue.KING); hand.TakeCard(card); card = new Card(CardSuit.CLUBS, CardValue.TEN); hand.TakeCard(card); Assert.AreEqual(25u, hand.GetHandValue(), "Wrong hand value calculation."); Assert.ThrowsException <System.NotImplementedException>(() => _ = hand.ThrowCard(0)); hand.ResetHand(); Assert.AreEqual(0u, hand.GetHandValue(), "Wrong hand value calculation after reset"); }
public boardFormSimple() { InitializeComponent(); // Initializes the instance variables cards = new Deck(); dealerHand = new BJHand(); playerHand = new BJHand(); // Shuffles the new deck 10 times for (int i = 0; i < 10; i++) { cards.Shuffle(); } }
private void newHandButton_Click(object sender, EventArgs e) { deck = new Deck(); player = new BJHand(); dealer = new BJHand(); deck.Shuffle(); player.Add(deck.Deal()); // deal a card and add to player's hand dealer.Add(deck.Deal()); player.Add(deck.Deal()); dealer.Add(deck.Deal()); LoadPlayerHand(); LoadDealerHand(); }
private void ComputerTurn(BJHand h) { for (int i = 0; i < 5; i++) { PictureBox pb = GetPictureBox(i + 16); if (i < h.NumCards) { Show(pb, h.GetCard(i)); pb.Visible = true; } else { pb.Hide(); } } }
private void Setup() { //Created objects d = new Deck(); d.Shuffle(); playerHand = new BJHand(d, 2); dealerHand = new BJHand(d, 2); //Add's cards to UI PlayerTurn(playerHand); ComputerTurn(dealerHand); //Showing what's visible hitButton.Enabled = true; standButton.Enabled = true; playerWinLabel.Visible = false; dealerWinLabel.Visible = false; playAgainButton.Enabled = false; }
private void frmBoard_Load(object sender, EventArgs e) { // MessageBox.Show("I got to here"); hitButton.Enabled = true; standButton.Enabled = true; playerWinLabel.Visible = false; dealerWinLabel.Visible = false; playAgainButton.Enabled = false; //shuffle the deck and give both the player and the dealer two cards-MWB_4/29/2019 deck.Shuffle(); playerHand = new BJHand(deck, 2); dealerHand = new BJHand(deck, 2); playerpb = new List <PictureBox> { card1, card2, card3, card4, card5 }; dealerpb = new List <PictureBox> { card16, card17, card18, card19, card20 }; //show faces of first two cards and backs of remaining cards immediately -MWB_4/29/2019 Show(playerpb[0], playerHand[0]); Show(playerpb[1], playerHand[1]); ShowBack(playerpb[2], playerHand[0]); ShowBack(playerpb[3], playerHand[0]); ShowBack(playerpb[4], playerHand[0]); //next card should be the third card which is called position 2-MWB_4/29/2019 playerNextDrawIndex = 2; //the dealer gets some cards too-MWB_4/29/2019 Show(dealerpb[0], dealerHand[0]); Show(dealerpb[1], dealerHand[1]); ShowBack(dealerpb[2], dealerHand[0]); ShowBack(dealerpb[3], dealerHand[0]); ShowBack(dealerpb[4], dealerHand[0]); //next card should be the third card which is called position 2-MWB_4/29/2019 dealerNextDrawIndex = 2; }
public BJPlayer() { Hand = new BJHand(); }
public void ReturnHand(BJHand hand) { Deck.DiscardHand(hand.ClearHand()); }
public void SetUpAllTests() { def = new BJHand(); defDeck = new Deck(); overloaded = new BJHand(defDeck, 2); }
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(); }
static void BlackJackGameTest() { // Make the deck and shuffle. Deck d = new Deck(); d.Shuffle(); // Initiate the dealer and player. BJHand dealer = new BJHand(d, 2); BJHand player = new BJHand(d, 2); // While playing start hitting or just stand. bool playing = true; while (playing) { if (player.Score == 21) { Console.WriteLine("The player just scored a blackjack."); return; } else if (dealer.Score == 21) { Console.WriteLine("The dealer just scored a blackjack."); return; } Console.WriteLine("Enter HIT to draw a card or STAND to finish up."); ShowResults(player, dealer); string sss = Console.ReadLine(); if (sss == "HIT") { player.AddCard(d.Draw()); dealer.AddCard(d.Draw()); if (player.Score > 20 || dealer.Score > 20) { playing = false; ShowResults(player, dealer); } } else if (sss == "STAND") { playing = false; ShowResults(player, dealer); } else { Console.WriteLine("That wasn't a readable answer, try again."); } } // Game over. Console.WriteLine("Calculating results."); // If the dealer has a score less than the player and neither are busted. while (dealer.Score <= player.Score && !(dealer.IsBusted || player.IsBusted)) { dealer.AddCard(d.Draw()); ShowResults(player, dealer); } // Show the final results. if ((player.IsBusted && dealer.IsBusted) || (player.Score == dealer.Score)) { Console.WriteLine("It's a tie."); } else { if (player.IsBusted) { Console.WriteLine("The player has busted and the dealer won."); } else if (dealer.IsBusted) { Console.WriteLine("The dealer has busted and the player won."); } else if (player.Score > dealer.Score) { Console.WriteLine("The player has won."); } else { Console.WriteLine("The dealer has won."); } } }
private static void TestScoreIsBusted() { Random ranGen = new Random(); // Non-Face Cards, Non-Aces Console.WriteLine("Testing non-face cards, non-Aces scoring..."); Console.WriteLine(); BJHand bjHand = new BJHand(); bjHand.AddCard(new Card(2, ranGen.Next(1, 5))); bjHand.AddCard(new Card(8, ranGen.Next(1, 5))); Console.WriteLine(bjHand.ToString()); Console.WriteLine("Expect: Score = 10"); Console.WriteLine("Result: Score = " + bjHand.Score.ToString()); Console.WriteLine(); Console.WriteLine("Expect: IsBusted = False"); Console.WriteLine("Result: IsBusted = " + bjHand.IsBusted.ToString()); Console.WriteLine(); bjHand.AddCard(new Card(9, ranGen.Next(1, 5))); bjHand.AddCard(new Card(5, ranGen.Next(1, 5))); Console.WriteLine(bjHand.ToString()); Console.WriteLine("Expect: Score = 24"); Console.WriteLine("Result: Score = " + bjHand.Score.ToString()); Console.WriteLine(); Console.WriteLine("Expect: IsBusted = True"); Console.WriteLine("Result: IsBusted = " + bjHand.IsBusted.ToString()); Console.WriteLine(); ContinuePrompt(); // Face Cards Console.WriteLine("Testing face card scoring ..."); Console.WriteLine(); bjHand = new BJHand(); bjHand.AddCard(new Card(11, ranGen.Next(1, 5))); bjHand.AddCard(new Card(12, ranGen.Next(1, 5))); Console.WriteLine(bjHand.ToString()); Console.WriteLine("Expect: Score = 20"); Console.WriteLine("Result: Score = " + bjHand.Score.ToString()); Console.WriteLine(); Console.WriteLine("Expect: IsBusted = False"); Console.WriteLine("Result: IsBusted = " + bjHand.IsBusted.ToString()); Console.WriteLine(); bjHand.AddCard(new Card(13, ranGen.Next(1, 5))); Console.WriteLine(bjHand.ToString()); Console.WriteLine("Expect: Score = 30"); Console.WriteLine("Result: Score = " + bjHand.Score.ToString()); Console.WriteLine(); Console.WriteLine("Expect: IsBusted = True"); Console.WriteLine("Result: IsBusted = " + bjHand.IsBusted.ToString()); Console.WriteLine(); ContinuePrompt(); Console.WriteLine("Testing ace scoring ..."); Console.WriteLine(); bjHand = new BJHand(); bjHand.AddCard(new Card(1, ranGen.Next(1, 5))); bjHand.AddCard(new Card(10, ranGen.Next(1, 5))); Console.WriteLine(bjHand.ToString()); Console.WriteLine("Expect: Score = 21"); Console.WriteLine("Result: Score = " + bjHand.Score.ToString()); Console.WriteLine(); Console.WriteLine("Expect: IsBusted = False"); Console.WriteLine("Result: IsBusted = " + bjHand.IsBusted.ToString()); Console.WriteLine(); bjHand.AddCard(new Card(1, ranGen.Next(1, 5))); Console.WriteLine(bjHand.ToString()); Console.WriteLine("Expect: Score = 12"); Console.WriteLine("Result: Score = " + bjHand.Score.ToString()); Console.WriteLine(); Console.WriteLine("Expect: IsBusted = False"); Console.WriteLine("Result: IsBusted = " + bjHand.IsBusted.ToString()); Console.WriteLine(); }