diff --git a/Lingo/DisplayCharacters.cs b/Lingo/DisplayCharacters.cs index 56f038f..543e610 100644 --- a/Lingo/DisplayCharacters.cs +++ b/Lingo/DisplayCharacters.cs @@ -26,25 +26,11 @@ public class DisplayCharacters } } - private string colour; + public string Colour { get; set; } - public string Colour - { - get { return colour; } - set - { - if (value.ToLower() == "green" || value.ToLower() == "yellow" || value.ToLower() == "black") - { - colour = value; - } - else - { - throw new ArgumentException("Not a valid colour, needs to be green, black, or yellow"); - } - } - } - - public DisplayCharacters() + public DisplayCharacters(char letter, string colour) { + Letter = letter; + Colour = colour; } } \ No newline at end of file diff --git a/Lingo/Game.cs b/Lingo/Game.cs index 6c46cb3..a918305 100644 --- a/Lingo/Game.cs +++ b/Lingo/Game.cs @@ -7,48 +7,19 @@ namespace Lingo; public class Game { //This should only be the data, not the logic. - public int count = 0; - static Random rnd = new Random(); - public static int index = rnd.Next(1, Words.FiveLetterWords.Count); - public string solution = Words.FiveLetterWords[index]; + + public int Rounds = 0; public static bool exit = false; - public string attempt; + public static Random rnd = new Random(); + public static int index = rnd.Next(1, Words.FiveLetterWords.Count); + public static string solution = Words.FiveLetterWords[index]; + public static string attempt; private DisplayCharacters[] displayArray; private List solutionList; - public void ValidateFiveLetters(string solutionCheck) - { - exit = false; - while (exit == false) - { - if (solutionCheck.Length != 5) - { - index = rnd.Next(0, Words.FiveLetterWords.Count); - solution = Words.FiveLetterWords[index]; - } - else - { - exit = true; - } - } - } - public void ValidateFiveLettersAttempt(string attemptCheck) - { - exit = false; - while (exit == false) - { - if (attemptCheck.Length != 5) - { - attempt = AnsiConsole.Ask("[red]Your word is not exactly 5 letters. Try again.[/]"); - attemptCheck = attempt; - } - else - { - exit = true; - } - } - } + + public void checking(string tries) { @@ -57,25 +28,16 @@ public class Game if (tries[i] == solution[i]) { //Green - displayArray[i] = new DisplayCharacters(); - - // try - // { - // displayArray[i].Colour = "blue"; - // } - // catch (ArgumentException e) - // { - // displayArray[i].Colour = "green"; - // } - displayArray[i].Colour = DisplayCharacters.green; - displayArray[i].Letter = tries[i]; + displayArray[i] = new DisplayCharacters(tries[i], DisplayCharacters.green); } + else if (solution.Contains(tries[i])) { //Yellow displayArray[i].Colour = DisplayCharacters.yellow; displayArray[i].Letter = tries[i]; } + else { // black diff --git a/Lingo/GameController.cs b/Lingo/GameController.cs new file mode 100644 index 0000000..809683a --- /dev/null +++ b/Lingo/GameController.cs @@ -0,0 +1,40 @@ +namespace Lingo; +using Spectre.Console; + + +public class GameController +{ + public void ValidateFiveLettersAttempt(string attemptCheck) + { + Game.exit = false; + while (Game.exit == false) + { + if (attemptCheck.Length != 5) + { + Game.attempt = AnsiConsole.Ask("[red]Your word is not exactly 5 letters. Try again.[/]"); + attemptCheck = Game.attempt; + } + else + { + Game.exit = true; + } + } + } + + public void ValidateFiveLetters(string solutionCheck) + { + Game.exit = false; + while (Game.exit == false) + { + if (solutionCheck.Length != 5) + { + Game.index = Game.rnd.Next(0, Words.FiveLetterWords.Count); + Game.solution = Words.FiveLetterWords[Game.index]; + } + else + { + Game.exit = true; + } + } + } +} \ No newline at end of file diff --git a/Lingo/Play.cs b/Lingo/Play.cs deleted file mode 100644 index 021eb87..0000000 --- a/Lingo/Play.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Lingo; - -public class Play -{ - //Put the logic here, methods. Controlling the game loop. -} \ No newline at end of file diff --git a/Lingo/Program.cs b/Lingo/Program.cs index 30c1ae9..2776c60 100644 --- a/Lingo/Program.cs +++ b/Lingo/Program.cs @@ -6,32 +6,6 @@ class Program { static void Main(string[] args) { - //Make a view class instead of stuffing it here. - // Game controller could have the game loop? try this. - // Also an input controller, instead of putting it in view or others. - bool isRunning = true; - - - AnsiConsole.Clear(); - - string userSelection = AnsiConsole.Prompt( - new SelectionPrompt() - .Title("Choose play or quit ") - .AddChoices - ( - "1. Play Lingo", - "2. Quit" - ) - ); - switch (userSelection) - { - case "1. Play Lingo": - Game game = new Game(); - - break; - case "2. Quit": - - break; - } + SpectreGame game = new SpectreGame(); } } \ No newline at end of file diff --git a/Lingo/SpectreGame.cs b/Lingo/SpectreGame.cs new file mode 100644 index 0000000..5cc6d43 --- /dev/null +++ b/Lingo/SpectreGame.cs @@ -0,0 +1,36 @@ +namespace Lingo; + +using Spectre.Console; + +public class SpectreGame +{ + //Make a view class instead of stuffing it here. + // Game controller could have the game loop? try this. + // Also an input controller, instead of putting it in view or others. + + public SpectreGame() + { + bool isRunning = true; + AnsiConsole.Clear(); + + string userSelection = AnsiConsole.Prompt( + new SelectionPrompt() + .Title("Choose play or quit ") + .AddChoices + ( + "1. Play Lingo", + "2. Quit" + ) + ); + switch (userSelection) + { + case "1. Play Lingo": + Game game = new Game(); + + break; + case "2. Quit": + isRunning = false; + break; + } + } +} \ No newline at end of file