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
b9be7c77
Commit
b9be7c77
authored
2 months ago
by
seilenthalma100744
Browse files
Options
Downloads
Patches
Plain Diff
Fixed Auto-save bug
parent
1282d215
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
MastermindGame.cs
+20
-13
20 additions, 13 deletions
MastermindGame.cs
with
20 additions
and
13 deletions
MastermindGame.cs
+
20
−
13
View file @
b9be7c77
...
...
@@ -55,22 +55,12 @@ namespace Game
/// </param>
public
MastermindGame
(
string
difficulty
,
bool
newGame
)
{
DifficultySetup
(
difficulty
,
out
code_length
,
out
duplicates
,
out
yellowHints
,
out
maxAttempt
,
out
usedTipp
);
attempts
=
new
int
[
maxAttempt
][];
feedback
=
new
(
int
,
Hints
)[
code_length
];
// Initializes each inner array to avoid null reference later
for
(
int
i
=
0
;
i
<
maxAttempt
;
i
++)
{
attempts
[
i
]
=
new
int
[
code_length
];
// Preinitializes each inner array
}
currentAttempt
=
0
;
// Starts a new Game or loads a old save
// (newGame = false -> Trys to load old game; newGame = true -> Starts a new Game)
if
(
newGame
)
{
DifficultySetup
(
difficulty
,
out
code_length
,
out
duplicates
,
out
yellowHints
,
out
maxAttempt
,
out
usedTipp
);
SetupGame
();
GenerateCode
();
AutoSaveGame
();
}
...
...
@@ -88,6 +78,8 @@ namespace Game
{
// If an error occurs during loading, a new game is started
Console
.
WriteLine
(
$"Error! Something went wrong with the loading of the savegame:
{
e
.
Message
}
. \nA new game is starting..."
);
DifficultySetup
(
difficulty
,
out
code_length
,
out
duplicates
,
out
yellowHints
,
out
maxAttempt
,
out
usedTipp
);
SetupGame
();
GenerateCode
();
AutoSaveGame
();
}
...
...
@@ -95,11 +87,13 @@ namespace Game
else
{
Console
.
WriteLine
(
"No Savegame found! Starting a new Game"
);
DifficultySetup
(
difficulty
,
out
code_length
,
out
duplicates
,
out
yellowHints
,
out
maxAttempt
,
out
usedTipp
);
SetupGame
();
GenerateCode
();
AutoSaveGame
();
}
}
// Debugging (Gets removed later)
foreach
(
int
zahl
in
code
)
{
...
...
@@ -107,7 +101,17 @@ namespace Game
}
}
private
void
SetupGame
()
{
attempts
=
new
int
[
maxAttempt
][];
feedback
=
new
(
int
,
Hints
)[
code_length
];
// Initializes each inner array to avoid null reference later
for
(
int
i
=
0
;
i
<
maxAttempt
;
i
++)
{
attempts
[
i
]
=
new
int
[
code_length
];
// Preinitializes each inner array
}
currentAttempt
=
0
;
}
private
void
DifficultySetup
(
string
difficulty
,
out
int
code_length
,
out
bool
duplicates
,
out
bool
yellowHints
,
out
int
maxAttempt
,
out
bool
usedTipp
)
{
...
...
@@ -488,6 +492,9 @@ namespace Game
string
usedTippLine
=
sr
.
ReadLine
();
usedTipp
=
bool
.
Parse
(
usedTippLine
);
// Initializes the arrays
SetupGame
();
// Reads and converts all the last attempts
string
line
;
while
((
line
=
sr
.
ReadLine
())
!=
null
)
...
...
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