예제 #1
0
        private Advantage GetNewAdvantage(List <Advantage> a)
        {
            Array             enumValues        = Enum.GetValues(typeof(AdvantageCategory));
            AdvantageCategory advantageCategory = (AdvantageCategory)Enum.Parse(typeof(AdvantageCategory), rand.Next(enumValues.Length).ToString());

            try
            {
                List <Advantage> advantageList = advantages.GetAdvantages(advantageCategory);

                Advantage newAdvantage = advantageList[rand.Next(0, advantageList.Count)];

                int count = 0;
                while (a.Contains(newAdvantage))
                {
                    newAdvantage = advantageList[rand.Next(0, advantageList.Count)];
                    count++;

                    if (count == (advantages.Size * 10))
                    {
                        throw new NullReferenceException();
                    }
                }

                return(newAdvantage);
            }
            catch (KeyNotFoundException)
            {
                throw new KeyNotFoundException();
            }
        }
예제 #2
0
 public List <Advantage> GetAdvantages(AdvantageCategory aC)
 {
     if (advantageDict.TryGetValue(aC, out List <Advantage> advantageList))
     {
         return(advantageList);
     }
     else
     {
         throw new KeyNotFoundException();
     }
 }
예제 #3
0
 public void AddAdvantage(AdvantageCategory aC, Advantage advantage)
 {
     try
     {
         advantageDict[aC].Add(advantage);
     }
     catch (KeyNotFoundException)
     {
         Console.WriteLine("Key not found");
     }
 }
예제 #4
0
 public Advantage GetAdvantage(AdvantageCategory aC, int listPos)
 {
     if (advantageDict.TryGetValue(aC, out List <Advantage> advantageList))
     {
         return(advantageList[listPos]);
     }
     else
     {
         Console.WriteLine("Key not found");
     }
     return(null);
 }