private void SelectKiller() { KillerNonPlayableCharacter killer = new KillerNonPlayableCharacter(_characters.RollAndRemove()); _killer = killer; _characters.Add(killer); }
/// <summary> /// RollList generates random list of elements from a pre-existing list. /// </summary> /// <example> /// ["A","B","C","D"].RollList(2) -> ["A","D"] /// </example> /// <returns>The list.</returns> /// <param name="size">Size.</param> public RandomList <T> RollList(int size) { if (size > this.Count) { Exception e = new Exception("Cannot generate random list of size :" + size + " from original list of size: " + this.Count); Console.Write(e); throw e; } else { // List That Will Have Elements Removed From To Prevent Duplicate Rolls RandomList <T> throwableList = (RandomList <T>) this.Clone(); // List That Will Contain Random Elements and Be Returned RandomList <T> generatedList = new RandomList <T>(); // Generate Member In Generated List (of size n) by // Rolling on Throwable, adding to Generated and removing from // Throwable to mitigate any duplicate elements. for (int i = 0; (i < size - 1); i++) { T element = throwableList.Roll(); generatedList.Add(element); throwableList.Remove(element); } return(generatedList); } }
//function for initializing the case public GameManager() { //Decide which ID number the killer will have. Random WhoDunIt = new Random(); KillerID = WhoDunIt.Next(0, 10); for (int s = 0; s < 10; s++) { //Generate the ten suspects, assign their IDs, and put them in storage. Suspect latestSuspect = new Suspect { ID = s }; SuspectObjectList.Add(latestSuspect); } for (int h = 0; h < 10; h++) { //Generate hints based on what kind of suspect we generated in the previous loop //There's probably a way to do this more efficiently switch (SuspectObjectList[h].ID == KillerID) { case true: SuspectObjectList[h].Hint = SuspectObjectList[KillerID]._Traits[WhoDunIt.Next(2)].TraitHints.Roll(); SuspectObjectList[h].Sanity -= WhoDunIt.Next(50); break; default: SuspectObjectList[h].Hint = SuspectObjectList[KillerID]._Traits[WhoDunIt.Next(2)].TraitHints.Roll(); SuspectObjectList[h].Sanity -= WhoDunIt.Next(50); break; } } for (int p = 0; p < 10; p++) { Console.WriteLine("#" + SuspectObjectList[p].ID + ": " + SuspectObjectList[p].Name); Console.WriteLine("\"" + SuspectObjectList[p].Hint + "\""); Console.WriteLine(SuspectObjectList[p].Examine[0]); Console.WriteLine(SuspectObjectList[p].Examine[1]); Console.WriteLine("They're " + SuspectObjectList[p].Age + " years old."); Console.WriteLine("Their sanity is at " + SuspectObjectList[p].Sanity + "%."); } }