98 lines
3.6 KiB
C#
98 lines
3.6 KiB
C#
using CoopSweeper.GameTypes;
|
|
using System;
|
|
using System.Text;
|
|
|
|
namespace CoopSweeper
|
|
{
|
|
class Program
|
|
{
|
|
|
|
static void Main(string[] args)
|
|
{
|
|
var game = new Game();
|
|
var cursorPosX = 0;
|
|
var cursorPosY = 0;
|
|
ConsoleKey key = (ConsoleKey)(-1);
|
|
do
|
|
{
|
|
switch(key)
|
|
{
|
|
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 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)];
|
|
for (var y = 0; y < map.GetLength(1); y++)
|
|
{
|
|
Console.SetCursorPosition(posX, posY + y);
|
|
for (var x = 0; x < map.GetLength(0); x++)
|
|
{
|
|
DrawChar(map[x, y], x == cursorX && y == cursorY);
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void DrawBorder(int posX, int posY, int width, int height)
|
|
{
|
|
Console.SetCursorPosition(posX, posY);
|
|
var linebuilder = new StringBuilder();
|
|
linebuilder.Append("╔");
|
|
for (var x = 0; x < width - 2; x++)
|
|
linebuilder.Append("═");
|
|
linebuilder.Append("╗");
|
|
Console.Write(linebuilder);
|
|
for (var y = 1; y < height - 1; y++)
|
|
{
|
|
Console.SetCursorPosition(posX, posY + y);
|
|
Console.Write("║");
|
|
Console.SetCursorPosition(posX + width - 1, posY + y);
|
|
Console.Write("║");
|
|
}
|
|
Console.SetCursorPosition(posX, posY + height - 1);
|
|
linebuilder = new StringBuilder();
|
|
linebuilder.Append("╚");
|
|
for (var x = 0; x < width - 2; x++)
|
|
linebuilder.Append("═");
|
|
linebuilder.Append("╝");
|
|
Console.Write(linebuilder);
|
|
// ┌──┬──┐ ╔══╦══╗ ╒══╤══╕ ╓──╥──╖
|
|
// │ │ │ ║ ║ ║ │ │ │ ║ ║ ║
|
|
// ├──┼──┤ ╠══╬══╣ ╞══╪══╡ ╟──╫──╢
|
|
// │ │ │ ║ ║ ║ │ │ │ ║ ║ ║
|
|
// └──┴──┘ ╚══╩══╝ ╘══╧══╛ ╙──╨──╜
|
|
}
|
|
}
|
|
}
|