Add colorcoded rendering
This commit is contained in:
@@ -16,19 +16,20 @@ namespace CoopSweeper.GameTypes
|
|||||||
|
|
||||||
public FieldState State { get; set; }
|
public FieldState State { get; set; }
|
||||||
|
|
||||||
public char ToChar()
|
public DisplayState GetDisplayState()
|
||||||
{
|
{
|
||||||
switch(State)
|
switch(State)
|
||||||
{
|
{
|
||||||
case FieldState.FLAG: return 'F';
|
case FieldState.QUESTIONMARK:
|
||||||
case FieldState.NONE: return '◌';
|
case FieldState.NONE:
|
||||||
case FieldState.QUESTIONMARK: return '?';
|
case FieldState.FLAG:
|
||||||
|
return (DisplayState)State;
|
||||||
case FieldState.REVEALED:
|
case FieldState.REVEALED:
|
||||||
if(ContainsBomb)
|
if(ContainsBomb)
|
||||||
return '☼';
|
return DisplayState.BOMB;
|
||||||
return ' ';
|
return 0;
|
||||||
}
|
}
|
||||||
return 'E';
|
return DisplayState.ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,12 +4,30 @@ using System.Text;
|
|||||||
|
|
||||||
namespace CoopSweeper.GameTypes
|
namespace CoopSweeper.GameTypes
|
||||||
{
|
{
|
||||||
|
public enum DisplayState
|
||||||
|
{
|
||||||
|
ERROR = -667,
|
||||||
|
NONE = -1,
|
||||||
|
QUESTIONMARK = -2,
|
||||||
|
FLAG = -42,
|
||||||
|
BOMB = -666,
|
||||||
|
EMPTY = 0,
|
||||||
|
NUMBER1 = 1,
|
||||||
|
NUMBER2 = 2,
|
||||||
|
NUMBER3 = 3,
|
||||||
|
NUMBER4 = 4,
|
||||||
|
NUMBER5 = 5,
|
||||||
|
NUMBER6 = 6,
|
||||||
|
NUMBER7 = 7,
|
||||||
|
NUMBER8 = 8
|
||||||
|
}
|
||||||
|
|
||||||
public enum FieldState
|
public enum FieldState
|
||||||
{
|
{
|
||||||
NONE,
|
NONE = DisplayState.NONE,
|
||||||
REVEALED,
|
REVEALED = DisplayState.EMPTY,
|
||||||
QUESTIONMARK,
|
QUESTIONMARK = DisplayState.QUESTIONMARK,
|
||||||
FLAG
|
FLAG = DisplayState.FLAG
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IField
|
public interface IField
|
||||||
@@ -19,6 +37,6 @@ namespace CoopSweeper.GameTypes
|
|||||||
|
|
||||||
FieldState State { get; set; }
|
FieldState State { get; set; }
|
||||||
|
|
||||||
char ToChar();
|
DisplayState GetDisplayState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,12 @@ namespace CoopSweeper
|
|||||||
|
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
Console.OutputEncoding = Encoding.UTF8;
|
||||||
|
Console.ForegroundColor = ConsoleColor.White;
|
||||||
|
Console.BackgroundColor = ConsoleColor.Black;
|
||||||
|
Console.Clear();
|
||||||
var game = new Game();
|
var game = new Game();
|
||||||
|
game.GenerateGame(15, 10, 15);
|
||||||
var cursorPosX = 0;
|
var cursorPosX = 0;
|
||||||
var cursorPosY = 0;
|
var cursorPosY = 0;
|
||||||
ConsoleKey key = (ConsoleKey)(-1);
|
ConsoleKey key = (ConsoleKey)(-1);
|
||||||
@@ -25,8 +30,15 @@ namespace CoopSweeper
|
|||||||
cursorPosX--; break;
|
cursorPosX--; break;
|
||||||
case ConsoleKey.RightArrow:
|
case ConsoleKey.RightArrow:
|
||||||
cursorPosX++; break;
|
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);
|
DrawBorder(2, 2, game.Map.GetLength(0) + 2, game.Map.GetLength(1) + 2);
|
||||||
DrawMap(3, 3, game.Map, cursorPosX, cursorPosY);
|
DrawMap(3, 3, game.Map, cursorPosX, cursorPosY);
|
||||||
} while ((key = Console.ReadKey().Key) != ConsoleKey.Escape);
|
} while ((key = Console.ReadKey().Key) != ConsoleKey.Escape);
|
||||||
@@ -36,19 +48,61 @@ namespace CoopSweeper
|
|||||||
{
|
{
|
||||||
var oldBg = Console.BackgroundColor;
|
var oldBg = Console.BackgroundColor;
|
||||||
var oldFg = Console.ForegroundColor;
|
var oldFg = Console.ForegroundColor;
|
||||||
if(isCursor)
|
bool fgChanged = false;
|
||||||
{
|
bool bgChanged = false;
|
||||||
var c = Console.ForegroundColor;
|
var c = 'E';
|
||||||
Console.ForegroundColor = Console.BackgroundColor;
|
var state = f.GetDisplayState();
|
||||||
Console.BackgroundColor = c;
|
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)
|
if (isCursor)
|
||||||
{
|
{
|
||||||
var c = Console.ForegroundColor;
|
fgChanged = true;
|
||||||
|
bgChanged = true;
|
||||||
|
var s = Console.ForegroundColor;
|
||||||
Console.ForegroundColor = Console.BackgroundColor;
|
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)
|
private static void DrawMap(int posX, int posY, IField[,] map, int cursorX, int cursorY)
|
||||||
|
|||||||
Reference in New Issue
Block a user