示例#1
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);
     }
 }
示例#2
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();
         }
     }
 }
示例#3
0
    void exeKingDeciding(RaycastHit hit)
    {
        if (hit.transform.tag == "Confirm" || hit.transform.tag == "Cancel")
        {
            thisSwapSpot.getCard().flipDown();
            otherSwapSpot.getCard().flipDown();

            if (hit.transform.tag == "Confirm")
            {
                int thisSwapInd  = this.findHandCard(thisSwapSpot);
                int otherSwapInd = otherSwapSpot.getOwner().findHandCard(otherSwapSpot);
                this.CmdSetCard(thisSwapInd, otherSwapSpot.getCard().gameObject);
                this.CmdSetOtherPlayerCard(otherSwapSpot.getOwner().gameObject, otherSwapInd, thisSwapSpot.getCard().gameObject);
            }

            pickingSelfForSwap = true;
            thisSwapSpot       = null;
            otherSwapSpot      = null;
            confirmButton.SetActive(false);
            cancelButton.SetActive(false);
            this.CmdFinishTurn();
        }
    }
示例#4
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");
        }
    }
示例#5
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;
                    }
                }
            }
        }
    }