initial commit
This commit is contained in:
commit
65c137cec1
32 changed files with 420 additions and 0 deletions
58
MadLib/StoryGenerator.cs
Normal file
58
MadLib/StoryGenerator.cs
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
namespace MadLib;
|
||||
|
||||
public class StoryGenerator(StoryGenerator.Categories category)
|
||||
{
|
||||
public enum Categories
|
||||
{
|
||||
Adventure,
|
||||
Science,
|
||||
Fantasy,
|
||||
Horror,
|
||||
Mystery
|
||||
}
|
||||
|
||||
private StoryTemplate _template;
|
||||
|
||||
public static void DisplayCategories()
|
||||
{
|
||||
foreach (var category in Enum.GetValues<Categories>()) Console.WriteLine($"{(int)category + 1}) {category}");
|
||||
Console.WriteLine("\n");
|
||||
}
|
||||
|
||||
public void Generate()
|
||||
{
|
||||
var storyWords = GetWords();
|
||||
var story = _template.Text;
|
||||
|
||||
foreach (var placeholder in _template.Placeholders)
|
||||
story = story.Replace($"[{placeholder}]", storyWords[placeholder]);
|
||||
|
||||
DisplayStory(story);
|
||||
}
|
||||
|
||||
private Dictionary<string, string> GetWords()
|
||||
{
|
||||
if (!StoryTemplates.Templates.TryGetValue(category, out var template))
|
||||
throw new Exception("Could not find Story Template.");
|
||||
|
||||
_template = template;
|
||||
var words = new Dictionary<string, string>();
|
||||
|
||||
foreach (var placeholder in template.Placeholders)
|
||||
{
|
||||
Console.WriteLine($"Enter a {placeholder}: ");
|
||||
var input = Console.ReadLine() ?? string.Empty;
|
||||
words.Add(placeholder, input);
|
||||
}
|
||||
|
||||
return words;
|
||||
}
|
||||
|
||||
|
||||
private void DisplayStory(string story)
|
||||
{
|
||||
Console.WriteLine("====================================================\n");
|
||||
Console.WriteLine(story);
|
||||
Console.WriteLine("\n====================================================");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue