This commit is contained in:
AUnicornWithNoLife 2023-05-25 12:50:53 +01:00
parent 70bb3d52fb
commit 9fed104d24
2 changed files with 57 additions and 20 deletions

View File

@ -54,6 +54,42 @@ namespace Master_Mind
this.go++; this.go++;
} }
public int[] ContainsCalcIHateThis(int row)
{
int[] retVal = new int[4];
int[] seqCache = new int[4];
this.sequence.CopyTo(seqCache, 0);
for (int i = 0; i < 4; i++)
{
if (this.board[row, i] == seqCache[i])
{
seqCache[i] = -1;
retVal[i] = 1;
}
}
for (int i = 0; i < 4; i++)
{
if (retVal[i] == 1)
continue;
for (int s = 0; s < 4; s++)
{
if (this.board[row, i] == seqCache[s])
{
seqCache[s] = -1;
retVal[i] = 2;
}
}
}
return retVal;
}
} }
public static void Play() public static void Play()

View File

@ -10,7 +10,7 @@ namespace Master_Mind
{ {
public static void RenderBoard(Game.GameData board) public static void RenderBoard(Game.GameData board)
{ {
for (int x = 0; x < 12; x++) for (int x = 0; x < (board.go); x++)
{ {
for (int y = 0; y < 4; y++) for (int y = 0; y < 4; y++)
{ {
@ -22,38 +22,39 @@ namespace Master_Mind
Console.Write(" "); Console.Write(" ");
int[] checks = board.ContainsCalcIHateThis(x);
Console.BackgroundColor = ConsoleColor.White;
Console.Write(" ");
for (int y = 0; y < 4; y++) for (int y = 0; y < 4; y++)
{ {
if (board.board[x, y] == board.sequence[y]) switch (checks[y])
{ {
Console.BackgroundColor = ConsoleColor.DarkGreen; case 1:
} Console.BackgroundColor = ConsoleColor.DarkGreen;
else if (board.sequence.Contains(board.board[x,y])) break;
{
Console.BackgroundColor = ConsoleColor.DarkRed; case 2:
} Console.BackgroundColor = ConsoleColor.DarkRed;
else break;
{
Console.BackgroundColor = ConsoleColor.Black; case 0:
Console.BackgroundColor = ConsoleColor.Black;
break;
} }
Console.Write(" "); Console.Write(" ");
} }
Console.BackgroundColor = ConsoleColor.Black; Console.BackgroundColor = ConsoleColor.White;
Console.Write(" ");
Console.BackgroundColor = ConsoleColor.Black;
Console.WriteLine("\n"); Console.WriteLine("\n");
} }
Console.WriteLine("\n"); Console.WriteLine("\n");
for (int y = 0; y < 4; y++)
{
Console.BackgroundColor = Values.colors[board.sequence[y]];
Console.Write(" ");
Console.BackgroundColor = ConsoleColor.Black;
Console.Write(" ");
}
} }
public static int[] GetColorInput() public static int[] GetColorInput()