コード例 #1
0
        public async Task <List <Card> > getPresetDeck(PresetDeckEnum deckShape)
        {
            //récupère un deck en fonction de la selection
            List <Card> deck;

            //selection des cartes
            //deck de moins de 30 cartes
            string[] packCard1 = { "AT_017", "AT_022", "AT_024", "AT_067", "AT_069", "AT_071", "CFM_669", "AT_091", "AT_117", "AT_130", "BOT_059", "BOT_102t", "BOT_104", "BOT_107", "BOT_218", "BOT_218t", "BOT_237", "BOT_286", "BOT_286", "BOT_406", "BOT_413", "BRMA10_6", "BRMA13_4", "BRMA16_5", "BRMA17_9", "CS2_049", "EX1_144", "GILA_600h2", "AT_005", "AT_005", "EX1_144" };
            //deck avec 3 cartes identiques
            string[] packCard2 = { "AT_017", "AT_022", "AT_024", "AT_067", "AT_069", "AT_071", "CFM_669", "AT_091", "AT_117", "AT_130", "BOT_059", "BOT_102t", "BOT_104", "BOT_107", "BOT_218", "BOT_218t", "BOT_237", "BOT_286", "BOT_286", "BOT_406", "BOT_413", "BRMA10_6", "BRMA13_4", "BRMA16_5", "BRMA17_9", "CS2_049", "AT_005", "GILA_600h2", "AT_005", "AT_005" };
            //deck avec 2 héros
            string[] packCard3 = { "AT_017", "AT_022", "AT_024", "AT_067", "AT_069", "AT_071", "CFM_669", "AT_091", "AT_117", "AT_130", "BOT_059", "BOT_102t", "BOT_104", "BOT_107", "BOT_218", "BOT_218t", "BOT_237", "BOT_286", "BOT_286", "BOT_406", "BOT_413", "BRMA10_6", "BRMA13_4", "BRMA16_5", "BRMA17_9", "CS2_049", "EX1_144", "GILA_600h2", "ICC_829", "AT_005" };
            //deck ne respectant pas la class du deck
            string[] packCard4 = { "AT_017", "AT_057", "AT_024", "AT_067", "AT_069", "AT_071", "CFM_669", "AT_091", "AT_117", "AT_130", "BOT_059", "BOT_102t", "BOT_104", "BOT_107", "BOT_218", "BOT_218t", "BOT_237", "BOT_286", "BOT_286", "BOT_406", "BOT_413", "BRMA10_6", "BRMA13_4", "BRMA16_5", "BRMA17_9", "CS2_049", "EX1_144", "GILA_600h2", "AT_005", "AT_005" };
            //respectant les règles
            string[] packCard5 = { "AT_017", "AT_022", "AT_024", "AT_067", "AT_069", "AT_071", "CFM_669", "AT_091", "AT_117", "AT_130", "BOT_059", "BOT_102t", "BOT_104", "BOT_107", "BOT_218", "BOT_218t", "BOT_237", "BOT_286", "BOT_286", "BOT_406", "BOT_413", "BRMA10_6", "BRMA13_4", "BRMA16_5", "BRMA17_9", "CS2_049", "EX1_144", "GILA_600h2", "AT_005", "AT_005" };

            if (deckShape == PresetDeckEnum.InvalidBadNumberCards)
            {
                deck = await getCardsByID(packCard1);
            }
            else if (deckShape == PresetDeckEnum.InvalidRepeatCard)
            {
                deck = await getCardsByID(packCard2);
            }
            else if (deckShape == PresetDeckEnum.InvalidOverHero)
            {
                deck = await getCardsByID(packCard3);
            }
            else if (deckShape == PresetDeckEnum.InvalidClassDeck)
            {
                deck = await getCardsByID(packCard4);
            }
            else if (deckShape == PresetDeckEnum.ValidDeck)
            {
                deck = await getCardsByID(packCard5);
            }
            else
            {
                deck = new List <Card>();
            }

            return(deck);
        }
コード例 #2
0
        public IActionResult Create(string author, string title, string presetDeckString, ClassType classType)
        {
            List <Card>      checkList;
            List <ClassType> classTypeNumber = new List <ClassType>();

            Console.WriteLine(presetDeckString);
            PresetDeckEnum presetDeck = (PresetDeckEnum)Enum.Parse(typeof(PresetDeckEnum), presetDeckString);

            if (ModelState.IsValid)
            {
                int     countHero              = 0;
                Boolean validDeckNumber        = true;
                Boolean validDeckHereoNumber   = true;
                Boolean validDeckCardDuplicate = true;
                Boolean validClassDeck         = true;
                Boolean validLegendaryNumber   = true;
                checkList = _ihelperApi.getPresetDeck(presetDeck).Result;

                //verifier les decks de 30 cartes
                if (checkList.Count != 30)
                {
                    validDeckNumber = false;
                }

                foreach (var item in checkList)
                {
                    //verifier max 1 hero
                    if (item.Type == CardType.HERO)
                    {
                        countHero++;
                    }
                    if (countHero >= 2)
                    {
                        validDeckHereoNumber = false;
                    }
                    //vérification de triplon
                    if (CountCard(item.Name, "name") > 2)
                    {
                        validDeckCardDuplicate = false;
                    }
                    //verifier bien 2 class type max
                    if (CountClassType(item.CardClass) == false)
                    {
                        validClassDeck = false;
                    }
                    //verification du nombre de legendaire
                    if (CountCard(item.Rarity.ToString(), "rarity") > 1)
                    {
                        validLegendaryNumber = false;
                    }
                }

                if (validDeckCardDuplicate == true && validDeckHereoNumber == true && validDeckNumber == true && validClassDeck == true && validLegendaryNumber == true)
                {
                    Deck deck = new Deck(title, author, classType);
                    deck.List = checkList;
                    _context.Add(deck);
                    _context.SaveChangesAsync();
                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    Console.WriteLine("validDeckCardDuplicate: " + validDeckCardDuplicate + ", validDeckHereoNumber: " + validDeckHereoNumber + "/" + countHero + ", validDeckNumber: " + validDeckNumber + "/" + checkList.Count + ", validClassDeck: " + validClassDeck + "/" + classTypeNumber.Count + ", validLegendaryNumber: " + validLegendaryNumber);
                    //renvoyer la liste des erreurs
                    var message = "validDeckCardDuplicate: " + validDeckCardDuplicate + ", validDeckHereoNumber: " + validDeckHereoNumber + "/" + countHero + ", validDeckNumber: " + validDeckNumber + "/" + checkList.Count + ", validClassDeck: " + validClassDeck + "/" + classTypeNumber.Count + ", validLegendaryNumber: " + validLegendaryNumber;
                    return(RedirectToAction(nameof(Create), new { message = message }));
                }
            }

            return(View());

            int CountCard(string name, string entity)
            {
                int count = 0;

                foreach (var item in checkList)
                {
                    if (entity == "name")
                    {
                        if (item.Name == name)
                        {
                            count++;
                        }
                    }
                    if (entity == "rarity")
                    {
                        if (item.Rarity == CardRarity.LEGENDARY)
                        {
                            count++;
                        }
                    }
                }
                return(count);
            }

            Boolean CountClassType(ClassType className)
            {
                if (!classTypeNumber.Contains(className))
                {
                    classTypeNumber.Add(className);
                }
                if (classTypeNumber.Count == 2 && !classTypeNumber.Contains(ClassType.Neutral))
                {
                    return(false);
                }
                if (classTypeNumber.Count <= 2)
                {
                    return(true);
                }

                return(false);
            }
        }