Exemplo n.º 1
0
        public void TestAdd()
        {
            CardStack stack =
                CardStack.GetEmptyStack(CardStackOrientation.FaceDown);
            Card card;

            card = new Card(CardSuit.Hearts, CardRank.Ace);
            stack.AddCard(card);
            Assert.AreEqual(stack.Count, 1);
            Assert.AreEqual(stack.Contents[0],
                            new Card(CardSuit.Hearts, CardRank.Ace));

            stack.Flip();
            card = new Card(CardSuit.Diamonds, CardRank.King);
            stack.AddCard(card);
            Assert.AreEqual(2, stack.Count);
            Assert.AreEqual(new Card(CardSuit.Diamonds, CardRank.King),
                            stack.Contents[0]);
            Assert.AreEqual(new Card(CardSuit.Hearts, CardRank.Ace),
                            stack.Contents[1]);

            //Add a duplicated card
            stack.AddCard(new Card(CardSuit.Diamonds, CardRank.King));
            Assert.AreEqual(3, stack.Count);
            Assert.AreEqual(new Card(CardSuit.Diamonds, CardRank.King),
                            stack.Contents[0]);
            Assert.AreEqual(new Card(CardSuit.Diamonds, CardRank.King),
                            stack.Contents[1]);
            Assert.AreEqual(new Card(CardSuit.Hearts, CardRank.Ace),
                            stack.Contents[2]);
            Assert.AreEqual(stack.Contents[0], stack.Contents[1]);

            stack.Flip();
            Assert.AreEqual(stack.Contents[1], stack.Contents[2]);
        }
Exemplo n.º 2
0
    void StartGame()
    {
        VictoryScreen.SetActive(false);
        InitDeck();
        DistributeCard();

        List <Card> deck = Deck.GetCards();

        m_playerTurn = 0;
        PlayedCard.AddCard(deck[deck.Count - 1]);
        m_lastCardplayed = deck[deck.Count - 1];
        Deck.RemoveCard(deck[deck.Count - 1]);
        history.text = "";
        PlayNextTurn();
    }
Exemplo n.º 3
0
    public void AllocateCard(GameObject card)
    {
        var diff1X = active.transform.position.x - card.transform.position.x;
        var diff1Z = active.transform.position.z - card.transform.position.z;

        var diff2X = inactive.transform.position.x - card.transform.position.x;
        var diff2Z = inactive.transform.position.z - card.transform.position.z;

        if (Mathf.Sqrt(Mathf.Pow(diff1X, 2) + Mathf.Pow(diff1Z, 2))
            > Mathf.Sqrt(Mathf.Pow(diff2X, 2) + Mathf.Pow(diff2Z, 2)))
        {
            if (active.transform.FindChild(card.name))
            {
                active.RemoveTopCard();
            }
            inactive.AddCard(card);
        }
        else
        {
            if (inactive.transform.FindChild(card.name))
            {
                inactive.RemoveTopCard();
            }
            active.AddCard(card);
        }
    }
Exemplo n.º 4
0
    private void Setup()
    {
        SetPhase(Phase.Setup);
        m_turn     = 0;
        m_handSize = m_handBones.Count;
        m_mana     = 3;

        // TODO: remove test
        // For testing, initialize all soldiers to be lizards
        for (int i = 0; i < m_soldiers.Count; i++)
        {
            int random = Random.Range(0, m_soldierData.Count);
            m_soldiers[i].Initialize(m_soldierData[random]);
        }

        // TODO: Load up the deck for the game sommehow?
        // For now, we will just create a deck of random cards
        // Create a deck with random action cards for player, and random calamities
        for (int i = 0; i < DECK_SIZE; i++)
        {
            int random = Random.Range(0, m_actionData.Count);
            m_draw.AddCard(m_actionData[random]);
        }

        for (int i = 0; i < CALAMITY_DECK_SIZE; i++)
        {
            int random = Random.Range(0, m_calamityData.Count);
            m_calamitiesDraw.AddCard(m_calamityData[random]);
        }

        Reveal();
    }
Exemplo n.º 5
0
        public void TestSort()
        {
            Card kingOfDiamonds  = new Card(CardSuit.Diamonds, CardRank.King);
            Card deuceOfDiamonds = new Card(CardSuit.Diamonds, CardRank.Deuce);
            Card fiveOfHearts    = new Card(CardSuit.Hearts, CardRank.Five);
            Card sixOfSpades     = new Card(CardSuit.Spades, CardRank.Six);

            CardStack stack =
                CardStack.GetEmptyStack(CardStackOrientation.FaceDown);

            stack.AddCard(kingOfDiamonds);
            stack.AddCard(deuceOfDiamonds);
            stack.AddCard(fiveOfHearts);
            stack.AddCard(sixOfSpades);

            //facedown sort by suit/rank
            stack.Sort(Card.COMPARE_SUIT_RANK);
            Assert.AreEqual(fiveOfHearts, stack.Contents[0]);
            Assert.AreEqual(sixOfSpades, stack.Contents[1]);
            Assert.AreEqual(deuceOfDiamonds, stack.Contents[2]);
            Assert.AreEqual(kingOfDiamonds, stack.Contents[3]);

            //face up sort by suit/rank
            stack.Flip();
            stack.Sort(Card.COMPARE_SUIT_RANK);
            Assert.AreEqual(fiveOfHearts, stack.Contents[0]);
            Assert.AreEqual(sixOfSpades, stack.Contents[1]);
            Assert.AreEqual(deuceOfDiamonds, stack.Contents[2]);
            Assert.AreEqual(kingOfDiamonds, stack.Contents[3]);

            //face down sort by rank/suit
            stack.Flip();
            stack.Sort(Card.COMPARE_RANK_SUIT);
            Assert.AreEqual(deuceOfDiamonds, stack.Contents[0]);
            Assert.AreEqual(fiveOfHearts, stack.Contents[1]);
            Assert.AreEqual(sixOfSpades, stack.Contents[2]);
            Assert.AreEqual(kingOfDiamonds, stack.Contents[3]);

            //face up sort by rank/suit
            stack.Flip();
            stack.Sort(Card.COMPARE_RANK_SUIT);
            Assert.AreEqual(deuceOfDiamonds, stack.Contents[0]);
            Assert.AreEqual(fiveOfHearts, stack.Contents[1]);
            Assert.AreEqual(sixOfSpades, stack.Contents[2]);
            Assert.AreEqual(kingOfDiamonds, stack.Contents[3]);
        }
Exemplo n.º 6
0
    public void PickACard(CardStack stack)
    {
        List <Card> deck = Deck.GetCards();

        stack.AddCard(deck[deck.Count - 1]);
        Deck.RemoveCard(deck[deck.Count - 1]);
        history.text = "Player " + (m_playerTurn + 1) + " picked a card";
    }
Exemplo n.º 7
0
 public virtual void MoveCardToStack(Card card, CardStack stack, bool IsSloppy)
 {
     Cards.Remove(card);
     stack.AddCard(card);
     card.transform.SetParent(stack.transform, true);
     card.Parent = stack;
     stack.SetZPositionToTopOfStack(card);
     if (IsSloppy)
     {
         card.SetRandomTransform(20.0f, 0.2f);
     }
 }
Exemplo n.º 8
0
    private void Draw()
    {
        SetPhase(Phase.Draw);

        // First, discard all current hand
        foreach (Card card in m_hand)
        {
            // TODO: Discard delegate called here

            // Add to discard pile
            m_discard.AddCard(card);
        }
        m_hand.Clear();

        // Draw the maximum amount of cards
        // TODO: Clean this up
        int currentHandPosition = 0;
        int toDraw = m_handSize;

        while (toDraw > 0)
        {
            // If the draw pile is empty, then shuffle the discard pile inside of it
            if (m_draw.IsEmpty())
            {
                m_discard.Shuffle();
                m_draw.AddCardStack(m_discard);
            }

            // Take the top of the draw pile and add it to the next hand
            Card topDrawCard = m_draw.RemoveTop();
            topDrawCard.transform.SetParent(m_handBones[currentHandPosition], false);
            m_hand.Add(topDrawCard);
            currentHandPosition++;
            toDraw--;
        }

        EnterMainPhase();
    }
Exemplo n.º 9
0
    // DealersTurn is a coroutine that gets kick off after the player stands
    // or has a card stack value >= 21. It will execute the automated dealer
    // hit/stand. After the dealers hand value > 17 then it will decide the
    // turn out of the round.
    private IEnumerator DealersTurn()
    {
        // disable these buttons since it is not longer the players turn
        HitButton.interactable        = false;
        StandButton.interactable      = false;
        DoubleDownButton.interactable = false;

        // since it is the dealers turn then don't hide their score or cards
        _HideDealerScore = false;
        Dealer.GetCard(1).GetComponent <Card>().ToggleFace(true);

        // loop will the dealers card stack value is less than 17
        while (Dealer.Value() < 17)
        {
            // wait 1 sec in between cards for suspense
            yield return(new WaitForSeconds(1));

            Dealer.AddCard(Deck.RemoveCard(), true);
        }

        // dealer has 21 or less
        // AND (player has 21 or more
        //      OR dealer has higher value than player)
        if (Dealer.Value() <= 21 && (Player.Value() > 21 || Dealer.Value() > Player.Value()))
        {
            ResultsText.text        = "Dealer Wins";
            CashDeltaValueText.text = "-$" + Mathf.RoundToInt(BetSlider.value).ToString();
        }
        // player has 21 or less
        // AND (dealer has 21 or more
        //      OR player has higher value than dealer)
        else if (Player.Value() <= 21 && (Dealer.Value() > 21 || Player.Value() > Dealer.Value()))
        {
            // give the player back their bet * bet ratio
            _PlayerCash            += Mathf.RoundToInt(BetSlider.value * _BetRatio);
            ResultsText.text        = "Player Wins";
            CashDeltaValueText.text = "+$" + Mathf.RoundToInt((BetSlider.value * _BetRatio)).ToString();
        }
        // player has 21 or less
        // AND dealer has 21 or less
        // AND player and dealer have equal value
        else if (Player.Value() <= 21 && Player.Value() <= 21 && Player.Value() == Dealer.Value())
        {
            // give the player back their bet
            _PlayerCash            += Mathf.RoundToInt(BetSlider.value);
            ResultsText.text        = "Draw";
            CashDeltaValueText.text = "+$0";
        }
        // player and dealer have over 21
        else
        {
            ResultsText.text        = "House Wins";
            CashDeltaValueText.text = "-$" + Mathf.RoundToInt(BetSlider.value).ToString();
        }

        // force the player to restart if they have zero cash
        if (_PlayerCash > 0)
        {
            // enable these since they are needed to start a round
            BetSlider.interactable  = true;
            DealButton.interactable = true;
        }

        // update the max bet value to the players current cash
        BetSlider.maxValue = _PlayerCash;
        BetSlider.value    = 0;
    }
Exemplo n.º 10
0
    // Deal is used by the deal button. Before the function is called the
    // player will set their bet. The player and dealer will get their
    // initial 2 cards.
    public void Deal()
    {
        // enable these buttons since it is the players turn
        HitButton.interactable   = true;
        StandButton.interactable = true;
        // disable these since we do not want them used mid round
        BetSlider.interactable  = false;
        DealButton.interactable = false;

        // new round so blank the results and cash delta text
        ResultsText.text        = "";
        CashDeltaValueText.text = "";

        // hide the dealers score since it is the players turn
        _HideDealerScore = true;
        // subtract the players bet from their cash
        _PlayerCash -= Mathf.RoundToInt(BetSlider.value);

        // reset the deck if there is less than 14 cards
        // 14 is magic number here. The logic is that 14 cards is the
        // max amount of cards to get a game total of 42. e.g.
        // 4 2s + 4 3s + 4 4s + 2 5s = 46
        if (Deck.GetCardCount() < 14)
        {
            // clear and make a new deck
            Deck.Clear();
            Deck.MakeDeck();
        }

        // clear the card stacks
        Dealer.Clear();
        Player.Clear();

        // loop 2 times
        for (int i = 1; i <= 2; i++)
        {
            // give the player a card face up
            Player.AddCard(Deck.RemoveCard(), true);

            // if it is the 2nd card
            if (i == 2)
            {
                // give the dealer a card face down
                Dealer.AddCard(Deck.RemoveCard(), false);
            }
            // first card
            else
            {
                // give the dealer a card face up
                Dealer.AddCard(Deck.RemoveCard(), true);
            }
        }

        // players hand is 9, 10 or 11 so give option to double down
        // AND the player has enough cash to do their bet again
        if ((Player.Value() == 9 || Player.Value() == 10 || Player.Value() == 11) && _PlayerCash >= Mathf.RoundToInt(BetSlider.value))
        {
            DoubleDownButton.interactable = true;
        }
        else if (Player.Value() == 21)
        {
            StartCoroutine(DealersTurn());
        }
    }