Ammended, added controller, started inserting logic. using Game.cs just for data.

This commit is contained in:
Jocelyn Hebert 2026-06-04 16:52:31 -03:00
commit eb8c36c2ae
6 changed files with 92 additions and 100 deletions

View file

@ -26,25 +26,11 @@ public class DisplayCharacters
} }
} }
private string colour; public string Colour { get; set; }
public string Colour public DisplayCharacters(char letter, 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()
{ {
Letter = letter;
Colour = colour;
} }
} }

View file

@ -7,48 +7,19 @@ namespace Lingo;
public class Game public class Game
{ {
//This should only be the data, not the logic. //This should only be the data, not the logic.
public int count = 0;
static Random rnd = new Random(); public int Rounds = 0;
public static int index = rnd.Next(1, Words.FiveLetterWords.Count);
public string solution = Words.FiveLetterWords[index];
public static bool exit = false; 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 DisplayCharacters[] displayArray;
private List<char> solutionList; private List<char> 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<string>("[red]Your word is not exactly 5 letters. Try again.[/]");
attemptCheck = attempt;
}
else
{
exit = true;
}
}
}
public void checking(string tries) public void checking(string tries)
{ {
@ -57,25 +28,16 @@ public class Game
if (tries[i] == solution[i]) if (tries[i] == solution[i])
{ {
//Green //Green
displayArray[i] = new DisplayCharacters(); displayArray[i] = new DisplayCharacters(tries[i], DisplayCharacters.green);
// 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])) else if (solution.Contains(tries[i]))
{ {
//Yellow //Yellow
displayArray[i].Colour = DisplayCharacters.yellow; displayArray[i].Colour = DisplayCharacters.yellow;
displayArray[i].Letter = tries[i]; displayArray[i].Letter = tries[i];
} }
else else
{ {
// black // black

40
Lingo/GameController.cs Normal file
View file

@ -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<string>("[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;
}
}
}
}

View file

@ -1,6 +0,0 @@
namespace Lingo;
public class Play
{
//Put the logic here, methods. Controlling the game loop.
}

View file

@ -6,32 +6,6 @@ class Program
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
//Make a view class instead of stuffing it here. SpectreGame game = new SpectreGame();
// 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<string>()
.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;
}
} }
} }

36
Lingo/SpectreGame.cs Normal file
View file

@ -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<string>()
.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;
}
}
}