Beispiel #1
0
    public HeroPower createHeroPower(string classname, Player p)
    {
        HeroPower     newHeroPower  = Instantiate(baseHeroPower) as HeroPower;
        HeroPowerCard heroPowerCard = getHeroPowerCardByClassname(classname);

        newHeroPower.player = p;
        newHeroPower.SetCard(heroPowerCard);

        return(newHeroPower);
    }
Beispiel #2
0
        //fonction de simplification de parcour de type de card
        private Card searchRightTypeClass(JToken item)
        {
            //je recup mon token et je veux verifier de quel type il est pour utiliser la bonne class
            string   jsonType      = item["type"].Value <string>();
            string   idCard        = item["id"].Value <string>();
            CardType jsonTypeClass = (CardType)Enum.Parse(typeof(CardType), jsonType);

            if (jsonTypeClass == CardType.HERO)
            {
                HeroCard Card = item.ToObject <HeroCard>();
                Card.LinkPicture = "https://art.hearthstonejson.com/v1/render/latest/frFR/512x/" + idCard + ".png";
                Console.WriteLine(Card.Name + " " + Card.Type + " " + Card.CardClass + " " + Card.Rarity + " : " + idCard);
                return(Card);
            }
            else if (jsonTypeClass == CardType.HERO_POWER)
            {
                HeroPowerCard Card = item.ToObject <HeroPowerCard>();
                Card.LinkPicture = "https://art.hearthstonejson.com/v1/render/latest/frFR/512x/" + idCard + ".png";
                Console.WriteLine(Card.Name + " " + Card.Type + " " + Card.CardClass + " " + Card.Rarity + " : " + idCard);
                return(Card);
            }
            else if (jsonTypeClass == CardType.MINION)
            {
                MinionCard Card = item.ToObject <MinionCard>();
                Card.LinkPicture = "https://art.hearthstonejson.com/v1/render/latest/frFR/512x/" + idCard + ".png";
                Console.WriteLine(Card.Name + " " + Card.Type + " " + Card.CardClass + " " + Card.Rarity + " : " + idCard);
                return(Card);
            }
            else if (jsonTypeClass == CardType.SPELL)
            {
                SpellCard Card = item.ToObject <SpellCard>();
                Card.LinkPicture = "https://art.hearthstonejson.com/v1/render/latest/frFR/512x/" + idCard + ".png";
                Console.WriteLine(Card.Name + " " + Card.Type + " " + Card.CardClass + " " + Card.Rarity + " : " + idCard);
                return(Card);
            }
            else if (jsonTypeClass == CardType.WEAPON)
            {
                WeaponCard Card = item.ToObject <WeaponCard>();
                Card.LinkPicture = "https://art.hearthstonejson.com/v1/render/latest/frFR/512x/" + idCard + ".png";
                Console.WriteLine(Card.Name + " " + Card.Type + " " + Card.CardClass + " " + Card.Rarity + " : " + idCard);
                return(Card);
            }

            return(null);
        }
Beispiel #3
0
    public void SetCard(HeroPowerCard _heroPowerCard)
    {
        heroPowerCard = _heroPowerCard;
        GetComponent <SpriteRenderer>().sprite = _heroPowerCard.image;
        string effectFile = heroPowerCard.filename + "Effect";

        effectFile = effectFile.Substring(0, 1).ToUpper() + effectFile.Substring(1);
        try
        {
            gameObject.AddComponent(System.Type.GetType(effectFile));
            effect       = (HeroPowerEffect)GetComponent(System.Type.GetType(effectFile));
            effect.owner = player;
        }
        catch (Exception e)
        {
            gameObject.AddComponent <HeroPowerEffect>();
            effect = GetComponent <HeroPowerEffect>();
        }
    }
Beispiel #4
0
    //method to read in input from text files. Code not written by me (the inside is, but not the Streamreader part).
    private static bool processSomething(string type, string fileName)
    {
        try
        {
            string line;

            StreamReader theReader = new StreamReader(fileName, Encoding.Default);

            using (theReader)
            {
                do
                {
                    line = theReader.ReadLine();
                    if (line != null)
                    {
                        string[] entries;
                        if (type == "cardlist")
                        {
                            entries = line.Split('\t');
                            if (entries.Length > 0)
                            {
                                String tribe;
                                if (entries.Length < 9)
                                {
                                    tribe = "none";
                                }
                                else
                                {
                                    tribe = entries[8];
                                }
                                Card newCard = new Card(entries[0], entries[1], entries[2], entries[3], Convert.ToInt32(entries[4]), Convert.ToInt32(entries[5]), Convert.ToInt32(entries[6]), entries[7], tribe);
                                cardList.Add(newCard);
                            }
                        }
                        else if (type == "herolist")
                        {
                            entries = line.Split('\t');
                            if (entries.Length > 0)
                            {
                                String tribe;
                                if (entries.Length < 8)
                                {
                                    tribe = "none";
                                }
                                else
                                {
                                    tribe = entries[7];
                                }
                                Card newHero = new Card(entries[0], entries[1], entries[2], entries[3], Convert.ToInt32(entries[4]), Convert.ToInt32(entries[5]), Convert.ToInt32(entries[6]), entries[7], tribe);
                                heroList.Add(newHero);
                            }
                        }
                        else if (type == "heropowerlist")
                        {
                            entries = line.Split('\t');
                            if (entries.Length > 0)
                            {
                                HeroPowerCard newHeroPower = new HeroPowerCard(entries[0], entries[1], entries[2], Convert.ToInt32(entries[3]));
                                heroPowerList.Add(newHeroPower);
                            }
                        }
                    }
                }while (line != null);

                theReader.Close();

                return(true);
            }
        }
        catch (Exception e)
        {
            Console.WriteLine("{0}\n", e.Message);
            return(false);
        }
    }
Beispiel #5
0
        public async Task <BuildDeckViewModel> getCards(List <string> types)
        {
            int         countMinion                     = 0;
            int         countSpell                      = 0;
            int         countEnchantment                = 0;
            int         countHero                       = 0;
            int         countHeroPower                  = 0;
            int         countWeapon                     = 0;
            List <Card> CardListMinion                  = new List <Card>();
            List <Card> CardListSpell                   = new List <Card>();
            List <Card> CardListEnchantment             = new List <Card>();
            List <Card> CardListWeapon                  = new List <Card>();
            List <Card> CardListHero                    = new List <Card>();
            List <Card> CardListHeroPower               = new List <Card>();
            List <BuildDeckStatViewModel> viewModelList = new List <BuildDeckStatViewModel>();

            HttpResponseMessage response = await client.GetAsync("https://api.hearthstonejson.com/v1/27845/frFR/cards.json");

            JArray jsonParseList = new JArray();

            if (response.IsSuccessStatusCode)
            {
                jsonParseList = await response.Content.ReadAsAsync <JArray>();

                foreach (var item in jsonParseList)
                {
                    if (item["type"] != null)
                    {
                        string   jsonType      = item["type"].Value <string>();
                        string   idCard        = item["id"].Value <string>();
                        CardType jsonTypeClass = (CardType)Enum.Parse(typeof(CardType), jsonType);
                        foreach (var type in types)
                        {
                            CardType typeClass = (CardType)Enum.Parse(typeof(CardType), type);
                            if (jsonTypeClass == typeClass)
                            {
                                if (typeClass == CardType.ENCHANTMENT)
                                {
                                    EnchantmentCard Card = item.ToObject <EnchantmentCard>();
                                    countEnchantment++;
                                    Card.LinkPicture = "https://art.hearthstonejson.com/v1/render/latest/frFR/512x/" + idCard + ".png";
                                    CardListEnchantment.Add(Card);
                                }
                                else if (typeClass == CardType.HERO)
                                {
                                    HeroCard Card = item.ToObject <HeroCard>();
                                    if (Card.Armor != 0)
                                    {
                                        countHero++;
                                        Card.LinkPicture = "https://art.hearthstonejson.com/v1/render/latest/frFR/512x/" + idCard + ".png";
                                        CardListHero.Add(Card);
                                    }
                                }
                                else if (typeClass == CardType.HERO_POWER)
                                {
                                    HeroPowerCard Card = item.ToObject <HeroPowerCard>();
                                    countHeroPower++;
                                    Card.LinkPicture = "https://art.hearthstonejson.com/v1/render/latest/frFR/512x/" + idCard + ".png";
                                    CardListHeroPower.Add(Card);
                                }
                                else if (typeClass == CardType.MINION)
                                {
                                    MinionCard Card = item.ToObject <MinionCard>();
                                    countMinion++;
                                    Card.LinkPicture = "https://art.hearthstonejson.com/v1/render/latest/frFR/512x/" + idCard + ".png";
                                    CardListMinion.Add(Card);
                                }
                                else if (typeClass == CardType.SPELL)
                                {
                                    SpellCard Card = item.ToObject <SpellCard>();
                                    countSpell++;
                                    Card.LinkPicture = "https://art.hearthstonejson.com/v1/render/latest/frFR/512x/" + idCard + ".png";
                                    CardListSpell.Add(Card);
                                }
                                else if (typeClass == CardType.WEAPON)
                                {
                                    WeaponCard Card = item.ToObject <WeaponCard>();
                                    countWeapon++;
                                    Card.LinkPicture = "https://art.hearthstonejson.com/v1/render/latest/frFR/512x/" + idCard + ".png";
                                    CardListWeapon.Add(Card);
                                }
                            }
                        }
                    }
                }

                CardStat cardStatMinion      = new CardStat("minion", countMinion);
                CardStat cardStatSpell       = new CardStat("spell", countSpell);
                CardStat cardStatHero        = new CardStat("hero", countHero);
                CardStat cardStatHeroPower   = new CardStat("hero_power", countHeroPower);
                CardStat cardStatWeapon      = new CardStat("weapon", countWeapon);
                CardStat cardStatEnchantment = new CardStat("enchantment", countEnchantment);

                var statViewModelMinion = new BuildDeckStatViewModel
                {
                    CardStat = cardStatMinion,
                    Cards    = CardListMinion
                };
                var statViewModelSpell = new BuildDeckStatViewModel
                {
                    CardStat = cardStatSpell,
                    Cards    = CardListSpell
                };
                var statViewModelHero = new BuildDeckStatViewModel
                {
                    CardStat = cardStatHero,
                    Cards    = CardListHero
                };
                var statViewModelHeroPower = new BuildDeckStatViewModel
                {
                    CardStat = cardStatHeroPower,
                    Cards    = CardListHeroPower
                };
                var statViewModelWeapon = new BuildDeckStatViewModel
                {
                    CardStat = cardStatWeapon,
                    Cards    = CardListWeapon
                };
                var statViewModelEnchantment = new BuildDeckStatViewModel
                {
                    CardStat = cardStatEnchantment,
                    Cards    = CardListEnchantment
                };

                BuildDeckStatViewModel[] rangeStatViewModel =
                {
                    statViewModelEnchantment,
                    statViewModelHero,
                    statViewModelHeroPower,
                    statViewModelWeapon,
                    statViewModelSpell,
                    statViewModelMinion
                };

                viewModelList.AddRange(rangeStatViewModel);

                var model = new BuildDeckViewModel
                {
                    Stats = viewModelList
                };
                return(model);
            }
            else
            {
                return(null);
            }
        }