Skip to content
Snippets Groups Projects
Commit e1cb1875 authored by Seilenthal's avatar Seilenthal
Browse files

Changes for small resource savings

parent b5af5050
No related branches found
No related tags found
No related merge requests found
......@@ -22,7 +22,7 @@ namespace Game
private readonly int maxAttempt;
private int currentAttempt;
private int[][] attempts; // Jagged array (array of arrays) to save attempts
private (int guess, Hints hint)[,] feedback;
private (int guess, Hints hint)[] feedback;
private const string SaveFilePath = "mastermind_gamehistorie.txt";
/// <summary>
......@@ -56,7 +56,7 @@ namespace Game
}
attempts = new int[maxAttempt][];
feedback = new (int, Hints)[code_length, 1];
feedback = new (int, Hints)[code_length];
// Initializes each inner array to avoid null reference later
for (int i = 0; i < maxAttempt; i++)
......@@ -129,9 +129,9 @@ namespace Game
int[] used = new int[10]; // Tracks used numbers to prevent duplicate hints
// Resets the feedback-array
for(int i = 0; i < feedback.GetLength(0); i++)
for(int i = 0; i < feedback.Length; i++)
{
feedback[i,0] = (-1, Hints.None);
feedback[i] = (-1, Hints.None);
}
foreach(int i in input)
......@@ -146,7 +146,7 @@ namespace Game
// If duplicates are not allowed, check if the number hasn't already been used
if (used[i] == 0)
{
feedback[counter, 0] = (i, Hints.Green);
feedback[counter] = (i, Hints.Green);
used[i] = 1; // Marks as used
}
......@@ -154,7 +154,7 @@ namespace Game
else
{
// If duplicates are allowed, ignore used
feedback[counter, 0] = (i, Hints.Green);
feedback[counter] = (i, Hints.Green);
}
counter++;
check = true;
......@@ -172,7 +172,7 @@ namespace Game
// If duplicates are not allowed, check if the number hasn't already been used
if (used[i] == 0)
{
feedback[counter, 0] = (i, Hints.Yellow);
feedback[counter] = (i, Hints.Yellow);
used[i] = 1; // Marks as used
}
......@@ -180,7 +180,7 @@ namespace Game
else
{
// If duplicates are allowed, ignore used
feedback[counter, 0] = (i, Hints.Yellow);
feedback[counter] = (i, Hints.Yellow);
}
counter++;
}
......@@ -189,7 +189,7 @@ namespace Game
// Number is not present in the code
else
{
feedback[counter, 0] = (i, Hints.None);
feedback[counter] = (i, Hints.None);
counter++;
}
}
......@@ -197,9 +197,9 @@ namespace Game
// Sets numbers to -1 if hint is not green or yellow
for(int i = 0; i < feedback.GetLength(0); i++)
{
if (feedback[i, 0].hint != Hints.Green && feedback[i, 0].hint != Hints.Yellow)
if (feedback[i].hint != Hints.Green && feedback[i].hint != Hints.Yellow)
{
feedback[i, 0].guess = -1;
feedback[i].guess = -1;
}
}
}
......@@ -256,13 +256,13 @@ namespace Game
for (int i = 0; i < feedback.GetLength(0); i++)
{
if (feedback[i, 0].hint == Hints.Green)
if (feedback[i].hint == Hints.Green)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("X ");
Console.ForegroundColor = ConsoleColor.Gray;
}
else if (feedback[i, 0].hint == Hints.Yellow)
else if (feedback[i].hint == Hints.Yellow)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write("Y ");
......@@ -291,7 +291,7 @@ namespace Game
for(int i = 0; i < feedback.GetLength(0); i++)
{
Console.WriteLine($"Zahl: {feedback[i, 0].guess}, Hinweis: {feedback[i, 0].hint}");
Console.WriteLine($"Zahl: {feedback[i].guess}, Hinweis: {feedback[i].hint}");
}
}
......
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