Merge branch 'master' of https://gitlab.com/timwundenberg/minesweeper-coop
This commit is contained in:
@@ -20,7 +20,17 @@ namespace CoopSweeper.GameTypes
|
|||||||
|
|
||||||
public char ToChar()
|
public char ToChar()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
switch(State)
|
||||||
|
{
|
||||||
|
case FieldState.FLAG: return 'F';
|
||||||
|
case FieldState.NONE: return '◌';
|
||||||
|
case FieldState.QUESTIONMARK: return '?';
|
||||||
|
case FieldState.REVEALED:
|
||||||
|
if(ContainsBomb)
|
||||||
|
return '☼';
|
||||||
|
return ' ';
|
||||||
|
}
|
||||||
|
return 'E';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,44 +1,66 @@
|
|||||||
using System;
|
using CoopSweeper.GameTypes;
|
||||||
|
using System;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace CoopSweeper
|
namespace CoopSweeper
|
||||||
{
|
{
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
|
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
string[,] map = new string[,] {
|
var game = new Game();
|
||||||
{"X"," ","X"," "},
|
var cursorPosX = 0;
|
||||||
{"X"," ","X"," "},
|
var cursorPosY = 0;
|
||||||
{"X"," ","X"," "},
|
ConsoleKey key = (ConsoleKey)(-1);
|
||||||
{"X"," ","X"," "}
|
do
|
||||||
};
|
{
|
||||||
DrawBorder(2, 2, map.GetLength(0) + 2, map.GetLength(1) + 2);
|
switch(key)
|
||||||
DrawMap(3,3,RenderMap(map));
|
{
|
||||||
Console.ReadKey();
|
case ConsoleKey.UpArrow:
|
||||||
|
cursorPosY--; break;
|
||||||
|
case ConsoleKey.DownArrow:
|
||||||
|
cursorPosY++; break;
|
||||||
|
case ConsoleKey.LeftArrow:
|
||||||
|
cursorPosX--; break;
|
||||||
|
case ConsoleKey.RightArrow:
|
||||||
|
cursorPosX++; break;
|
||||||
|
}
|
||||||
|
game.GenerateGame(15, 10, 15);
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string[] RenderMap(string[,] map)
|
private static void DrawChar(IField f, bool isCursor)
|
||||||
|
{
|
||||||
|
var oldBg = Console.BackgroundColor;
|
||||||
|
var oldFg = Console.ForegroundColor;
|
||||||
|
if(isCursor)
|
||||||
|
{
|
||||||
|
var c = Console.ForegroundColor;
|
||||||
|
Console.ForegroundColor = Console.BackgroundColor;
|
||||||
|
Console.BackgroundColor = c;
|
||||||
|
}
|
||||||
|
Console.Write(f.ToChar());
|
||||||
|
if (isCursor)
|
||||||
|
{
|
||||||
|
var c = Console.ForegroundColor;
|
||||||
|
Console.ForegroundColor = Console.BackgroundColor;
|
||||||
|
Console.BackgroundColor = c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void DrawMap(int posX, int posY, IField[,] map, int cursorX, int cursorY)
|
||||||
{
|
{
|
||||||
var res = new string[map.GetLength(1)];
|
var res = new string[map.GetLength(1)];
|
||||||
for (var y = 0; y < map.GetLength(1); y++)
|
for (var y = 0; y < map.GetLength(1); y++)
|
||||||
{
|
{
|
||||||
var linebuilder = new StringBuilder();
|
Console.SetCursorPosition(posX, posY + y);
|
||||||
for (var x = 0; x < map.GetLength(0); x++)
|
for (var x = 0; x < map.GetLength(0); x++)
|
||||||
{
|
{
|
||||||
linebuilder.Append(map[x, y]);
|
DrawChar(map[x, y], x == cursorX && y == cursorY);
|
||||||
}
|
}
|
||||||
res[y] = linebuilder.ToString();
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void DrawMap(int posX, int posY, string[] mapLines)
|
|
||||||
{
|
|
||||||
for(var y = 0; y < mapLines.Length; y++)
|
|
||||||
{
|
|
||||||
Console.SetCursorPosition(posX, posY + y);
|
|
||||||
Console.Write(mapLines[y]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user