diff --git a/CoopSweeper/GameTypes/Field.cs b/CoopSweeper/GameTypes/Field.cs index e32129a..7b70130 100644 --- a/CoopSweeper/GameTypes/Field.cs +++ b/CoopSweeper/GameTypes/Field.cs @@ -16,19 +16,20 @@ namespace CoopSweeper.GameTypes public FieldState State { get; set; } - public char ToChar() + public DisplayState GetDisplayState() { switch(State) { - case FieldState.FLAG: return 'F'; - case FieldState.NONE: return '◌'; - case FieldState.QUESTIONMARK: return '?'; + case FieldState.QUESTIONMARK: + case FieldState.NONE: + case FieldState.FLAG: + return (DisplayState)State; case FieldState.REVEALED: if(ContainsBomb) - return '☼'; - return ' '; + return DisplayState.BOMB; + return 0; } - return 'E'; + return DisplayState.ERROR; } } } diff --git a/CoopSweeper/GameTypes/IField.cs b/CoopSweeper/GameTypes/IField.cs index ff1e1eb..afa6b17 100644 --- a/CoopSweeper/GameTypes/IField.cs +++ b/CoopSweeper/GameTypes/IField.cs @@ -4,12 +4,30 @@ using System.Text; 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 { - NONE, - REVEALED, - QUESTIONMARK, - FLAG + NONE = DisplayState.NONE, + REVEALED = DisplayState.EMPTY, + QUESTIONMARK = DisplayState.QUESTIONMARK, + FLAG = DisplayState.FLAG } public interface IField @@ -19,6 +37,6 @@ namespace CoopSweeper.GameTypes FieldState State { get; set; } - char ToChar(); + DisplayState GetDisplayState(); } } diff --git a/CoopSweeper/Program.cs b/CoopSweeper/Program.cs index 3c57702..21d417e 100644 --- a/CoopSweeper/Program.cs +++ b/CoopSweeper/Program.cs @@ -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)