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

View file

@ -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<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)
{
@ -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

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)
{
//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<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;
}
SpectreGame game = new SpectreGame();
}
}

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