Added ChooseWord logic

This commit is contained in:
Jocelyn Hebert 2026-07-17 15:11:28 -03:00
commit 19a87dea6e
3 changed files with 23 additions and 3 deletions

View file

@ -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;
}
}

View file

@ -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; }

View file

@ -6,6 +6,9 @@ class Program
{
static void Main(string[] args)
{
AnsiConsole.MarkupLine($"[white on red]Enter your guess[/]");
while (PlayGame.Playing)
{
PlayGame();
}
}
}