맵 만들기
Program
using System;
using System.Collections;
using System.Reflection;
namespace Algorithm
{
class Program
{
static void Main(string[] args)
{
Board board = new Board();
board.Initialize(25);
Console.CursorVisible = false;
const int WAIT_TICK = 1000 / 30;
int lastTick = 0;
while (true)
{
//FPS 프레임 (60프레임 OK 30 프레임 이하는 X)
#region 프레임 관리
int currentTick = System.Environment.TickCount;
//만약에 경과한 시간이 1/30초보다 작다면
if (currentTick - lastTick < WAIT_TICK)
continue;
lastTick = currentTick;
#endregion
//입력
//로직
//렌더링
Console.SetCursorPosition(0, 0);
board.Render();
}
}
}
}
Board
using System;
namespace Algorithm
{
class Board
{
public TileType[,] _tile;
public int _size;
const char CIRCLE = '\u25cf';
public enum TileType
{
Empty,
Wall
}
public void Initialize(int size)
{
_tile = new TileType[size, size];
_size = size;
for(int y = 0; y<_size;y++)
{
for (int x = 0; x < _size; x++)
{
if (x == 0 || x == _size - 1 || y == 0 || y == size - 1)
_tile[y, x] = TileType.Wall;
else
_tile[y, x] = TileType.Empty;
}
}
}
public void Render()
{
ConsoleColor prevColor = Console.ForegroundColor;
for (int y = 0; y < _size; y++)
{
for (int x = 0; x < _size; x++)
{
Console.ForegroundColor = GetTileColor(_tile[y, x]);
Console.Write(CIRCLE);
}
Console.WriteLine();
}
}
ConsoleColor GetTileColor(TileType type)
{
switch (type)
{
case TileType.Empty:
return ConsoleColor.Green;
case TileType.Wall:
return ConsoleColor.Red;
default:
return ConsoleColor.Green;
}
}
}
}