diff --git a/Lingo/ChooseWord.cs b/Lingo/ChooseWord.cs index 1f09b1c..f2dc1cd 100644 --- a/Lingo/ChooseWord.cs +++ b/Lingo/ChooseWord.cs @@ -1,6 +1,20 @@ namespace Lingo; +using System.IO; +using System.Text.RegularExpressions; +using System.Linq; -public class ChooseWord +public static class ChooseWord { - + private static readonly Random rnd = new Random(); + + private static readonly string[] words = Regex.Split(File.ReadAllText("words.txt"), @"[^a-zA-Z]+") + .Where(s => !string.IsNullOrEmpty(s)) + .ToArray(); + + public static string GetRandomWord() + { + int wordChosenNumber = rnd.Next(0, words.Length); + string chosenWord = words[wordChosenNumber]; + return chosenWord; + } } \ No newline at end of file diff --git a/Lingo/PlayGame.cs b/Lingo/PlayGame.cs index 079b14f..4f24b7f 100644 --- a/Lingo/PlayGame.cs +++ b/Lingo/PlayGame.cs @@ -2,8 +2,11 @@ using System; using Spectre.Console; + public class PlayGame { + + public static bool Playing = true; public string CurrentAnswer { get; private set; } public string CurrentBoard { get; private set; } diff --git a/Lingo/Program.cs b/Lingo/Program.cs index 161265d..910be6c 100644 --- a/Lingo/Program.cs +++ b/Lingo/Program.cs @@ -6,6 +6,9 @@ class Program { static void Main(string[] args) { - AnsiConsole.MarkupLine($"[white on red]Enter your guess[/]"); + while (PlayGame.Playing) + { + PlayGame(); + } } } \ No newline at end of file