Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Mastermind
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package Registry
Operate
Terraform modules
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
seilenthalma100744
Mastermind
Commits
34a71627
Commit
34a71627
authored
4 months ago
by
Seilenthal
Committed by
steinti100434
3 months ago
Browse files
Options
Downloads
Patches
Plain Diff
TestAdd Mastermind game setup and difficulty handling
parent
5fb65e27
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
MastermindController.cs
+58
-0
58 additions, 0 deletions
MastermindController.cs
MastermindGame.cs
+20
-5
20 additions, 5 deletions
MastermindGame.cs
NewClass.cs
+12
-0
12 additions, 0 deletions
NewClass.cs
Program.cs
+7
-3
7 additions, 3 deletions
Program.cs
with
97 additions
and
8 deletions
MastermindController.cs
0 → 100644
+
58
−
0
View file @
34a71627
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
);
}
}
}
This diff is collapsed.
Click to expand it.
MastermindGame.cs
+
20
−
5
View file @
34a71627
...
...
@@ -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
;
}
...
...
This diff is collapsed.
Click to expand it.
NewClass.cs
0 → 100644
+
12
−
0
View file @
34a71627
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
Mastermind
{
internal
class
NewClass
{
}
}
This diff is collapsed.
Click to expand it.
Program.cs
+
7
−
3
View file @
34a71627
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
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment