Added ChooseWord logic
This commit is contained in:
parent
dfd0d82685
commit
19a87dea6e
3 changed files with 23 additions and 3 deletions
|
|
@ -1,6 +1,20 @@
|
||||||
namespace Lingo;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2,8 +2,11 @@
|
||||||
using System;
|
using System;
|
||||||
using Spectre.Console;
|
using Spectre.Console;
|
||||||
|
|
||||||
|
|
||||||
public class PlayGame
|
public class PlayGame
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public static bool Playing = true;
|
||||||
public string CurrentAnswer { get; private set; }
|
public string CurrentAnswer { get; private set; }
|
||||||
public string CurrentBoard { get; private set; }
|
public string CurrentBoard { get; private set; }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,9 @@ class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
AnsiConsole.MarkupLine($"[white on red]Enter your guess[/]");
|
while (PlayGame.Playing)
|
||||||
|
{
|
||||||
|
PlayGame();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue