/// <summary> /// Randomly separate half of the Avengers from the other and return the entire list /// </summary> /// <returns></returns> public Dictionary <string, bool> BalanceTheTeam() { int half = (int)Math.Ceiling((double)this.NumberOfTeammates / (double)2); List <int> indices = new List <int>(); Random random = new Random(); // Instantiate one time, outside of the loop; otherwise you'll get the same sequence each time due to the system clock while (indices.Count < half) { int i = GenerateRandomIndex(random); if (!indices.Contains(i)) { indices.Add(i); } } Dictionary <string, bool> results = new Dictionary <string, bool>(); for (int i = 0; i < this.NumberOfTeammates; i++) { Avenger avenger = this.Teammates[i]; bool includedInHalf = indices.Contains(i); results.Add(avenger.Name, includedInHalf); } return(results); }
/// <summary> /// Load the initial data for Thanos /// </summary> /// <returns></returns> public Team BootstrapThanos() { const string thanosTeamName = "Thanos"; Avenger thanos = new Avenger(thanosTeamName, 200, thanosTeamName); Team thanosTeam = new Team(thanosTeamName); thanosTeam.Teammates.Add(thanos); return(thanosTeam); }
/// <summary> /// Allow the user to add their own Avenger, and possibly create a new team /// </summary> /// <param name="avengers"></param> /// <param name="input"></param> static void AddCustomAvengers(ref List <Avenger> avengers, Input input) { bool addAvenger = input.AskAddAvenger(); while (addAvenger) { List <string> existingAvengerNames = avengers.Select(a => a.Name).OrderBy(n => n).ToList(); string name = input.AskAvengerName(existingAvengerNames); int powerLevel = input.AskAvengerPowerLevel(); string team = input.AskAvengerTeam(); Avenger avenger = new Avenger(name, powerLevel, team); avengers.Add(avenger); addAvenger = input.AskAddAvenger(); } }
/// <summary> /// Randomly select combatants from the list of Avengers on the team /// </summary> /// <param name="total">The total number of combatants to select on the team</param> /// <returns></returns> public List <Avenger> SelectCombatants(int total) { List <Avenger> combatants = new List <Avenger>(); Random random = new Random(); // Instantiate one time, outside of the loop; otherwise you'll get the same sequence each time due to the system clock while (combatants.Count < total && combatants.Count < this.NumberOfTeammates) { int i = GenerateRandomIndex(random); Avenger avenger = this.Teammates[i]; if (!combatants.Exists(c => c.Name == avenger.Name)) { combatants.Add(avenger); } } return(combatants); }