예제 #1
0
    // ETHAN: function that helps flip back the selected two cards with a delay
    IEnumerator flipBack(HandCard hand1, HandCard hand2)
    {
        yield return(new WaitForSeconds(FLIP_TIME));

        if (hand1 != null && hand1.getCard() != null)
        {
            hand1.getCard().flipDown();                                           //guarantees it always flip down and not up
        }
        if (hand2 != null && hand2.getCard() != null)
        {
            hand2.getCard().flipDown();
        }
    }
예제 #2
0
    public void OnDrag(PointerEventData eventData)
    {
        SetDraggedPosition(eventData);
        RectTransform cardRect = handCard.GetRect();

        if (cardRect.anchoredPosition.y > playareaBuffer)
        {
            inPlayable = true;
            if (handCard.getCard().isCombatCard() == true && handCard.getCard().GetTargetType() == Enums.CardTargetType.SingleEnemy)
            {
                Vector2 targetPos = eventData.position;
                handCard.visualContainer.SetActive(false);
                if (handCard.getCard().GetTargetType() == Enums.CardTargetType.SingleEnemy)
                {//TODO: Remove or replace
                }

                container.UpdateTargetingArrowPos(targetPos);
            }
        }
        else
        {
            inPlayable = false;
            if (handCard.getCard().isCombatCard() == true)
            {
                container.DeactivateTargetingArrow();
                handCard.visualContainer.SetActive(true);
            }
        }
        //Change into Arrow if in playable
        myAnimator.SetBool("isPlayable", inPlayable);
        //Scale with distance from bottom if not in playable
    }
예제 #3
0
    void exeBegin(RaycastHit hit)
    {
        if (hit.transform.tag == "HandCard" && hit.transform.GetComponent <HandCard>().getOwner() == this &&
            hit.transform.GetComponent <HandCard>().getCard() != null)
        {
            if (chosenCards == 0)
            {
                // ETHAN: added animation that flips the selected FIRST card
                hc1 = hit.transform.GetComponent <HandCard>();
                hc1.getCard().toggleCard();

                chosenCards++;
            }
            else if (chosenCards == 1 && hit.transform.GetComponent <HandCard>() != hc1)
            {
                // ETHAN: added animation that flips the selected SECOND card
                hc2 = hit.transform.GetComponent <HandCard>();
                hc2.getCard().toggleCard();

                // ETHAN: added animation that flips back the selected two cards (after flipBack() delay)
                StartCoroutine(flipBack(hc1, hc2));

                chosenCards = 0;
                this.unhighlightHand();
                CmdUpdateMode(Modes.WAITING);
                //Debug.Log("waiting");
            }
        }
    }
예제 #4
0
    public void ActivateExamined(HandCard cardToExamine)
    {
        Card c = cardToExamine.getCard();

        className.text   = c.GetDisplayName();
        description.text = c.GetDescription();
        gameObject.SetActive(true);
    }
예제 #5
0
 void exeDoubling(RaycastHit hit)
 {
     if (hit.transform.tag == "HandCard" && hit.transform.GetComponent <HandCard>().getCard() != null &&
         !hit.transform.GetComponent <HandCard>().getOwner().isCambrio())
     {
         control.unhighlightPlayerCardsExcept(null);
         doubleSpot = hit.transform.GetComponent <HandCard>(); //need to remember the spot across calls
         Card doubleCard = doubleSpot.getCard();
         if (doubleCard.getNum() == discard.peekTop().getNum())
         {
             this.CmdDiscardCard(doubleCard.gameObject);
             int handInd = doubleSpot.getOwner().findHandCard(doubleSpot);
             doubleSpot.getOwner().CmdSetCard(handInd, null); //remove card from handcard
             if (doubleSpot.getOwner() != this)
             {
                 CmdUpdateMode(Modes.REPLACING);
                 this.highlightHand();
                 //Debug.Log("replacing");
             }
             else
             {
                 CmdUpdateMode(oldMode);
                 revertBoardState();
             }
         }
         else //double incorrect, add top of discard to player's empty spot
         {
             this.CmdRevealOtherPlayerHandCard(doubleSpot.getOwner().gameObject, doubleSpot.getOwner().findHandCard(doubleSpot));
             int moveDestInd = FindEmptyHandCard();
             if (moveDestInd == -1) //no more empty spots, so you lose
             {
                 this.CmdUpdateMode(Modes.OUT);
                 this.CmdRevealHand();
                 this.CmdNextPlayer();
             }
             else
             {
                 this.CmdSetCard(moveDestInd, discard.peekTop().gameObject);
                 this.CmdPopDiscard();
                 CmdUpdateMode(oldMode);
                 revertBoardState();
             }
         }
     }
     else if (hit.transform.tag == "Discard")
     {
         CmdUpdateMode(oldMode);
         control.unhighlightPlayerCardsExcept(null);
         revertBoardState();
         //Debug.Log(oldMode);
     }
 }
예제 #6
0
    IEnumerator ExamineSelectedCard(HandCard c)
    {
        yield return(new WaitForSeconds(selectedExamineTimer));

        if (selectedCard == c && selectedCard.dragged == false)
        {
            if (selectedCard.getCard().GetCardType() == Enums.CardType.ClassSelect)
            {
                examineClass.ActivateExamined(selectedCard);
            }
            else
            {
                examineCard.ActivateExaminedCard(selectedCard);
            }
        }
        yield return(new WaitForEndOfFrame());
    }
예제 #7
0
 void exeReplacing(RaycastHit hit)
 {
     if (hit.transform.tag == "HandCard" && hit.transform.GetComponent <HandCard>().getCard() != null)
     {
         HandCard replacingSpot = hit.transform.GetComponent <HandCard>();
         if (replacingSpot.getOwner() == this)
         {
             int doubleHandInd  = doubleSpot.getOwner().findHandCard(doubleSpot);
             int replaceHandInd = this.findHandCard(replacingSpot);
             doubleSpot.getOwner().CmdSetCard(doubleHandInd, replacingSpot.getCard().gameObject);
             this.CmdSetCard(replaceHandInd, null);
             CmdUpdateMode(oldMode);
             this.unhighlightHand();
             revertBoardState();
         }
     }
 }
예제 #8
0
 void exePeek(RaycastHit hit)
 {
     if (hit.transform.tag == "HandCard" && hit.transform.GetComponent <HandCard>().getCard() != null)
     {
         if ((peekingSelf && hit.transform.GetComponent <HandCard>().getOwner() == this) ||
             (!peekingSelf && hit.transform.GetComponent <HandCard>().getOwner() != this))
         {
             hc1 = hit.transform.GetComponent <HandCard>();
             hc1.getCard().flipUp();
             StartCoroutine(flipBack(hc1, null));
             this.CmdFinishTurn();
             if (peekingSelf)
             {
                 this.unhighlightHand();
             }
             else
             {
                 control.unhighlightPlayerCardsExcept(this);
             }
             cancelButton.SetActive(false);
             //Debug.Log("waiting");
         }
     }
     else if (hit.transform.tag == "Discard" && discard.size() > 0)
     {
         cancelButton.SetActive(false);
         oldMode = mode;
         CmdUpdateMode(Modes.DOUBLING);
         control.highlightPlayerCardsExcept(null);
         //Debug.Log("doubling");
     }
     else if (hit.transform.tag == "Cancel")
     {
         cancelButton.SetActive(false);
         control.unhighlightPlayerCardsExcept(null);
         this.CmdFinishTurn();
         //Debug.Log("waiting");
     }
 }
예제 #9
0
    void exeSwap(RaycastHit hit)
    {
        if (hit.transform.tag == "HandCard" && hit.transform.GetComponent <HandCard>().getCard() != null)
        {
            if (pickingSelfForSwap && hit.transform.GetComponent <HandCard>().getOwner() == this)
            {
                thisSwapSpot       = hit.transform.GetComponent <HandCard>();
                pickingSelfForSwap = false;
                this.unhighlightHand();
                control.highlightPlayerCardsExcept(this);
            }
            else if (!pickingSelfForSwap && hit.transform.GetComponent <HandCard>().getOwner() != this &&
                     !hit.transform.GetComponent <HandCard>().getOwner().isCambrio())
            {
                otherSwapSpot = hit.transform.GetComponent <HandCard>();

                Card thisSwapCard  = thisSwapSpot.getCard();
                Card otherSwapCard = otherSwapSpot.getCard();

                if (!swapIsBlind)
                {
                    thisSwapCard.flipUp();
                    otherSwapCard.flipUp();
                    confirmButton.SetActive(true);
                    cancelButton.SetActive(true);
                    control.unhighlightPlayerCardsExcept(this);
                    this.CmdUpdateMode(Modes.KING_DECIDING);
                }
                else
                {
                    int thisSwapInd  = this.findHandCard(thisSwapSpot);
                    int otherSwapInd = otherSwapSpot.getOwner().findHandCard(otherSwapSpot);
                    this.CmdSetCard(thisSwapInd, otherSwapCard.gameObject);
                    this.CmdSetOtherPlayerCard(otherSwapSpot.getOwner().gameObject, otherSwapInd, thisSwapCard.gameObject);
                    pickingSelfForSwap = true;
                    thisSwapSpot       = null;
                    otherSwapSpot      = null;
                    cancelButton.SetActive(false);
                    control.unhighlightPlayerCardsExcept(this);
                    this.CmdFinishTurn();
                    //Debug.Log("waiting");
                }
            }
        }
        else if (hit.transform.tag == "Discard" && discard.size() > 0 && pickingSelfForSwap) //can only double before picking the first card
        {
            oldMode = mode;
            CmdUpdateMode(Modes.DOUBLING);
            control.highlightPlayerCardsExcept(null);
            cancelButton.SetActive(false);
            //Debug.Log("doubling");
        }
        else if (hit.transform.tag == "Cancel")
        {
            cancelButton.SetActive(false);
            control.unhighlightPlayerCardsExcept(null);
            if (thisSwapSpot != null)
            {
                thisSwapSpot.getCard().flipDown();
            }
            if (otherSwapSpot != null)
            {
                otherSwapSpot.getCard().flipDown();
            }
            this.CmdFinishTurn();
            //Debug.Log("waiting");
        }
    }
예제 #10
0
    void FixedUpdate()
    {
        if (this.isLocalPlayer)
        {
            /*Touch touch = Input.touches[0];
             * if (touch.phase == TouchPhase.Began) {
             *  Ray ray = Camera.main.ScreenPointToRay(touch.position);*/
            if (Input.GetMouseButtonDown(0))
            {
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit))
                {
                    switch (mode)
                    {
                    case Modes.BEGIN:
                        if (hit.transform.tag == "HandCard" && hit.transform.GetComponent <HandCard>().getOwner() == this &&
                            hit.transform.GetComponent <HandCard>().getCard() != null)
                        {
                            if (chosenCards == 0)
                            {
                                //reveal card
                                chosenCards++;
                                Debug.Log(chosenCards);
                            }
                            else if (chosenCards == 1)
                            {
                                //reveal card
                                chosenCards = 0;
                                mode        = Modes.WAITING;
                                control.nextPlayerTurn();
                                Debug.Log("waiting");
                                //unhighlight own cards
                            }
                        }
                        break;

                    case Modes.DRAW:
                        if (hit.transform.tag == "Deck")
                        {
                            //play animation of drawing card
                            activeCard = deck.drawCard();
                            mode       = Modes.TURN;
                            Debug.Log("turn");
                        }
                        else if (hit.transform.tag == "Discard")
                        {
                            oldMode = mode;
                            mode    = Modes.DOUBLING;
                            Debug.Log("doubling");
                        }
                        break;

                    case Modes.TURN:
                        if (hit.transform.tag == "Discard")
                        {
                            //play animation moving card to discard pile
                            discard.addCard(activeCard);
                            if (activeCard.getNum() == PEEK_SELF_7 || activeCard.getNum() == PEEK_SELF_8)
                            {
                                mode        = Modes.PEEK;
                                peekingSelf = true;
                            }
                            else if (activeCard.getNum() == PEEK_OTHER_9 || activeCard.getNum() == PEEK_OTHER_10)
                            {
                                mode        = Modes.PEEK;
                                peekingSelf = false;
                            }
                            else if (activeCard.getNum() == BLIND_SWAP_J || activeCard.getNum() == BLIND_SWAP_Q)
                            {
                                mode = Modes.SWAP;
                                pickingSelfForSwap = true;
                                swapIsBlind        = true;
                            }
                            else if (activeCard.getNum() == SEE_SWAP_K)
                            {
                                mode = Modes.SWAP;
                                pickingSelfForSwap = true;
                                swapIsBlind        = false;
                            }
                            activeCard = null;
                        }
                        else if (hit.transform.tag == "HandCard" && hit.transform.GetComponent <HandCard>().getCard() != null)
                        {
                            if (hit.transform.GetComponent <HandCard>().getOwner() == this)
                            {
                                Card oldCard = hit.transform.GetComponent <HandCard>().replaceCard(activeCard);
                                discard.addCard(oldCard);
                                //TODO add animations for replacing card and discarding old card
                                mode = Modes.WAITING;
                                control.nextPlayerTurn();
                                Debug.Log("waiting");
                            }
                        }
                        break;

                    case Modes.PEEK:
                        if (hit.transform.tag == "HandCard" && hit.transform.GetComponent <HandCard>().getCard() != null)
                        {
                            if ((peekingSelf && hit.transform.GetComponent <HandCard>().getOwner() == this) ||
                                (!peekingSelf && hit.transform.GetComponent <HandCard>().getOwner() != this))
                            {
                                Card peekCard = hit.transform.GetComponent <HandCard>().getCard();
                                //TODO play animation of revealing card
                                mode = Modes.WAITING;
                                control.nextPlayerTurn();
                            }
                        }
                        else if (hit.transform.tag == "Discard")
                        {
                            oldMode = mode;
                            mode    = Modes.DOUBLING;
                        }
                        break;

                    case Modes.SWAP:
                        if (hit.transform.tag == "HandCard" && hit.transform.GetComponent <HandCard>().getCard() != null)
                        {
                            if (pickingSelfForSwap && hit.transform.GetComponent <HandCard>().getOwner() == this)
                            {
                                swapSpot1          = hit.transform.GetComponent <HandCard>();
                                pickingSelfForSwap = false;
                                //TODO picked card and other cards
                            }
                            else if (!pickingSelfForSwap && hit.transform.GetComponent <HandCard>().getOwner() != this)
                            {
                                swapSpot2 = hit.transform.GetComponent <HandCard>();
                                if (!swapIsBlind)
                                {
                                    Card swap1 = swapSpot1.getCard();
                                    Card swap2 = swapSpot2.getCard();
                                    //TODO reveal the cards and prompt user if they want to swap
                                    //if they do, then do same as in else block
                                    //if not, then play animation for putting cards down and do nothing
                                }
                                else
                                {
                                    Card swapCard = swapSpot2.replaceCard(swapSpot1.getCard());
                                    swapSpot1.setCard(swapCard);
                                    //TODO play animation
                                }
                                pickingSelfForSwap = true;
                                mode = Modes.WAITING;
                                control.nextPlayerTurn();
                            }
                        }
                        else if (hit.transform.tag == "Discard")
                        {
                            oldMode = mode;
                            mode    = Modes.DOUBLING;
                        }
                        break;

                    case Modes.WAITING:
                        if (hit.transform.tag == "Discard")
                        {
                            oldMode = mode;
                            mode    = Modes.DOUBLING;
                            Debug.Log("doubling");
                        }
                        break;

                    case Modes.DOUBLING:
                        if (hit.transform.tag == "HandCard" && hit.transform.GetComponent <HandCard>().getCard() != null)
                        {
                            doubleSpot = hit.transform.GetComponent <HandCard>();    //need to remember the spot across calls
                            Card doubleCard = doubleSpot.getCard();
                            if (doubleCard.getNum() == discard.checkTop().getNum())
                            {
                                discard.addCard(doubleCard);
                                doubleSpot.setCard(null);     //remove card from handcard
                                //TODO play animation for moving card from handcard to discard
                                if (doubleSpot.getOwner() != this)
                                {
                                    mode = Modes.REPLACING;
                                    //TODO highlight own cards
                                    Debug.Log("replacing");
                                }
                                else
                                {
                                    mode = oldMode;
                                }
                            }
                            else
                            {
                                HandCard moveDest = addCard(discard.drawCard());
                                //play animation of moving card from discard to moveDest
                                mode = oldMode;
                            }
                        }
                        else if (hit.transform.tag == "Discard")
                        {
                            mode = oldMode;
                            Debug.Log(oldMode);
                        }
                        break;

                    case Modes.REPLACING:
                        if (hit.transform.tag == "HandCard" && hit.transform.GetComponent <HandCard>().getCard() != null)
                        {
                            HandCard replacingSpot = hit.transform.GetComponent <HandCard>();
                            if (replacingSpot.getOwner() == this)
                            {
                                doubleSpot.setCard(replacingSpot.getCard());
                                replacingSpot.setCard(null);
                                //TODO play animation for moving card from handcard to handcard
                                mode = oldMode;
                                //TODO unhighlight own cards
                            }
                        }
                        break;
                    }
                }
            }
        }
    }