Skip to content
Snippets Groups Projects
Commit 437a85f6 authored by muellerfa100445's avatar muellerfa100445
Browse files

Tutorial V2: Electric Boogaloo

parent ad30d032
No related branches found
No related tags found
No related merge requests found
......@@ -54,11 +54,11 @@ namespace Controller
// Starts Game
Console.WriteLine($"Game starts with the difficulty: {difficulty}");
game = new MastermindGame(difficulty);
int generatedCodeLength = game.GetCodeLength();
while (game.StillHasTrials())
{
// User input Code
int[] userInput = ReadInput();
int[] userInput = ReadInput(generatedCodeLength);
// Debugging (Gets removed later)
foreach (int i in userInput)
......@@ -72,9 +72,8 @@ namespace Controller
}
}
private int[] ReadInput()
public int[] ReadInput(int generatedCodeLength)
{
int generatedCodeLength = game.GetCodeLength();
int[] input = new int[generatedCodeLength];
string inputString;
string[] parts; // The code of the user
......@@ -104,7 +103,8 @@ namespace Controller
{
// Prevent incorrect codes caused by a space character
Console.WriteLine("Please don't start and end with \" \" and also don't double it!");
} else
}
else
{
Console.WriteLine($"Error! Please change {i} to a number between 0 and 9");
}
......
using System;
using Controller;
using Mastermind;
namespace Program
namespace Mastermind
{
class Program
{
static void Main()
{
{
MainMenu();
while (true)
{
Console.WriteLine("\n███╗ ███╗ █████╗ ███████╗████████╗███████╗██████╗ ███╗ ███╗██╗███╗ ██╗██████╗");
Console.WriteLine("████╗ ████║██╔══██╗██╔════╝╚══██╔══╝██╔════╝██╔══██╗████╗ ████║██║████╗ ██║██╔══██╗");
Console.WriteLine("██╔████╔██║███████║███████╗ ██║ █████╗ ██████╔╝██╔████╔██║██║██╔██╗ ██║██║ ██║");
Console.WriteLine("██║╚██╔╝██║██╔══██║╚════██║ ██║ ██╔══╝ ██╔══██╗██║╚██╔╝██║██║██║╚██╗██║██║ ██║");
Console.WriteLine("██║ ╚═╝ ██║██║ ██║███████║ ██║ ███████╗██║ ██║██║ ╚═╝ ██║██║██║ ╚████║██████╔╝");
Console.WriteLine("╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝ ╚═╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝╚═╝ ╚═══╝╚═════╝");
Console.WriteLine("\nBitte wählen Sie aus:");
Console.WriteLine("[S]tart Game");
Console.WriteLine("[T]utorial");
Console.WriteLine("[Q]uit");
bool checkMenu = false;
do
string? input = Console.ReadLine(); //string? allows for null-value
if (input != null) //"filter out" null values to avoid crash
{
switch (Console.ReadLine().ToLower())
switch (input.ToLower())
{
case "s":
Console.WriteLine("Starting Game ...");
MastermindController controller = new MastermindController();
MastermindController controller = new();
controller.Play();
checkMenu = true;
break;
case "t":
Tutorial tutorial = new Tutorial();
tutorial.TutorialGame();
checkMenu = true;
MasterMindTutorial.Tutorial();
break;
case "q":
Environment.Exit(0);
break;
return;
default:
Console.WriteLine("Please pick a valid Option.");
break;
}
}
while (checkMenu == false);
else
{
Console.WriteLine("Please pick a valid Option.");
}
}
}
}
public static void MainMenu()
{
Console.WriteLine("\n███╗ ███╗ █████╗ ███████╗████████╗███████╗██████╗ ███╗ ███╗██╗███╗ ██╗██████╗");
Console.WriteLine("████╗ ████║██╔══██╗██╔════╝╚══██╔══╝██╔════╝██╔══██╗████╗ ████║██║████╗ ██║██╔══██╗");
Console.WriteLine("██╔████╔██║███████║███████╗ ██║ █████╗ ██████╔╝██╔████╔██║██║██╔██╗ ██║██║ ██║");
Console.WriteLine("██║╚██╔╝██║██╔══██║╚════██║ ██║ ██╔══╝ ██╔══██╗██║╚██╔╝██║██║██║╚██╗██║██║ ██║");
Console.WriteLine("██║ ╚═╝ ██║██║ ██║███████║ ██║ ███████╗██║ ██║██║ ╚═╝ ██║██║██║ ╚████║██████╔╝");
Console.WriteLine("╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝ ╚═╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝╚═╝ ╚═══╝╚═════╝");
Console.WriteLine("\nPlease Choose:");
Console.WriteLine("[S]tart Game");
Console.WriteLine("[T]utorial");
Console.WriteLine("[Q]uit");
}
}
}
\ No newline at end of file
using System;
using Controller;
using System;
namespace Mastermind
{
public class Tutorial
public class MasterMindTutorial
{
public void TutorialGame()
public static void Tutorial()
{
{
{
TutorialMenu();
while (true)
{
string? input = Console.ReadLine(); //string? allows for null-value
if (input != null) //"filter out" null values to avoid crash
{
switch (input.ToLower())
{
case "e":
Console.Clear();
int[] tutorialCode = [2, 3, 5, 8];
int[] tutorialGuess = [0, 1, 2, 3];
Console.WriteLine("The goal of this game is to crack the (randomly) generated Code of which the Length will the determined by the chosen difficulty.\nIn this tutorial the Code will have a length of 4.\n Start by guessing 4 different Numbers with the Range 0 - 9 (0 and 9 are included).");
foreach (int n in tutorialGuess) //fill array that saves guesses of the user
Console.WriteLine("In this game a secret code consisting of numbers (0-9) is generated\nwhich the player attempts to decipher the code through repeated guesses.");
Console.WriteLine("After each guess, feedback is provided: the number of digits in the correct position (green)\nand the number of digits that are part of the code but in the wrong position (yellow).");
Console.WriteLine("The goal is to crack the code in as few attempts as possible.\nThe game ends when the code is correctly guessed or the maximum number of attempts is reached.");
Console.WriteLine("This Game offers three diffculties which influence the following:");
Console.WriteLine("\neasy\nCode Length: 4\nNo duplicate numbers\nAttempts: 6");
Console.WriteLine("\nmedium\nCode Length: 6\nNo duplicate numbers\nAttempts: 4");
Console.WriteLine("\nhard\nCode Length: 8\nDuplicate Numbers possible\nAttempts: 3");
Console.Write("\nPlease press any key in order to go back");
Console.ReadKey();
Console.Clear();
TutorialMenu();
break;
case "t":
Console.WriteLine("In this Tutorial Game you will have unlimited tries. Also the Code won't change.");
TutorialGame();
Console.Clear();
Program.MainMenu();
return;
case "b":
Console.Clear();
Program.MainMenu();
return;
default:
Console.WriteLine("Please pick a valid Option.");
break;
}
}
else
{
int input = 0; //used for user input
bool ret_1 = false;
Console.WriteLine("Please pick a valid Option.");
}
}
}
}
static void TutorialGame()
{
int[] tutorialCode = [2, 3, 5, 8];
int correctGuesses; //used to count how many guesses are correct number in correct position
int cNumberfPos; //used to count how many gueeses are correct number in wrong position
int indexCounter; //used to cycle through the array tutorialCode to check for correct position
do
{
ret_1 = int.TryParse(Console.ReadLine(), out input); //check if user input a number
if (ret_1 == false || input.ToString().Length != 1) //check if user input is a number and if it is a single digit
MastermindController controller = new();
int[] tutorialGuess = controller.ReadInput(tutorialCode.Length); //allow user to input their Guess and write them in the array tutorialGuess
correctGuesses = 0;
cNumberfPos = 0;
indexCounter = 0;
foreach (int n in tutorialGuess) //loop through each variable in the array tutorialGuess
{
Console.WriteLine("Please write a single number between 0 and 9."); //if user didn't input Number --> display message to guide User
bool checker = false;
if (n == tutorialCode[indexCounter]) //check if user guess has correct number in corresponding position
{
correctGuesses++;
indexCounter++;
checker = true;
}
else if (checker == false)
{
foreach (int m in tutorialCode) //check if user guess exists in code, if yes --> right number, wrong position
{
if (n == m)
{
cNumberfPos++;
indexCounter++;
}
}
while (ret_1 == false); //repeat if user didn't input a Number
//when user did input a Number --> write in array that saves user input
tutorialGuess[n] = input;
}
Console.WriteLine($"{tutorialGuess[0]}, {tutorialGuess[1]}, {tutorialGuess[2]}, {tutorialGuess[3]}");//Diese Meldung wird später noch herausgenommen.
Console.WriteLine("Press Q to quit.");//Diese Meldung wird später noch herausgenommen.
else //wrong number in wrong position
{
indexCounter++;
}
}
for (int i = 0; i < correctGuesses; i++)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("x ");
Console.ForegroundColor = ConsoleColor.Gray;
}
for (int i = 0; i < cNumberfPos; i++)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write("x ");
Console.ForegroundColor = ConsoleColor.Gray;
}
}
while (correctGuesses != 4);
Console.WriteLine("Congratulations! You have guessed all 4 Numbers right. You should now be ready for a real game.");
Console.WriteLine("To return to the main menu please press any key.");
Console.ReadKey();
}
static void TutorialMenu()
{
Console.Clear();
Console.WriteLine("\nPlease Choose:");
Console.WriteLine("[E]xplanation");
Console.WriteLine("[T]utorial Game");
Console.WriteLine("[B]ack");
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment