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
eceddd54
Commit
eceddd54
authored
3 months ago
by
Seilenthal
Browse files
Options
Downloads
Patches
Plain Diff
Added User Input
parent
c3d455a6
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
MastermindController.cs
+44
-0
44 additions, 0 deletions
MastermindController.cs
MastermindGame.cs
+19
-0
19 additions, 0 deletions
MastermindGame.cs
with
63 additions
and
0 deletions
MastermindController.cs
+
44
−
0
View file @
eceddd54
using
Mastermind
;
using
System
;
using
System.Net.Http.Headers
;
namespace
Controller
{
...
...
@@ -53,6 +54,49 @@ namespace Controller
// Starts Game
Console
.
WriteLine
(
$"Game starts with the difficulty:
{
difficulty
}
"
);
spiel
=
new
MastermindGame
(
difficulty
);
while
(
spiel
.
StillHasTrials
())
{
// User input Code
int
[]
userInput
=
ReadInput
();
foreach
(
int
i
in
userInput
)
{
Console
.
WriteLine
(
i
);
}
}
}
private
int
[]
ReadInput
()
{
int
generatedCodeLength
=
spiel
.
GetCodeLength
();
int
[]
input
=
new
int
[
generatedCodeLength
];
bool
check
=
false
;
while
(!
check
)
{
Console
.
WriteLine
(
$"Please enter
{
generatedCodeLength
}
numbers (0 - 9) according to this scheme (e.g.: 0 1 2 3) "
);
string
inputString
=
Console
.
ReadLine
();
string
[]
parts
=
inputString
.
Split
(
' '
);
if
(
parts
.
Length
==
generatedCodeLength
)
{
// Convert string to int in array
for
(
int
i
=
0
;
i
<
input
.
Length
;
i
++)
{
if
(
int
.
TryParse
(
parts
[
i
],
out
int
tmp
))
{
input
[
i
]
=
tmp
;
check
=
true
;
}
else
{
Console
.
WriteLine
(
"Error! Something went wrong with the formatting. Try again"
);
check
=
false
;
}
}
}
}
return
input
;
}
}
}
This diff is collapsed.
Click to expand it.
MastermindGame.cs
+
19
−
0
View file @
eceddd54
...
...
@@ -12,6 +12,8 @@ namespace Mastermind
private
int
[]
code
;
private
readonly
int
code_length
;
private
readonly
bool
duplicates
;
private
readonly
int
maxAttempt
;
private
int
currentAttempt
;
/// <summary>
/// Initializes a new game with the specified difficulty level
...
...
@@ -27,20 +29,27 @@ namespace Mastermind
case
"easy"
:
code_length
=
4
;
duplicates
=
false
;
maxAttempt
=
6
;
break
;
case
"medium"
:
code_length
=
6
;
duplicates
=
false
;
maxAttempt
=
4
;
break
;
case
"hard"
:
code_length
=
8
;
duplicates
=
true
;
maxAttempt
=
3
;
break
;
default
:
throw
new
ArgumentException
(
"Invalid difficulty level"
);
}
currentAttempt
=
0
;
GenerateCode
();
// Debugging (Gets removed later)
foreach
(
int
zahl
in
code
)
{
Console
.
WriteLine
(
$"
{
zahl
}
"
);
...
...
@@ -115,5 +124,15 @@ namespace Mastermind
}
public
bool
StillHasTrials
()
{
return
currentAttempt
<
maxAttempt
;
}
public
int
GetCodeLength
()
{
return
code
.
Length
;
}
}
}
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