Add map rendering

This commit is contained in:
Marvin Rohrbach
2018-05-25 10:04:52 +02:00
parent 764f98b7e0
commit 5bc4c3c375

View File

@@ -1,4 +1,5 @@
using System;
using System.Text;
namespace CoopSweeper
{
@@ -6,7 +7,69 @@ namespace CoopSweeper
{
static void Main(string[] args)
{
string[,] map = new string[,] {
{"X"," ","X"," "},
{"X"," ","X"," "},
{"X"," ","X"," "},
{"X"," ","X"," "}
};
DrawBorder(2, 2, map.GetLength(0) + 2, map.GetLength(1) + 2);
DrawMap(3,3,RenderMap(map));
Console.ReadKey();
}
private static string[] RenderMap(string[,] map)
{
var res = new string[map.GetLength(1)];
for(var y = 0; y < map.GetLength(1); y++)
{
var linebuilder = new StringBuilder();
for (var x = 0; x < map.GetLength(0); x++)
{
linebuilder.Append(map[x, y]);
}
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]);
}
}
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);
// ┌──┬──┐ ╔══╦══╗ ╒══╤══╕ ╓──╥──╖
// │ │ │ ║ ║ ║ │ │ │ ║ ║ ║
// ├──┼──┤ ╠══╬══╣ ╞══╪══╡ ╟──╫──╢
// │ │ │ ║ ║ ║ │ │ │ ║ ║ ║
// └──┴──┘ ╚══╩══╝ ╘══╧══╛ ╙──╨──╜
}
}
}