Changes with notes.
This commit is contained in:
parent
487912116e
commit
83cdc58672
5 changed files with 92 additions and 64 deletions
24
Lingo/DisplayCharacters.cs
Normal file
24
Lingo/DisplayCharacters.cs
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
namespace Lingo;
|
||||||
|
|
||||||
|
public class DisplayCharacters
|
||||||
|
{
|
||||||
|
private char letter;
|
||||||
|
public char Letter {
|
||||||
|
get;
|
||||||
|
private set
|
||||||
|
{
|
||||||
|
// Capital A is 65, to 90, 97-122
|
||||||
|
if (((int)value >= 65 && (int)value <= 90) || ((int)value <= 122 && (int)value >= 97))
|
||||||
|
{
|
||||||
|
letter = value;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,23 +1,29 @@
|
||||||
using System.Reflection.Metadata.Ecma335;
|
using System.Reflection.Metadata.Ecma335;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using Spectre.Console;
|
using Spectre.Console;
|
||||||
|
|
||||||
namespace Lingo;
|
namespace Lingo;
|
||||||
|
|
||||||
public class Game
|
public class Game
|
||||||
{
|
{
|
||||||
private int count = 0;
|
//This should only be the data, not the logic.
|
||||||
|
public int count = 0;
|
||||||
static Random rnd = new Random();
|
static Random rnd = new Random();
|
||||||
private static int index = rnd.Next(1, Words.FiveLetterWords.Count);
|
public static int index = rnd.Next(1, Words.FiveLetterWords.Count);
|
||||||
private static string solution = Words.FiveLetterWords[index];
|
public string solution = Words.FiveLetterWords[index];
|
||||||
private static bool exit = false;
|
public static bool exit = false;
|
||||||
public void validateFiveLetters(string solutionCheck)
|
public string attempt;
|
||||||
|
private List<char> attemptList;
|
||||||
|
private List<char> solutionList;
|
||||||
|
|
||||||
|
public void ValidateFiveLetters(string solutionCheck)
|
||||||
{
|
{
|
||||||
exit = false;
|
exit = false;
|
||||||
while (exit == false)
|
while (exit == false)
|
||||||
{
|
{
|
||||||
if (solutionCheck.Length != 5)
|
if (solutionCheck.Length != 5)
|
||||||
{
|
{
|
||||||
index = rnd.Next(1, Words.FiveLetterWords.Count);
|
index = rnd.Next(0, Words.FiveLetterWords.Count);
|
||||||
solution = Words.FiveLetterWords[index];
|
solution = Words.FiveLetterWords[index];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -27,14 +33,15 @@ public class Game
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void validateFiveLettersAttempt(string attemptCheck)
|
public void ValidateFiveLettersAttempt(string attemptCheck)
|
||||||
{
|
{
|
||||||
exit = false;
|
exit = false;
|
||||||
while (exit == false)
|
while (exit == false)
|
||||||
{
|
{
|
||||||
if (attemptCheck.Length != 5)
|
if (attemptCheck.Length != 5)
|
||||||
{
|
{
|
||||||
attempt = AnsiConsole.Ask<string>("Your word is not exactly 5 letters. Try again.");
|
attempt = AnsiConsole.Ask<string>("[red]Your word is not exactly 5 letters. Try again.[/]");
|
||||||
|
attemptCheck = attempt;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -43,31 +50,39 @@ public class Game
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string attempt = AnsiConsole.Ask<string>("What is your [green]name[/]?");
|
|
||||||
private List<char> attemptList;
|
|
||||||
private List<char> solutionList;
|
|
||||||
|
|
||||||
private void createCharList(string solution)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void checking (string tries)
|
||||||
{
|
{
|
||||||
foreach (char c in solution)
|
for (int i = 0; i < tries.Length; i++)
|
||||||
{
|
{
|
||||||
solutionList.Add(c);
|
if (tries[i] == solution[i])
|
||||||
|
{
|
||||||
|
//Green
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (solution.Contains(tries[i]))
|
||||||
|
{
|
||||||
|
//Yellow
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// black
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createAttemptCharList(string attempt)
|
public void askForInput()
|
||||||
{
|
{
|
||||||
foreach (char c in attempt)
|
attempt = AnsiConsole.Ask<string>("Enter a 5-letter word");
|
||||||
{
|
|
||||||
attemptList.Add(c);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Game()
|
public Game()
|
||||||
{
|
{
|
||||||
validateFiveLetters(solution);
|
|
||||||
validateFiveLettersAttempt(attempt);
|
|
||||||
createCharList(solution);
|
|
||||||
createAttemptCharList(attempt);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2,10 +2,5 @@ namespace Lingo;
|
||||||
|
|
||||||
public class Play
|
public class Play
|
||||||
{
|
{
|
||||||
public Play()
|
//Put the logic here, methods. Controlling the game loop.
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public int I { get; private set; }
|
|
||||||
}
|
}
|
||||||
|
|
@ -5,40 +5,33 @@ using Spectre.Console;
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{ //Make a view class instead of stuffing it here.
|
||||||
try
|
// Game controller could have the game loop? try this.
|
||||||
{
|
// Also an input controller, instead of putting it in view or others.
|
||||||
bool isRunning = true;
|
bool isRunning = true;
|
||||||
|
|
||||||
do
|
|
||||||
|
AnsiConsole.Clear();
|
||||||
|
|
||||||
|
string userSelection = AnsiConsole.Prompt(
|
||||||
|
new SelectionPrompt<string>()
|
||||||
|
.Title("Choose play or quit ")
|
||||||
|
.AddChoices
|
||||||
|
(
|
||||||
|
"1. Play Lingo",
|
||||||
|
"2. Quit"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
switch (userSelection)
|
||||||
{
|
{
|
||||||
AnsiConsole.Clear();
|
case "1. Play Lingo":
|
||||||
|
Game game = new Game();
|
||||||
|
|
||||||
string userSelection = AnsiConsole.Prompt(
|
break;
|
||||||
new SelectionPrompt<string>()
|
case "2. Quit":
|
||||||
.Title("Choose play or quit ")
|
|
||||||
.AddChoices
|
break;
|
||||||
(
|
}
|
||||||
"1. Play Lingo",
|
|
||||||
"2. Quit"
|
|
||||||
)
|
|
||||||
);
|
|
||||||
switch (userSelection)
|
|
||||||
{
|
|
||||||
case "1. Play Lingo":
|
|
||||||
Game attempt = new Game();
|
|
||||||
|
|
||||||
break;
|
|
||||||
case "2. Quit":
|
|
||||||
isRunning = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} while (isRunning);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
AnsiConsole.MarkupLine($"[red]Error:[/] {ex.Message}");
|
|
||||||
Console.ReadLine();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2,7 +2,8 @@ namespace Lingo;
|
||||||
|
|
||||||
public static class Words
|
public static class Words
|
||||||
{
|
{
|
||||||
public static readonly List<string> FiveLetterWords = new List<string>
|
//Readonly collection? Interface
|
||||||
|
public static List<string> FiveLetterWords = new List<string>
|
||||||
{
|
{
|
||||||
"joust", "swamp", "glint", "prawn", "chide", "stomp", "fleck", "groan",
|
"joust", "swamp", "glint", "prawn", "chide", "stomp", "fleck", "groan",
|
||||||
"birch", "thrum", "slunk", "brave", "chops", "twirl", "plank", "snore", "draft", "gloom", "wharf", "spunk",
|
"birch", "thrum", "slunk", "brave", "chops", "twirl", "plank", "snore", "draft", "gloom", "wharf", "spunk",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue