From 6d95041b83c553ccf10771e67b441da87ff8e7a4 Mon Sep 17 00:00:00 2001 From: Jocelyn Hebert Date: Wed, 3 Jun 2026 19:22:05 -0300 Subject: [PATCH] Need to decide where the game loop will be, make controller, etc. --- Lingo/DisplayCharacters.cs | 36 +++++++++++++++++++++++++++++----- Lingo/Game.cs | 27 ++++++++++++++++--------- Lingo/Program.cs | 40 +++++++++++++++++++------------------- 3 files changed, 69 insertions(+), 34 deletions(-) diff --git a/Lingo/DisplayCharacters.cs b/Lingo/DisplayCharacters.cs index 894b5a2..56f038f 100644 --- a/Lingo/DisplayCharacters.cs +++ b/Lingo/DisplayCharacters.cs @@ -2,10 +2,17 @@ public class DisplayCharacters { + public static readonly string green = "green"; + public static readonly string yellow = "yellow"; + public static readonly string black = "black"; + + private char letter; - public char Letter { - get; - private set + + public char Letter + { + get { return letter; } + set { // Capital A is 65, to 90, 97-122 if (((int)value >= 65 && (int)value <= 90) || ((int)value <= 122 && (int)value >= 97)) @@ -14,11 +21,30 @@ public class DisplayCharacters } else { - + throw new ArgumentException("Not a valid letter"); } - } } + private string colour; + 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() + { + } } \ No newline at end of file diff --git a/Lingo/Game.cs b/Lingo/Game.cs index 0a813d9..6c46cb3 100644 --- a/Lingo/Game.cs +++ b/Lingo/Game.cs @@ -13,7 +13,7 @@ public class Game public string solution = Words.FiveLetterWords[index]; public static bool exit = false; public string attempt; - private List attemptList; + private DisplayCharacters[] displayArray; private List solutionList; public void ValidateFiveLetters(string solutionCheck) @@ -50,28 +50,37 @@ public class Game } } - - - - - - public void checking (string tries) + public void checking(string tries) { for (int i = 0; i < tries.Length; i++) { 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]; } else if (solution.Contains(tries[i])) { //Yellow + displayArray[i].Colour = DisplayCharacters.yellow; + displayArray[i].Letter = tries[i]; } else { // black - + displayArray[i].Colour = DisplayCharacters.black; + displayArray[i].Letter = tries[i]; } } } @@ -83,6 +92,6 @@ public class Game public Game() { - + displayArray = new DisplayCharacters[5]; } } \ No newline at end of file diff --git a/Lingo/Program.cs b/Lingo/Program.cs index 56485ae..30c1ae9 100644 --- a/Lingo/Program.cs +++ b/Lingo/Program.cs @@ -5,33 +5,33 @@ using Spectre.Console; class Program { static void Main(string[] args) - { //Make a view class instead of stuffing it here. + { + //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(); + 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(); + 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; - } + break; + case "2. Quit": + break; + } } } \ No newline at end of file