Skip to content
Snippets Groups Projects
Commit 9ceca470 authored by Seilenthal's avatar Seilenthal
Browse files

Adding Menus

parent 329b5af4
No related branches found
No related tags found
No related merge requests found
......@@ -26,6 +26,7 @@ namespace Controller
Console.WriteLine("Difficulty: \t[E]asy \nDescription: \tRecommended for beginners.\n");
Console.WriteLine("Difficulty: \t[M]edium \nDescription: \tRecommended for advanced users.\n");
Console.WriteLine("Difficulty: \t[H]ard \nDescription: \tRecommended for those who are looking for a challenge.\n");
Console.WriteLine("Press \"R\" to return to the main menu. \n");
bool checkMenu = false;
do
......@@ -44,8 +45,11 @@ namespace Controller
difficulty = "hard";
checkMenu = true;
break;
case "r":
Program.MainMenu();
return;
default:
Console.WriteLine("Something went wrong! Try again. Only the letters \"E\", \"M\", \"H\" are allowed. ");
Console.WriteLine("Something went wrong! Try again. Only the letters \"E\", \"M\", \"H\". \"R\" are allowed. ");
break;
}
......@@ -55,7 +59,9 @@ namespace Controller
Console.WriteLine($"Game starts with the difficulty: {difficulty}");
game = new MastermindGame(difficulty);
int generatedCodeLength = game.GetCodeLength();
while (game.StillHasTrials())
bool breaker = false;
while (game.StillHasTrials() && !breaker)
{
// User input Code
int[] userInput = ReadInput(generatedCodeLength);
......@@ -69,7 +75,33 @@ namespace Controller
game.AddAttempt(userInput);
game.DisplayBoard();
Console.WriteLine("Hier ist gerade Ende. Ich bin ein Star holt mich hier raus (Zitat Fabian)!");
if (game.CheckWin(userInput))
{
Console.WriteLine("Congratulations! You have guessed the code.");
breaker = true;
}
}
if (!breaker)
{
Console.WriteLine("You have used all of your attempts. Next time you will win!");
}
Console.Clear();
Console.WriteLine("==========================");
Console.WriteLine("Do you want to play again?");
Console.WriteLine("[Y]es or [N]o");
Console.WriteLine("==========================");
switch(Console.ReadLine().ToLower())
{
case "Y":
Console.WriteLine("A new game is starting...");
Play();
return;
case "N":
Console.WriteLine("Returning to main menu");
Program.MainMenu();
return;
}
}
......
using System;
using PseudoRandomGenerator;
public enum Hints
{
None,
Yellow,
Green
}
namespace Mastermind
{
......@@ -15,7 +21,7 @@ namespace Mastermind
private readonly int maxAttempt;
private int currentAttempt;
private int[][] attempts; // Jagged array (array of arrays) to save attempts
private (int guess, string hint)[,] feedback;
private (int guess, Hints hint)[,] feedback;
/// <summary>
/// Initializes a new game with the specified difficulty level
......@@ -48,7 +54,7 @@ namespace Mastermind
}
attempts = new int[maxAttempt][];
feedback = new (int, string)[code_length, 1];
feedback = new (int, Hints)[code_length, 1];
// Initializes each inner array to avoid null reference later
for (int i = 0; i < maxAttempt; i++)
......@@ -123,7 +129,7 @@ namespace Mastermind
// Checks if the number is in the right place
if(i == code[counter])
{
feedback[counter, 0] = (i, "green");
feedback[counter, 0] = (i, Hints.Green);
counter++;
check = true;
......@@ -135,7 +141,7 @@ namespace Mastermind
{
if(i == j)
{
feedback[counter, 0] = (i, "yellow");
feedback[counter, 0] = (i, Hints.Yellow);
counter++;
}
}
......@@ -143,7 +149,7 @@ namespace Mastermind
// Number is not present in the code
else
{
feedback[counter, 0] = (i, "none");
feedback[counter, 0] = (i, Hints.None);
counter++;
}
}
......@@ -151,7 +157,7 @@ namespace Mastermind
// Sets numbers to -1 if hint is not green or yellow
for(int i = 0; i < feedback.GetLength(0); i++)
{
if (feedback[i, 0].hint != "green" && feedback[i, 0].hint != "yellow")
if (feedback[i, 0].hint != Hints.Green && feedback[i, 0].hint != Hints.Yellow)
{
feedback[i, 0].guess = -1;
}
......@@ -205,13 +211,13 @@ namespace Mastermind
for (int i = 0; i < feedback.GetLength(0); i++)
{
if (feedback[i, 0].hint == "green")
if (feedback[i, 0].hint == Hints.Green)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("X ");
Console.ForegroundColor = ConsoleColor.Gray;
}
else if (feedback[i, 0].hint == "yellow")
else if (feedback[i, 0].hint == Hints.Yellow)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write("Y ");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment