/// <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); } }
private NonPlayableCharacter KillCharacter(int leftCharacterIndex, int rightCharacterIndex, RandomList <NonPlayableCharacter> characters) { // Finding Characters That It Can Kill (Left and Right) NonPlayableCharacter leftCharacter = characters[leftCharacterIndex]; NonPlayableCharacter rightCharacter = characters[rightCharacterIndex]; // Making List with Two Potential Characters RandomList <NonPlayableCharacter> possibleKillableCharacters = new RandomList <NonPlayableCharacter> { leftCharacter, rightCharacter }; // Generating Character That Dies NonPlayableCharacter killedCharacter = possibleKillableCharacters.Roll(); // Killing Character characters.Remove(killedCharacter); // Returning Character (To Use For Printing) return(killedCharacter); }
/// <summary> /// Generates names /// </summary> /// <returns>A name</returns> public String NameGenerator() { RandomList <String> prefixes = new RandomList <String> { "lo", "te", "soa", "co" }; RandomList <String> suffixes = new RandomList <String> { "l", "as", "ud" }; return(prefixes.Roll() + suffixes.Roll()); }
/// <summary> /// Generates names /// </summary> /// <returns>A name</returns> public String NameGenerator() { RandomList <String> prefixes = new RandomList <String> { "Sha", "Telo", "Sap", "Ca" }; RandomList <String> suffixes = new RandomList <String> { "lleot", "as", "ud" }; return(prefixes.Roll() + suffixes.Roll()); }
/// <summary> /// Generates names /// </summary> /// <returns>A name</returns> public String NameGenerator() { return(prefixes.Roll() + suffixes.Roll()); }