Add colorcoded rendering
This commit is contained in:
@@ -9,7 +9,12 @@ namespace CoopSweeper
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.OutputEncoding = Encoding.UTF8;
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
Console.BackgroundColor = ConsoleColor.Black;
|
||||
Console.Clear();
|
||||
var game = new Game();
|
||||
game.GenerateGame(15, 10, 15);
|
||||
var cursorPosX = 0;
|
||||
var cursorPosY = 0;
|
||||
ConsoleKey key = (ConsoleKey)(-1);
|
||||
@@ -25,8 +30,15 @@ namespace CoopSweeper
|
||||
cursorPosX--; break;
|
||||
case ConsoleKey.RightArrow:
|
||||
cursorPosX++; break;
|
||||
case ConsoleKey.Spacebar:
|
||||
game.Reveal(cursorPosX, cursorPosY); break;
|
||||
case ConsoleKey.F:
|
||||
game.SetFlag(cursorPosX, cursorPosY); break;
|
||||
}
|
||||
game.GenerateGame(15, 10, 15);
|
||||
if (cursorPosX < 0) cursorPosX = 0;
|
||||
if (cursorPosY < 0) cursorPosY = 0;
|
||||
if (cursorPosX >= game.Map.GetLength(0)) cursorPosX = game.Map.GetLength(0) - 1;
|
||||
if (cursorPosY >= game.Map.GetLength(1)) cursorPosY = game.Map.GetLength(1) - 1;
|
||||
DrawBorder(2, 2, game.Map.GetLength(0) + 2, game.Map.GetLength(1) + 2);
|
||||
DrawMap(3, 3, game.Map, cursorPosX, cursorPosY);
|
||||
} while ((key = Console.ReadKey().Key) != ConsoleKey.Escape);
|
||||
@@ -36,19 +48,61 @@ namespace CoopSweeper
|
||||
{
|
||||
var oldBg = Console.BackgroundColor;
|
||||
var oldFg = Console.ForegroundColor;
|
||||
if(isCursor)
|
||||
{
|
||||
var c = Console.ForegroundColor;
|
||||
Console.ForegroundColor = Console.BackgroundColor;
|
||||
Console.BackgroundColor = c;
|
||||
bool fgChanged = false;
|
||||
bool bgChanged = false;
|
||||
var c = 'E';
|
||||
var state = f.GetDisplayState();
|
||||
switch (state) {
|
||||
case DisplayState.EMPTY:
|
||||
c = ' ';
|
||||
break;
|
||||
case DisplayState.NONE:
|
||||
fgChanged = true;
|
||||
Console.ForegroundColor = ConsoleColor.Gray;
|
||||
c = '◌';
|
||||
break;
|
||||
case DisplayState.QUESTIONMARK:
|
||||
c = '?';
|
||||
break;
|
||||
case DisplayState.BOMB:
|
||||
fgChanged = true;
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
c = '☼';
|
||||
break;
|
||||
case DisplayState.ERROR:
|
||||
c = 'e';
|
||||
break;
|
||||
case DisplayState.FLAG:
|
||||
fgChanged = true;
|
||||
Console.ForegroundColor = ConsoleColor.Cyan;
|
||||
c = 'F';
|
||||
break;
|
||||
case DisplayState.NUMBER1:
|
||||
case DisplayState.NUMBER2:
|
||||
case DisplayState.NUMBER3:
|
||||
case DisplayState.NUMBER4:
|
||||
case DisplayState.NUMBER5:
|
||||
case DisplayState.NUMBER6:
|
||||
case DisplayState.NUMBER7:
|
||||
case DisplayState.NUMBER8:
|
||||
fgChanged = true;
|
||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||
c = state.ToString()[0];
|
||||
break;
|
||||
}
|
||||
Console.Write(f.ToChar());
|
||||
if (isCursor)
|
||||
{
|
||||
var c = Console.ForegroundColor;
|
||||
fgChanged = true;
|
||||
bgChanged = true;
|
||||
var s = Console.ForegroundColor;
|
||||
Console.ForegroundColor = Console.BackgroundColor;
|
||||
Console.BackgroundColor = c;
|
||||
Console.BackgroundColor = s;
|
||||
}
|
||||
Console.Write(c);
|
||||
if (fgChanged)
|
||||
Console.ForegroundColor = oldFg;
|
||||
if (bgChanged)
|
||||
Console.BackgroundColor = oldBg;
|
||||
}
|
||||
|
||||
private static void DrawMap(int posX, int posY, IField[,] map, int cursorX, int cursorY)
|
||||
|
||||
Reference in New Issue
Block a user