Пример #1
0
        public void shuffled_deck_returns_different_order()
        {
            // Arrange

            // Return "random" numbers 2 then 1 then 0
            // to reverse the card order
            var rng = Substitute.For<IRandom>();
            rng.Next(100).ReturnsForAnyArgs(2, 1, 0);

            var stackedDeck = GetStackedDeck();

            var deck = Substitute.For<IDeck>();
            deck.GetCards().Returns(stackedDeck);

            IShoe shoe = new Shoe(deck);
            shoe.CardCount().Should().Equal(3);

            // Act
            shoe.Shuffle(rng);

            // Assert
            for (var i = 2; i >= 0; i--)
            {
                shoe.Deal().Should().Be.SameAs(stackedDeck[i]);
                shoe.CardCount().Should().Equal(i);
            }
        }
Пример #2
0
    private string DealCard(string whichPlayer, bool faceUp = true)
    {
        // Set the X and Y based on whether it's the Dealer's or Player's
        // card, and increment X accordingly for the next deal
        if (whichPlayer.ToUpper().StartsWith("D"))
        {
            xOffset        = DealerXOffset + UnityEngine.Random.Range(-6, 6); // Add some randomness for more realistic card placement;;
            yOffset        = DEALERROW + UnityEngine.Random.Range(-6, 6);
            DealerXOffset += CARDOFFSET;
        }
        else
        {
            xOffset        = PlayerXOffset + UnityEngine.Random.Range(-6, 6); // Add some randomness for more realistic card placement;
            yOffset        = PLAYERROW + UnityEngine.Random.Range(-6, 6);
            PlayerXOffset += CARDOFFSET;
        }

        zOffset -= 1;

        Vector3 position = new Vector3(xOffset, yOffset, zOffset);

        string nextCard = gameShoe.Deal();

        // Place the card image, either the card corresponding to the name, or the card back object
        GameObject cardImage = Instantiate(faceUp ? GameObject.Find(nextCard.ToString()) : GameObject.Find("cardBack"), position, Quaternion.identity);

        gameCards.Add(cardImage);

        return(nextCard);
    }
Пример #3
0
        public void shoe_throws_exception_if_deal_when_empty()
        {
            // Arrange
            var card = Substitute.For<IBlackjackCard>();
            IEnumerable<ICard> cards = new List<IBlackjackCard>() { card };

            var deck = Substitute.For<IDeck>();
            deck.GetCards().Returns(cards);

            IShoe shoe = new Shoe(deck);
            shoe.CardCount().Should().Equal(1);

            shoe.Deal();
            shoe.CardCount().Should().Equal(0);

            // Act
            shoe.Deal();  // Should throw a ShoeOutOfCardsException
        }
Пример #4
0
 public void PunterResponds(bool hit)
 {
     punterHand.buttons.gameObject.SetActive(false);
     bankerHand.buttons.gameObject.SetActive(true);
     if (hit)
     {
         shoe.Deal(punterHand);
     }
     gameState = GameState.AskingIfBankerHits;
     if (bankerHand.player is AiPlayer)
     {
         BankerResponds((bankerHand.player as AiPlayer).HitOrStay(punterHand, true));
     }
 }
Пример #5
0
        public void unshuffled_deck_returns_expected_order()
        {
            // Arrange
            var stackedDeck = GetStackedDeck();

            var deck = Substitute.For<IDeck>();
            deck.GetCards().Returns(stackedDeck);

            IShoe shoe = new Shoe(deck);
            shoe.CardCount().Should().Equal(3);

            // Act

            // Assert
            for (var i = 0; i <= 2; i++)
            {
                var card = shoe.Deal();
                card.Should().Be.SameAs(stackedDeck[i]);  // 0, 1, 2
                shoe.CardCount().Should().Equal(2-i);     // 2, 1, 0
            }
        }