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(); } }
public List <Advantage> GetAdvantages(AdvantageCategory aC) { if (advantageDict.TryGetValue(aC, out List <Advantage> advantageList)) { return(advantageList); } else { throw new KeyNotFoundException(); } }
public void AddAdvantage(AdvantageCategory aC, Advantage advantage) { try { advantageDict[aC].Add(advantage); } catch (KeyNotFoundException) { Console.WriteLine("Key not found"); } }
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); }