MasterMind/Master Mind/Render.cs

128 lines
3.7 KiB
C#
Raw Permalink Normal View History

2023-05-25 11:33:44 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Master_Mind
{
public class Render
{
2023-05-26 07:42:05 +00:00
public static void RenderBoard(Game.GameData board, bool showAns = false)
2023-05-25 11:33:44 +00:00
{
2023-05-25 11:50:53 +00:00
for (int x = 0; x < (board.go); x++)
2023-05-25 11:33:44 +00:00
{
for (int y = 0; y < 4; y++)
{
Console.BackgroundColor = Values.colors[board.board[x, y]];
Console.Write(" ");
Console.BackgroundColor = ConsoleColor.Black;
Console.Write(" ");
}
Console.Write(" ");
2023-05-25 11:50:53 +00:00
int[] checks = board.ContainsCalcIHateThis(x);
2023-05-25 12:07:02 +00:00
Console.BackgroundColor = ConsoleColor.Gray;
2023-05-25 11:50:53 +00:00
Console.Write(" ");
2023-05-25 11:33:44 +00:00
for (int y = 0; y < 4; y++)
{
2023-05-25 11:50:53 +00:00
switch (checks[y])
2023-05-25 11:33:44 +00:00
{
2023-05-25 11:50:53 +00:00
case 1:
Console.BackgroundColor = ConsoleColor.DarkGreen;
break;
case 2:
Console.BackgroundColor = ConsoleColor.DarkRed;
break;
case 0:
Console.BackgroundColor = ConsoleColor.Black;
break;
2023-05-25 11:33:44 +00:00
}
Console.Write(" ");
}
2023-05-25 12:07:02 +00:00
Console.BackgroundColor = ConsoleColor.Gray;
2023-05-25 11:50:53 +00:00
Console.Write(" ");
2023-05-25 11:33:44 +00:00
2023-05-25 11:50:53 +00:00
Console.BackgroundColor = ConsoleColor.Black;
2023-05-25 11:33:44 +00:00
Console.WriteLine("\n");
}
Console.WriteLine("\n");
2023-05-25 12:58:09 +00:00
2023-05-26 07:42:05 +00:00
if (showAns)
2023-05-25 12:58:09 +00:00
{
2023-05-26 07:42:05 +00:00
for (int y = 0; y < 4; y++)
{
Console.BackgroundColor = Values.colors[board.sequence[y]];
Console.Write(" ");
Console.BackgroundColor = ConsoleColor.Black;
Console.Write(" ");
}
2023-05-25 12:58:09 +00:00
}
2023-05-25 11:33:44 +00:00
}
public static int[] GetColorInput()
{
int[] colors = new int[4];
int selected = 0;
while (true)
{
Console.Clear();
for (int x = 0; x < 4; x++)
{
Console.Write(" ");
for (int y = 0; y < 4; y++)
{
Console.BackgroundColor = Values.colors[colors[y]];
Console.Write((y == selected) ? "# #" : " ");
Console.BackgroundColor = ConsoleColor.Black;
Console.Write(" ");
}
Console.WriteLine();
}
ConsoleKey ck = Console.ReadKey().Key;
switch (ck)
{
case ConsoleKey.LeftArrow:
if (--selected < 0)
selected = 3;
break;
case ConsoleKey.RightArrow:
if (++selected > 3)
selected = 0;
break;
case ConsoleKey.UpArrow:
if (++colors[selected] > 5)
colors[selected] = 0;
break;
case ConsoleKey.DownArrow:
if (--colors[selected] < 0)
colors[selected] = 5;
break;
case ConsoleKey.Enter:
return colors;
}
}
}
}
}