Exemple #1
0
    // This method create a card on the scene during the runtime
    // The card will be initialize with the id took from the deck.
    public void InstantiateUtilCard()
    {
        int PlayerAction = Player.GetPlayerAction();

        if (PlayerTurn1 == true && PlayerAction > 0)
        {
            int nbCardsDeck = currentUtilDeck.UtilCardsList.Count;

            if (nbCardsDeck > 0)
            {
                GameObject newCard = Instantiate(cardPrefab, handPlayer.transform.position, handPlayer.transform.rotation);

                int index = (int)Random.value * nbCardsDeck;

                UtilCardData myCard = currentUtilDeck.UtilCardsList[index];
                currentUtilDeck.UtilCardsList.Remove(myCard);

                var script = newCard.GetComponent <DisplayUtilCard>();
                script.card = myCard;

                var scriptDrag = newCard.GetComponent <Drag>();
                scriptDrag.typeOfAction     = (Drag.Action)myCard.TypeOfAction;
                scriptDrag.parentToReturnTo = handPlayer.transform;

                newCard.transform.SetParent(handPlayer.transform);
                Player.SpendAction();
            }

            numberCardText.text = "Deck Util : " + currentUtilDeck.UtilCardsList.Count.ToString() + " cartes";
        }
    }
Exemple #2
0
    public bool Verif(UtilCardData c)
    {
        int  nb   = 0;
        bool test = true;

        foreach (UtilCardData card in myDeck.UtilCardsList)
        {
            if (card.Id == myCard.Id)
            {
                nb++;
            }
        }
        if (nb == 3)
        {
            test = false;
        }
        return(test);
    }
    public void Update()
    {
        if (i > myUtilDeck.UtilCardsList.Count)
        {
            i = 0;
        }

        if (i < myUtilDeck.UtilCardsList.Count)
        {
            GameObject copy = Instantiate(myTemplate);
            //On copy itemTemplate qui est un bouton

            //on transform le content pour y ajouter le bouton  // copy.transform.parent = content.transform; Vielle Version

            copy.transform.SetParent(myContent.transform);

            UtilCardData c = myUtilDeck.UtilCardsList[i];
            copy.GetComponentInChildren <Text>().text = c.Name;

            copy.GetComponentInChildren <Image>().sprite = c.Artwork;
            int copyIndex = i;
            copy.GetComponent <Button>().onClick.AddListener(

                () =>
            {
                Debug.Log("i = " + copyIndex);
                UtilCardData d = myUtilDeck.UtilCardsList[copyIndex];
                myUtilDeck.UtilCardsList.Remove(d);
                Destroy(copy);

                //On detruit tous les boutons puis on recommence la liste à 0 pour faire basculer les id.
                foreach (Transform child in myContent.transform)
                {
                    GameObject.Destroy(child.gameObject);
                }
                i = 0;
            }
                );
            i++;
        }
        myNumberCards.text = myUtilDeck.UtilCardsList.Count + "/15";
    }
Exemple #4
0
    public void Start()
    {
        playerUtilDeck.text = PlayerPrefs.GetString("UtilDeck");
        Debug.Log(playerUtilDeck.text);

        string path = Application.persistentDataPath + "/" + playerUtilDeck.text + ".json";
        // string path = Application.persistentDataPath + "/deck.json";
        //On lit tout le fichier json
        string contents = System.IO.File.ReadAllText(path);

        //On recupère les objets dans le fichier .json à l'aide de la classe JsonHelper et on les stocks dans un Array de Card
        string[] card = JsonHelper.FromJson <string>(contents);

        for (int i = 0; i < card.Length; i++)
        {
            UtilCardData c = myDataBase.Get(card[i]);
            currentUtilDeck.UtilCardsList.Add(c);
        }

        numberCardText.text = "Deck Util : " + currentUtilDeck.UtilCardsList.Count.ToString() + " cartes";
    }
Exemple #5
0
    // Update is called once per frame
    void Update()
    {
        List <string> myUtilDecks = myDecksList.myUtilDecks;

        if (i < myUtilDecks.Count)
        {
            GameObject copy    = Instantiate(itemTemplate);
            GameObject copydel = Instantiate(itemTemplate2);

            //On copy itemTemplate qui est un bouton

            //on transform le content pour y ajouter le bouton  // copy.transform.parent = content.transform; Vielle Version

            copy.transform.SetParent(content.transform);
            copydel.transform.SetParent(content.transform);

            string s = myUtilDecks[i];
            copy.GetComponentInChildren <Text>().text = s;
            int copyIndex = i;

            copydel.GetComponent <Button>().onClick.AddListener(

                () =>
            {
                string path = Application.persistentDataPath + "/" + myUtilDecks[copyIndex] + ".json";

                // On retire l'élement de la liste
                myUtilDecks.Remove(myUtilDecks[copyIndex]);
                // On supprime le fichier ayant pour nom liste.deckls[copyIndex]
                File.Delete(path);
                //On détruit tous les boutons dans content puis on fait recommencer i à 0 pour qu'il recharge la liste avec les nouveaux id;
                foreach (Transform child in content.transform)
                {
                    GameObject.Destroy(child.gameObject);
                }
                i = 0;


                // sauvegarde

                string[] fis;

                fis = new string[myUtilDecks.Count];

                int j = 0;
                foreach (string str in myUtilDecks)
                {
                    fis[j] = str;
                    j++;
                }


                string fi = JsonHelper.ToJson(fis, true);
                path      = Application.persistentDataPath + "/dataUtilDecks.json";
                System.IO.File.WriteAllText(path, fi);
            }

                );



            copy.GetComponent <Button>().onClick.AddListener(

                () =>
            {
                Debug.Log("i = " + copyIndex);
                string d = myUtilDecks[copyIndex];

                copy.GetComponentInChildren <Text>().text = d;
                nameDeck.text = d.Replace("_Util", "");

                string path = Application.persistentDataPath + "/" + d + ".json";
                // string path = Application.persistentDataPath + "/deck.json";
                //On lit tout le fichier json
                string contents = System.IO.File.ReadAllText(path);

                //On recupère les objets dans le fichier .json à l'aide de la classe JsonHelper et on les stocks dans un Array de Card
                string[] card = JsonHelper.FromJson <string>(contents);

                for (int i = 0; i < card.Length; i++)
                {
                    UtilCardData c = myDataBase.Get(card[i]);
                    Debug.Log(c.name);
                    myDeck.UtilCardsList.Add(c);
                }
            }
                );
            i++;
        }
    }