public void CollectionGeneratorParams() { var generator = new ChoiceGenerator(1, 2, 3, 4); var random = new FuzzRandom(); var generatedValue = generator.Generate(Mock.Of <IFuzzProfile>(), typeof(int), random); Assert.That.IsType <int>(generatedValue); Assert.IsTrue((int)generatedValue < 5); Assert.IsTrue((int)generatedValue > 0); }
/// <summary>Runs the story until continuation point.</summary> /// <param name="story">The story.</param> /// <param name="parsedFiction"></param> /// <param name="options">The options.</param> /// <returns></returns> public virtual bool RunStoryUntilContinuationPoint(Runtime.IStory story, Parsed.IFiction parsedFiction, ConsoleUserInterfaceOptions options) { if (story == null) { return(false); } var choices = story.currentChoices; bool isAutoPlayActive = options != null ? options.IsAutoPlayActive : false; if (isAutoPlayActive) { // autoPlay: Pick random choice var choiceIndex = ChoiceGenerator.GetRandomChoice(choices.Count); ConsoleInteractor.ResetConsoleColor(); } else { // Normal: Ask user for choice number OutputManager.ShowChoices(choices, options); var uiResult = GetPropperUserInteractionResult(story, parsedFiction, options); ConsoleInteractor.ResetConsoleColor(); if (uiResult == null) { return(false); } else if (uiResult.IsInputStreamClosed) { return(false); } else if (uiResult.IsValidChoice) { story.ChooseChoiceIndex(uiResult.ChosenIndex); } else if (uiResult.DivertedPath != null) { story.ChoosePathString(uiResult.DivertedPath); uiResult.DivertedPath = null; } } EvaluateStory(story, options); return(true); }
public void LoadParentObjectsFile() { ChoiceGenerator = (HudCombo)view["ChoiceGenerator"]; ChoiceGenerator.Clear(); try { string assemblyFolder = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string filePath = System.IO.Path.Combine(assemblyFolder, "parentobjects.ini"); if (!File.Exists(filePath)) { File.Create(filePath).Close(); using (StreamWriter writer = new StreamWriter(filePath, false)) { // Monster Gens writer.WriteLine("28282 Linkable Monster Generator - 10 Secs"); writer.WriteLine("15274 Linkable Monster Generator - 1 Min"); writer.WriteLine("24129 Linkable Monster Generator - 2 Min"); writer.WriteLine("07923 Linkable Monster Generator - 3 Min"); writer.WriteLine("07932 Linkable Monster Generator - 4 Min"); writer.WriteLine("07924 Linkable Monster Generator - 5 Min"); writer.WriteLine("04219 Linkable Monster Generator - 7 Min"); writer.WriteLine("07925 Linkable Monster Generator - 10 Min"); writer.WriteLine("03955 Linkable Monster Generator - 15 Min"); writer.WriteLine("07926 Linkable Monster Generator - 20 Min"); // Item Gens writer.WriteLine("15759 Linkable Item Generator - 10 Secs"); writer.WriteLine("05085 Linkable Item Generator - 25 Secs"); writer.WriteLine("04142 Linkable Item Generator - 2 Min"); writer.Close(); } } string[] lines = File.ReadAllLines(filePath); foreach (string line in File.ReadAllLines(filePath)) { ChoiceGenerator.AddItem(line, line); } } catch (Exception ex) { Util.WriteToChat(ex.Message); } }
public static IEnumerable <T> Pick <T>(this IEnumerable <T> choices, int number) { var list = choices.ToList(); if (list.Count() < number) { throw new TheNumberOfElementsToPickMustBeSmallerThanTheNumberOfPossibleChoices(); } var newList = new List <T>(); number.Times( () => { var el = new ChoiceGenerator <T>(list.ToArray).GetRandomValue(); newList.Add(el); list.Remove(el); }); return(newList); }
public EmailGenerator(string[] firstnames, string[] lastnames, string[] domains) { firstnameGenerator = new ChoiceGenerator <string>(firstnames); lastnameGenerator = new ChoiceGenerator <string>(lastnames); domainGenerator = new ChoiceGenerator <string>(domains); }