Esempio n. 1
0
    //INCOMPLETE: Current playing code relies on hits from user input. Not sure how to make it work with AI actions.
    //Moves a card from the hand to the discard pile
    //Assuming passed cardName is legal to play
    public void playFromHand(GameObject handPos, List <string> hand, string cardName)
    {
        if (cardName == "NULL")
        {
            print("  >Not playing a card");
            return;
        }
        print("  >Playing " + cardName);

        /*Place the card onto the discard pile and remove from hand*/
        //GameObject temp = GameObject.Find("UNOGame").GetComponent<UNO>().DiscardPos;
        //hit.transform.parent = temp.transform;

        //Move card onto top of discard pile
        //hit.transform.position = new Vector3(temp.transform.position.x, temp.transform.position.y, temp.transform.position.z - .03f * (GameObject.Find("UNOGame").GetComponent<UNO>().Discard.Count + 1));

        //Add to the discard pile and remove from player hand
        hand.Remove(cardName);
        Discard.Add(cardName);

        //hit.transform.GetComponent<Selectable>().playerCard = false;

        //Moving to function
        input.refresh_hand_display(handPos);

        curColor = cardName[0];
        actionManager.getRules(cardName);
        actionManager.playDone = true;

        return;
    }
Esempio n. 2
0
    void GetMouseClick()
    {
        if (Input.GetMouseButtonDown(0))
        {
            if (EventSystem.current.IsPointerOverGameObject())
            {
                return;
            }

            //clickCount++;

            Vector3      mousePosition = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, -10));
            RaycastHit2D hit           = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
            if (hit)
            {
                // what has been hit? Deck/Card/EmptySlot...
                if (hit.collider.CompareTag("Deck"))
                {
                    //clicked deck

                    Deck();
                }
                else if ((hit.collider.CompareTag("Card")) && (hit.transform.GetComponent <Selectable>().playerCard == false))
                {
                    //Shouldn't detect anything if clicked on another player's card

                    //Card();
                }
                else if ((hit.collider.CompareTag("Card")) && (hit.transform.GetComponent <Selectable>().playerCard == true))
                {
                    //Card(cardName);
                    //print(hit.transform.name);

                    /*
                     * string testCase = hit.transform.name;//" Wild";
                     * if(valid(testCase))
                     * {
                     *  print("  valid("+testCase+") works");
                     * }
                     * else
                     * {
                     *  print("  valid("+testCase+") doesn't work");
                     * }
                     */

                    //If the card is valid, play it
                    if (actionManager.playAllowed)
                    {
                        if (valid(hit.transform.name) && ((!actionManager.cardDrawn) || (hit.transform.name == UNOsystem.Player1[UNOsystem.Player1.Count - 1])))//Connecting to turnActionManager.cs; Determining whether allowed to play and which cards to play
                        {
                            print("  >Playing " + hit.transform.name);
                            /*Place the card onto the discard pile and remove from hand*/
                            GameObject temp = GameObject.Find("UNOGame").GetComponent <UNO>().DiscardPos;
                            hit.transform.parent = temp.transform;
                            //Move card onto top of discard pile
                            hit.transform.position = new Vector3(temp.transform.position.x, temp.transform.position.y, temp.transform.position.z - .03f * (GameObject.Find("UNOGame").GetComponent <UNO>().Discard.Count + 1));

                            //Add to the discard pile and remove from player hand
                            GameObject.Find("UNOGame").GetComponent <UNO>().Player1.Remove(hit.transform.name);
                            GameObject.Find("UNOGame").GetComponent <UNO>().Discard.Add(hit.transform.name);
                            hit.transform.GetComponent <Selectable>().playerCard = false;
                            allAudio[1].Play();
                            //Moving to function
                            refresh_hand_display(UNOsystem.Player1Pos);

                            /*
                             * // Update the position of remaining Player1 cards
                             * float xOffset = 0.03f;
                             * float yOffset = 0.03f;
                             * float zOffset = 0.03f;
                             * foreach (Transform child in UNOsystem.Player1Pos.transform)
                             * {
                             *  child.gameObject.transform.position = new Vector3(UNOsystem.Player1Pos.transform.position.x + xOffset, UNOsystem.Player1Pos.transform.position.y - yOffset, UNOsystem.Player1Pos.transform.position.z - zOffset);
                             *  xOffset = xOffset + 1.0f;
                             *  zOffset = zOffset + 0.05f;
                             * }
                             */

                            /* ------ the card play logic goes here ------*/
                            UNOsystem.curColor = hit.transform.name[0];
                            actionManager.getRules(hit.transform.name);
                            actionManager.playDone = true;

                            HardAI.addCard(hit.transform.name, HardAI.discardMem);

                            print("This is valid");
                        }
                        else //otherwise, ignore the card click
                        {
                            print("Invalid, select another.");
                        }
                    }
                }

                /*
                 * else if (hit.collider.CompareTag("Discard Pile"))
                 * {
                 *  // clicked card
                 *
                 *  Discard_Pile();
                 * }
                 */
                else if (hit.collider.CompareTag("UNO Button"))
                {
                    // clicked UNO button this frame

                    UNO_Button();
                }
            }
        }
    }