コード例 #1
0
ファイル: DeckTests.cs プロジェクト: genecyber/TDD-BlackJack
 public void DrawingOneCardResultsInOneCardBeingRemovedFromDeck()
 {
     Deck theDeck = new Deck();
     int number = 1;
     theDeck.Draw(number);
     theDeck.CardsRemaining.Count.Should().Be(51);
 }
コード例 #2
0
            public void Draw(Deck deck)
            {
                Card selcard = deck.Draw();

                LastDrawn = selcard;
                CardList.Add(selcard);
            }
コード例 #3
0
ファイル: DeckTests.cs プロジェクト: genecyber/TDD-BlackJack
        public void DrawingCardFromDeckRemovesItFromDeck()
        {
            var theDeck = new Deck();

            var dealt = theDeck.Draw();

            theDeck.CardsRemaining.Should().NotContain(dealt);
        }
コード例 #4
0
ファイル: DeckTests.cs プロジェクト: genecyber/TDD-BlackJack
        public void DrawingTopCardFromShuffledDeckDoesNotReturnAceOfSpades()
        {
            var theDeck = new Deck();
            theDeck.Shuffle();

            var dealt = theDeck.Draw();

            dealt.Should().NotBe(new Card("Spade",1));
        }
コード例 #5
0
        public void DrawCard(MainNode node)
        {
            var se = Sound.Load(@"resources/card-put.ogg", true);

            Engine.Sound.Play(se);

            var card = Deck.Draw();

            Hand.Add(card);
            card.Position = new Vector2F(100 + 100 * Hand.Count, 370);
            card.ZOrder   = Hand.Count;
            node.AddChildNode(card);
        }
コード例 #6
0
ファイル: Dealer.cs プロジェクト: nanaka0012/BlackJack
        public Card FirstDraw(MainNode node)
        {
            var se = Sound.Load(@"resources/card-put.ogg", true);

            Engine.Sound.Play(se);

            var card = Deck.Draw();

            Hand.Add(card);
            card.Position = new Vector2F(100 + 100 * Hand.Count, 150);
            card.ZOrder   = Hand.Count;

            card.IsReverse = true;
            node.AddChildNode(card);
            return(card);
        }
コード例 #7
0
ファイル: DeckTests.cs プロジェクト: genecyber/TDD-BlackJack
        public void DrawingNegativeNumberOfCardsShouldThrowException()
        {
            Deck theDeck = new Deck();

            const int number = -1;
            var isValid = true;

            try
            {
                theDeck.Draw(number);
            }
            catch (Exception e)
            {
                isValid = false;
            }

            isValid.Should().BeFalse();
        }
コード例 #8
0
ファイル: DeckTests.cs プロジェクト: genecyber/TDD-BlackJack
        public void DrawingThreeCardsShouldThrowException()
        {
            Deck theDeck = new Deck();

            int number = 3;
            bool isValid = true;

            try
            {
                theDeck.Draw(number);
            }
            catch (Exception e)
            {
                isValid = false;
            }

            isValid.Should().BeFalse();
        }
コード例 #9
0
 public void Deal(Player player)
 {
     player.Take(deck.Draw());
 }
コード例 #10
0
 // 'Draws' a number of cards from a given deck by adding them to this.Hand and removing them from the deck.
 public void Draw(Deck deck, int num)
 {
     this.Hand.AddRange(deck.Draw(num));
 }
コード例 #11
0
 // 'Draws' a card from a given deck by adding it to this.Hand and removing it from the deck.
 public void Draw(Deck deck)
 {
     this.Hand.Add(deck.Draw());
 }
コード例 #12
0
        /// <summary>
        /// Gives a card to the specified participant
        /// </summary>
        /// <param name="participant">Participant.</param>
        public void DealCardTo(Participant participant)
        {
            Card card = _deck.Draw();

            participant.ReceiveCard(card);
        }
コード例 #13
0
ファイル: DeckTests.cs プロジェクト: genecyber/TDD-BlackJack
        public void DrawingTopCardsFromTwoShuffledDecksShouldBeDifferent()
        {
            var theDeck = new Deck();
            theDeck.Shuffle();
            var anotherDeck = new Deck();
            anotherDeck.Shuffle();

            var card1 = theDeck.Draw();
            var card2 = anotherDeck.Draw();

            card1.Should().NotBe(card2);
        }
コード例 #14
0
ファイル: Player.cs プロジェクト: GorginZ/BlackJack
        public void DrawCard(Deck deck)
        {
            var drawnCard = deck.Draw();

            Hand.Add(drawnCard);
        }
コード例 #15
0
        private void dealButton_Click(object sender, EventArgs e)
        {
            deck.Shuffle(4);
            //dealing dealer's hand
            for (int i = 0; i < 2; i++)
            {
                DealerHand.Add(deck.Draw());
                if ((int)DealerHand[i].Value >= 10)
                {
                    dealerScore += 10;
                }
                else if (DealerHand[i].Value == Enums.Value.Ace)
                {
                    dealerCheck();
                }
                else
                {
                    dealerScore += (int)DealerHand[i].Value;
                }
            }

            PrintHand(DealerHand, DealerPics, true);
            //if the dealer has 21, they win before the player's hand is checked
            if (dealerScore == 21)
            {
                dealt21 = true;
                PrintHand(DealerHand, DealerPics);
                DialogResult dialogResult = MessageBox.Show("The dealer scored 21! Would you like to play again?", "Loss", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    resetGame();
                }
            }

            //dealing player's hand if the dealer doesnt get a 21 on their first turn
            if (!dealt21)
            {
                for (int i = 0; i < 2; i++)
                {
                    PlayerHand.Add(deck.Draw());
                    if ((int)PlayerHand[i].Value >= 10)
                    {
                        playerScore += 10;
                    }
                    else if (PlayerHand[i].Value == Enums.Value.Ace)
                    {
                        using (AceDialogue aceDialogue = new AceDialogue(playerScore))
                        {
                            if (aceDialogue.ShowDialog() == DialogResult.OK)
                            {
                                playerScore += aceDialogue.ChosenValue;
                            }
                        }
                    }
                    else
                    {
                        playerScore += (int)PlayerHand[i].Value;
                    }
                }
                PrintHand(PlayerHand, PlayerPics);
                scoreLabel.Text    = playerScore.ToString();
                dealButton.Enabled = false;
                drawButton.Enabled = true;
                keepButton.Enabled = true;
            }
        }
コード例 #16
0
        public static void Play()
        {
            Deck deck = new Deck();

            Hand player = new Hand();

            player.AddCard(deck.Draw());
            player.AddCard(deck.Draw());
            Console.WriteLine($"Player has drawn {player} worth {player.PointValue} points.");

            if (player.IsBlackJack)
            {
                Console.WriteLine("Black Jack! You Win!");
                return;
            }

            bool keepDrawing;

            do
            {
                Console.WriteLine("Do you want to draw another card?");
                var input = Console.ReadLine().ToLower();
                keepDrawing = input == "yes" || input == "hit me";
                if (keepDrawing)
                {
                    player.AddCard(deck.Draw());
                    Console.WriteLine($"You drew the {player.LastCard.FullName} for a new total of {player.PointValue} points.");
                }
            } while (keepDrawing && !player.IsBusted);

            if (player.IsBusted)
            {
                Console.WriteLine("Busted!  You lose.");
                return;
            }

            Hand computer = new Hand();

            computer.AddCard(deck.Draw());
            computer.AddCard(deck.Draw());
            Console.WriteLine($"Computer has drawn {computer} worth {computer.PointValue} points.");

            if (computer.IsBlackJack)
            {
                Console.WriteLine("Black Jack! You Lose.");
                return;
            }

            while (computer.PointValue < player.PointValue && computer.PointValue <= 21)
            {
                computer.AddCard(deck.Draw());
                Console.WriteLine($"Computer has drawn the {computer.LastCard.FullName} for a new total of {computer.PointValue} points.");
            }

            if (computer.IsBusted)
            {
                Console.WriteLine("Busted!  You win!");
                return;
            }

            if (computer.PointValue >= player.PointValue)
            {
                Console.WriteLine($"The computer won with {computer.PointValue} compared to your {player.PointValue}.");
            }
            if (computer.PointValue == player.PointValue)
            {
                Console.WriteLine("Ties always goes to the house.");
            }

            if (computer.PointValue < player.PointValue)
            {
                Console.WriteLine($"You won with {player.PointValue} compared to its {computer.PointValue}.");
            }

            return;
        }
コード例 #17
0
ファイル: Player.cs プロジェクト: chanaAkerman/BlackJack
        /// <summary>
        /// Player has hit, draw a card from the deck and add it to the player's hand
        /// </summary>
        public void Hit()
        {
            Card c = currentDeck.Draw();

            hand.Cards.Add(c);
        }
コード例 #18
0
 private void DealFirstHandToPlayer(Player player)
 {
     player.Hand.Add(_deck.Draw());
     player.Hand.Add(_deck.Draw());
 }