Ejemplo n.º 1
0
    public void drawCard()
    {
        GameScript  gameScript  = FindObjectOfType <Camera>().GetComponent <GameScript>();
        GameObject  trashObj    = GameObject.Find("P" + gameScript.getPlayer() + " Trash");
        TrashScript trashScript = trashObj.GetComponent <TrashScript>();

        string objName = "P" + gameScript.getPlayer() + " Deck";

        if (gameObject.name.CompareTo(objName) == 0 && (gameScript.noEmptyHouses() || trashScript.isEmpty()))
        {
            // if it's empty we must pull the cards from trash
            if (cardDeck.Count == 0)
            {
                cardDeck = trashScript.getTrashDeck();
                trashScript.emptyTrash();
                this.GetComponent <Image>().sprite = Resources.Load <Sprite>("Images/deck");
            }
            cardObject = GameObject.Find("P" + gameScript.getPlayer() + " Card");

            CardScript cardScript = cardObject.GetComponent <CardScript>();

            cardScript.setCard(cardDeck[0]);

            cardScript.loadCard();

            cardObject.GetComponent <Image>().enabled          = true;
            cardObject.GetComponentInChildren <Text>().enabled = true;

            if (cardDeck.Count == 1) // if this is the last card being drawn
            {
                this.GetComponent <Image>().sprite = Resources.Load <Sprite>("Images/empty");
            }
        }
    }
Ejemplo n.º 2
0
    void trashCard()
    {
        GameScript gameScript = FindObjectOfType <Camera>().GetComponent <GameScript>();

        trashDeck.Add(gameScript.getCardSelected());

        if (gameScript.getCardSelObjName().Contains("Card"))
        {
            CardScript cardScript = GameObject.Find(gameScript.getCardSelObjName()).GetComponent <CardScript>();
            if (gameScript.getCardSelObjName().Contains("1"))
            {
                DeckScript deckScript = GameObject.Find("P1 Deck").GetComponent <DeckScript>();
                deckScript.removeCard();
            }
            else if (gameScript.getCardSelObjName().Contains("2"))
            {
                DeckScript deckScript = GameObject.Find("P2 Deck").GetComponent <DeckScript>();
                deckScript.removeCard();
            }
            cardScript.setEnabled(false);
            cardScript.selectCard(); //To unselect it
        }

        else if (gameScript.getCardSelObjName().Contains("Trash"))
        {
            TrashScript trashScript = GameObject.Find(gameScript.getCardSelObjName()).GetComponent <TrashScript>();
            trashScript.removeCard();
            gameScript.setCardSelected(null);
            gameScript.setCardSelObjName(null);
        }

        else if (gameScript.getCardSelObjName().Contains("Main"))
        {
            HouseScript houseScript = GameObject.Find(gameScript.getCardSelObjName()).GetComponent <HouseScript>();
            houseScript.removeCard();
            gameScript.setCardSelected(null);
            gameScript.setCardSelObjName(null);
        }

        loadCard();
    }
Ejemplo n.º 3
0
    public void addToPile()
    {
        GameScript gameScript = FindObjectOfType <Camera>().GetComponent <GameScript>();

        pile.Add(gameScript.getCardSelected());
        if (pile.Count > 1)
        {
            GameObject newObj;
            GameObject createdObj;
            Transform  parent = gameObject.transform.parent;

            if (gameObject.name.Contains("LH"))
            {
                newObj = Resources.Load <GameObject>("LPiledCard");
                //parentName = "LHCanvas" + houseNum;
                createdObj      = Instantiate(newObj, parent);
                createdObj.name = "LH" + houseNum + "C" + (pile.Count - 1);
                createdObj.transform.localPosition = new Vector3((pile.Count - 2) * -15.0f, 0.0f, 0.0f);
            }
            else //if (gameObject.name.Contains("RH"))
            {
                newObj          = Resources.Load <GameObject>("RPiledCard");
                createdObj      = Instantiate(newObj, parent);
                createdObj.name = "RH" + houseNum + "C" + (pile.Count - 1);
                createdObj.transform.localPosition = new Vector3((pile.Count - 2) * 15.0f, 0.0f, 0.0f);
            }

            gameObject.transform.SetSiblingIndex(pile.Count - 1);
            PiledScript piledScript = createdObj.GetComponent <PiledScript>();
            piledScript.setCard(pile[pile.Count - 2]);
            piledScript.loadCard();
        }

        if (gameScript.getCardSelObjName().Contains("Card"))
        {
            CardScript  cardScript  = GameObject.Find(gameScript.getCardSelObjName()).GetComponent <CardScript>();
            DeckScript  deckScript  = GameObject.Find("P" + gameScript.getPlayer() + " Deck").GetComponent <DeckScript>();
            TrashScript trashScript = GameObject.Find("P" + gameScript.getPlayer() + " Trash").GetComponent <TrashScript>();

            deckScript.removeCard();

            cardScript.setEnabled(false);
            cardScript.selectCard(); //To unselect it

            if (trashScript.isEmpty() && deckScript.isEmpty())
            {
                Instantiate(Resources.Load <GameObject>("Winner"), GameObject.Find("Canvas").transform);
                GameObject.Find("Winner").GetComponent <Text>().text = "Player " + gameScript.getPlayer() + " wins!!";
            }
        }

        else if (gameScript.getCardSelObjName().Contains("Trash"))
        {
            TrashScript trashScript = GameObject.Find(gameScript.getCardSelObjName()).GetComponent <TrashScript>();
            trashScript.removeCard();
            gameScript.setCardSelected(null);
            gameScript.setCardSelObjName(null);

            DeckScript deckScript = GameObject.Find("P" + gameScript.getPlayer() + " Deck").GetComponent <DeckScript>();
            if (trashScript.isEmpty() && deckScript.isEmpty())
            {
                Instantiate(Resources.Load <GameObject>("Winner"), GameObject.Find("Canvas").transform);
                GameObject.Find("Winner(Clone)").GetComponent <Text>().text = "Player " + gameScript.getPlayer() + " wins!!";
            }
        }

        else if (gameScript.getCardSelObjName().Contains("Main"))
        {
            HouseScript houseScript = GameObject.Find(gameScript.getCardSelObjName()).GetComponent <HouseScript>();
            houseScript.removeCard();
            gameScript.setCardSelected(null);
            gameScript.setCardSelObjName(null);
        }

        loadCard();
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Item is dropped in this cell
    /// </summary>
    /// <param name="data"></param>
    public void OnDrop(PointerEventData data)
    {
        if (DNDgem.icon != null)
        {
            DNDgem  item       = DNDgem.draggedItem;
            DNDslot sourceCell = DNDgem.sourceCell;
            if (DNDgem.icon.activeSelf == true)                                  // If icon inactive do not need to drop item into cell
            {
                if ((item != null) && (sourceCell != this))
                {
                    DropEventDescriptor desc = new DropEventDescriptor();
                    switch (cellType)                                                       // Check this cell's type
                    {
                    case CellType.Swap:                                                     // Item in destination cell can be swapped
                        UpdateMyItem();
                        switch (sourceCell.cellType)
                        {
                        case CellType.Swap:                                                 // Item in source cell can be swapped
                            // Fill event descriptor
                            desc.item            = item;
                            desc.sourceCell      = sourceCell;
                            desc.destinationCell = this;
                            SendRequest(desc);                                                   // Send drop request
                            StartCoroutine(NotifyOnDragEnd(desc));                               // Send notification after drop will be finished
                            if (desc.permission == true)                                         // If drop permitted by application
                            {
                                if (myDadItem != null)                                           // If destination cell has item
                                // Fill event descriptor
                                {
                                    DropEventDescriptor descAutoswap = new DropEventDescriptor();
                                    descAutoswap.item            = myDadItem;
                                    descAutoswap.sourceCell      = this;
                                    descAutoswap.destinationCell = sourceCell;
                                    SendRequest(descAutoswap);                                                           // Send drop request
                                    StartCoroutine(NotifyOnDragEnd(descAutoswap));                                       // Send notification after drop will be finished
                                    if (descAutoswap.permission == true)                                                 // If drop permitted by application
                                    {
                                        SwapItems(sourceCell, this);                                                     // Swap items between cells
                                    }
                                    else
                                    {
                                        PlaceItem(item);                                                     // Delete old item and place dropped item into this cell
                                    }
                                }
                                else
                                {
                                    PlaceItem(item);                                                     // Place dropped item into this empty cell
                                }
                            }
                            break;

                        default:                                                            // Item in source cell can not be swapped
                            // Fill event descriptor
                            desc.item            = item;
                            desc.sourceCell      = sourceCell;
                            desc.destinationCell = this;
                            SendRequest(desc);                                                   // Send drop request
                            StartCoroutine(NotifyOnDragEnd(desc));                               // Send notification after drop will be finished
                            if (desc.permission == true)                                         // If drop permitted by application
                            {
                                PlaceItem(item);                                                 // Place dropped item into this cell
                            }
                            break;
                        }
                        break;

                    case CellType.DropOnly:                                                 // Item only can be dropped into destination cell
                        // Fill event descriptor
                        desc.item            = item;
                        desc.sourceCell      = sourceCell;
                        desc.destinationCell = this;
                        SendRequest(desc);                                                       // Send drop request
                        StartCoroutine(NotifyOnDragEnd(desc));                                   // Send notification after drop will be finished
                        if (desc.permission == true)                                             // If drop permitted by application
                        {
                            PlaceItem(item);                                                     // Place dropped item in this cell
                        }
                        TrashScript temp = GetComponent <TrashScript> ();

                        if (temp != null)
                        {
                            temp.trash_item();
                            return;
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
            if (item != null)
            {
                if (item.GetComponentInParent <DNDslot> () == null)                    // If item have no cell after drop
                {
                    Destroy(item.gameObject);                                          // Destroy it
                }
            }
            UpdateMyItem();
            UpdateBackgroundState();
            sourceCell.UpdateMyItem();
            sourceCell.UpdateBackgroundState();
        }
    }