Skip to content
Snippets Groups Projects
Commit 34a71627 authored by Seilenthal's avatar Seilenthal Committed by steinti100434
Browse files

TestAdd Mastermind game setup and difficulty handling

parent 5fb65e27
No related branches found
No related tags found
No related merge requests found
using Mastermind;
using System;
namespace Controller
{
/// <summary>
/// Mangages the game flow, handling user interactions and processing inputs
/// </summary>
class MastermindController
{
private MastermindGame spiel;
private string difficulty;
/// <summary>
/// Starts the game and controls the sequence
/// </summary>
public void Play()
{
Console.WriteLine("Welcome to Mastermind!");
Console.WriteLine("======================");
// User selects a difficulty
Console.WriteLine("Please select the difficulty you would like to play on:\n");
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");
bool checkMenu = false;
do
{
switch (Console.ReadLine().ToLower())
{
case "e":
difficulty = "easy";
checkMenu = true;
break;
case "m":
difficulty = "medium";
checkMenu = true;
break;
case "h":
difficulty = "hard";
checkMenu = true;
break;
default:
Console.WriteLine("Something went wrong! Try again. Only the letters \"E\", \"M\", \"H\" are allowed. ");
break;
}
} while (!checkMenu);
// Starts Game
Console.WriteLine($"Game starts with the difficulty: {difficulty}");
spiel = new MastermindGame(difficulty);
}
}
}
......@@ -4,12 +4,21 @@ using PseudoRandomGenerator;
namespace Mastermind
{
/// <summary>
/// Manages the game mechanics. It includes methods for generating the code, providing feedback after each guess, and checking the win condition
/// </summary>
public class MastermindGame
{
private int[] code;
private readonly int code_length;
private readonly bool duplicates;
/// <summary>
/// Initializes a new game with the specified difficulty level
/// </summary>
/// <param name="difficulty">
/// The difficulty level of the game,determines the length of the code and the number of attempts
/// </param>
public MastermindGame(string difficulty)
{
// Set parameters based on difficulty level
......@@ -32,9 +41,15 @@ namespace Mastermind
}
GenerateCode();
foreach(int zahl in code)
{
Console.WriteLine($"{zahl} ");
}
}
/// <summary>
/// Generates the code
/// </summary>
public void GenerateCode()
{
LCG lcg = new LCG(DateTime.Now.Ticks);
......@@ -45,7 +60,7 @@ namespace Mastermind
// Allow duplicates
for(int i = 0; i < code_length; i++)
{
code[i] = lcg.Next(0, 9);
code[i] = lcg.Next(0, 10);
}
} else
{
......@@ -58,12 +73,12 @@ namespace Mastermind
do
{
isDuplicate = false;
newNumber = lcg.Next(0, 9); // Generates a number between 0 and 9
newNumber = lcg.Next(0, 10); // Generates a number between 0 and 9
//Check if the generated number is already in the code
for (int j = 0; j < i; i++)
for (int j = 0; j < i; j++)
{
if (code[i] == newNumber)
if (code[j] == newNumber)
{
isDuplicate = true;
}
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Mastermind
{
internal class NewClass
{
}
}
using Mastermind;
using System;
using System;
using Controller;
using Mastermind;
namespace Program
{
......@@ -25,12 +26,15 @@ namespace Program
switch (Console.ReadLine().ToLower())
{
case "s":
checkMenu = true;
Console.WriteLine("Starting Game ...");
MastermindController controller = new MastermindController();
controller.Play();
checkMenu = true;
break;
case "t":
Tutorial tutorial = new Tutorial();
tutorial.TutorialGame();
checkMenu = true;
break;
case "q":
Environment.Exit(0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment