Example #1
0
    public void MakeButtonCards(List <CardPokerFace> btnCards)
    {
        GameObject    tGO  = null;
        CardPokerFace tCPF = null;

        for (int i = 0; i < btnCards.Count; i++)
        {
            CardButton cb = UIManager.S.cardButtons[i];
            tGO = Instantiate(btnCards[i].gameObject, cb.transform);
            tGO.transform.localPosition = Vector3.zero;
            Destroy(tGO.GetComponent <Collider>());

            tCPF = tGO.GetComponent <CardPokerFace>();
            Destroy(tCPF.pipGOs[0]);
            tCPF.decoGOs[0].transform.localPosition = new Vector3(0f, 0.35f, 0);
            tCPF.decoGOs[1].transform.localPosition = new Vector3(0f, -0.45f, 0);
            tCPF.spriteRenderer.maskInteraction     = SpriteMaskInteraction.VisibleInsideMask;
            foreach (SpriteRenderer sr in tCPF.spriteRenderers)
            {
                sr.maskInteraction = SpriteMaskInteraction.VisibleInsideMask;
            }
            tCPF.faceUp = true;
            cb.SetPlayerCard(btnCards[i]);
            cb.SetUICard(tCPF);
        }
    }
    public void MoveToDiscard(CardPokerFace cd, bool immediate = false)
    {
        //set the state of the card to discard
        cd.state = CardState.Discard;
        discardPile.Add(cd);
        cd.transform.parent = layoutAnchor;

        /*if (immediate)
         * {
         *  cd.transform.localPosition = new Vector3
         *      (
         *          layout.multiplier.x * layout.discardPile.x - 80,
         *          layout.multiplier.y * layout.discardPile.y,
         *          -layout.discardPile.layerID + 0.5f
         *      );
         * }
         * else
         * {
         *  Sequence seq = DOTween.Sequence();
         *  seq.Append(cd.transform.DOMove(new Vector3(0f, 4.5f, 0f), 0.25f));
         *  seq.Append(cd.transform.DOMove(new Vector3(layout.multiplier.x * layout.discardPile.x - 80, layout.multiplier.y * layout.discardPile.y, -layout.discardPile.layerID + 0.5f), 0f));
         *  seq.Play();
         * }*/

        //position it on the discard pile
        cd.faceUp = false;
        //place it on top of the pile for depth sorting
        cd.SetSortingLayerName(layout.discardPile.layerName);
        cd.SetSortOrder(-100 + discardPile.Count);
        cd.playerID = (PlayerID)layout.discardPile.playerID;
    }
    public CardPokerFace Draw()
    {
        CardPokerFace cp = drawPile[0]; //pull the 0th CardPokerFace

        drawPile.RemoveAt(0);           // then remove it from list<> drawPile
        return(cp);
    }
Example #4
0
 public PokerHand(CardPokerFace c1, CardPokerFace c2, CardPokerFace c3, CardPokerFace c4, CardPokerFace c5)
 {
     Cards = new CardPokerFace[] { c1, c2, c3, c4, c5 };
     Sort();
     if (GetGroupByRankCount(5) != 0)
     {
         throw new Exception("Cannot have five cards with the same rank");
     }
     if (HasDuplicates())
     {
         throw new Exception("Cannot have duplicates");
     }
 }
Example #5
0
    public override void Execute(PokerPlayer p)
    {
        CardPokerFace newCard      = null;
        Vector3       cardPosition = Vector3.zero;
        Sequence      seq          = DOTween.Sequence();
        Layout        layout       = PokerFaceManager.S.layout;

        while (p.selectedCards.Count > 0)
        {
            cardPosition    = p.selectedCards[0].transform.localPosition;
            cardPosition.y -= 0.5f;
            int layerID = p.selectedCards[0].spriteRenderer.sortingLayerID;
            PokerFaceManager.S.MoveToDiscard(p.selectedCards[0]);
            // move old card to discard
            seq.Append(p.selectedCards[0].transform.DOMove(new Vector3(0f, 4.5f, 0f), 0.5f));
            newCard = PokerFaceManager.S.Draw(); // get new card from drawpile
            newCard.spriteRenderer.sortingLayerID = layerID;
            newCard.spriteRenderer.sortingOrder   = 0;
            foreach (SpriteRenderer sr in newCard.spriteRenderers)
            {
                sr.sortingLayerID = newCard.spriteRenderer.sortingLayerID;
                if (sr.name == "back")
                {
                    sr.sortingOrder = 2;
                }
                else
                {
                    sr.sortingOrder = 1;
                    Vector3 wantedPos = sr.transform.localPosition;
                    wantedPos.z = -1;
                    sr.transform.localPosition = wantedPos;
                }
            }
            seq.Append(newCard.transform.DOLocalMove(new Vector3(0f, 4.5f, 0f), 0.01f));
            seq.Append(newCard.transform.DOLocalMove(cardPosition, 0.5f).OnStart(() => PokerFaceManager.S.PlaySound(SoundType.CardMoveSlow))); // animate movement
            seq.Append(p.selectedCards[0].transform.DOMove(new Vector3(layout.multiplier.x * layout.discardPile.x - 80, layout.multiplier.y * layout.discardPile.y, -layout.discardPile.layerID + 0.5f), 0f));
            seq.Play();
            newCard.index          = p.selectedCards[0].index; // assigning the correct index
            p.cards[newCard.index] = newCard;                  // assign the correct card to player card list
            p.DeselectCard(p.selectedCards[0]);                // make sure the card is no longer selected
        }
        PokerFaceManager.S.RemovePokerHand(p);
        PokerFaceManager.S.AddPokerHand(p);
    }
Example #6
0
    public void ChangePlayerCard(CardPokerFace c)
    {
        Destroy(_UICard.gameObject);
        GameObject    tGO  = null;
        CardPokerFace tCPF = null;

        tGO = Instantiate(c.gameObject, transform);
        tGO.transform.localPosition = Vector3.zero;
        Destroy(tGO.GetComponent <Collider>());

        tCPF = tGO.GetComponent <CardPokerFace>();
        Destroy(tCPF.pipGOs[0]);
        tCPF.decoGOs[0].transform.localPosition = new Vector3(0f, 0.35f, 0);
        tCPF.decoGOs[1].transform.localPosition = new Vector3(0f, -0.45f, 0);
        tCPF.spriteRenderer.maskInteraction     = SpriteMaskInteraction.VisibleInsideMask;
        foreach (SpriteRenderer sr in tCPF.spriteRenderers)
        {
            sr.maskInteraction = SpriteMaskInteraction.VisibleInsideMask;
        }
        tCPF.faceUp = true;
        SetPlayerCard(c);
        SetUICard(tCPF);
    }
    IEnumerator LayoutGame()
    {
        //empty GameObject serves as an anchor for the tableau
        if (layoutAnchor == null)
        {
            GameObject tGo = new GameObject("_LayoutAnchor");
            layoutAnchor = tGo.transform;
            layoutAnchor.transform.position = layoutCenter;
        }

        CardPokerFace cp;

        //follow the layout
        for (int i = 0; i < layout.slotDefs.Count; i++)
        {
            SlotDef tSD = layout.slotDefs[i];
            //iterate through all the SlotDefs in the layout.slotDefs as tSD
            cp                         = Draw();       //pull a card from the top (beginning) of the drawPile
            cp.faceUp                  = tSD.faceUp;   //set its faceUp
            cp.transform.parent        = layoutAnchor; //this replaces the previous parent: deck.deckAnchor which appears as _Deck in the Hierarchy
            cp.transform.localPosition = new Vector3(0f, 4.5f, -tSD.layerID);
            cp.transform.localRotation = Quaternion.identity;
            cp.transform.localScale    = new Vector3(0.7f, 0.7f, 0.05f);
            if (_players[tSD.playerID].isIn)
            {
                cp.playerID = (PlayerID)tSD.playerID;              //assign the card with the correct player id
                cp.state    = CardState.Table;                     // assign the card state
                cp.layoutID = tSD.id;                              // assign the card layoutID
                cp.SetSortingLayerName(tSD.layerName);             // assign the card sorting layer
                cp.slotDef = tSD;                                  // assign the card slotDef
                table.Add(cp);                                     // add the card to cards on table
                _players[tSD.playerID].cards.Add(cp);              // add the card to the relevant player's list
                cp.index = _players[tSD.playerID].cards.Count - 1; // assign the card the correct index
                //Debug.Log("<color=red>name: " + _players[tSD.playerID].name + " cards: " + _players[tSD.playerID].cards.Count + "</color>");
            }
            else
            {
                cp.playerID = PlayerID.Dealer;
                cp.state    = CardState.DrawPile;
                drawPile.Add(cp);
            }
        }
        foreach (PokerPlayer p in activePlayers)
        {
            p.InitCards();
        }
        foreach (Card c in deck.cards)
        {
            CardPokerFace cpf = c as CardPokerFace;
            if (cpf.state == CardState.DrawPile)
            {
                cpf.transform.localScale = new Vector3(0.7f, 0.7f, 0.05f);
            }
            if (cpf.state != CardState.DrawPile && cpf.state != CardState.Discard)
            {
                //deal the cards...
                SlotDef tSD = cpf.slotDef;
                cpf.transform.localRotation = Quaternion.Euler(new Vector3(0f, 0f, tSD.zRotation));
                cpf.transform.DOLocalMove(new Vector3(layout.multiplier.x * tSD.x, layout.multiplier.y * tSD.y, -tSD.layerID), 0.6f);
                PlaySound(SoundType.CardMove3);
                yield return(new WaitForSeconds(0.25f));
            }
        }
        //position the draw pile
        UpdateDrawPile();
    }
Example #8
0
 public void SetPlayerCard(CardPokerFace c)
 {
     _playerCard = c;
 }
Example #9
0
 public void SetUICard(CardPokerFace c)
 {
     _UICard = c;
 }
Example #10
0
 public void DeselectCard(CardPokerFace card)
 {
     selectedCards.Remove(card);
     CardButton.selectedCards--;
 }
Example #11
0
 public void SelectCard(CardPokerFace card)
 {
     selectedCards.Add(card);
     CardButton.selectedCards++;
 }
Example #12
0
 public bool Contains(CardPokerFace card)
 {
     return(Cards.Where(c => c.rankType == card.rankType && c.suitType == card.suitType).Any());
 }