From 19a87dea6e3466f900837dd6767f55ca7fa03861 Mon Sep 17 00:00:00 2001 From: Jocelyn Hebert Date: Fri, 17 Jul 2026 15:11:28 -0300 Subject: [PATCH] Added ChooseWord logic --- Lingo/ChooseWord.cs | 18 ++++++++++++++++-- Lingo/PlayGame.cs | 3 +++ Lingo/Program.cs | 5 ++++- 3 files changed, 23 insertions(+), 3 deletions(-) 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