#include <stdio.h>
#include <windows.h>
#define MAP_WIDTH 6
#define MAP_SPACE 0
#define MAP_STONE 1
static void GotoXY(unsigned int x, unsigned int y)
{
COORD coord = {x * 2, y}; // unicode
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
static void HideCursor()
{
CONSOLE_CURSOR_INFO cci;
cci.bVisible = FALSE;
cci.dwSize = sizeof(cci);
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorInfo(handle, &cci);
}
void MapInit(unsigned char map[MAP_WIDTH][MAP_WIDTH])
{
for(int h = 0; h < MAP_WIDTH; ++h)
{
for(int w = 0; w < MAP_WIDTH; ++w)
{
map[h][w] = MAP_SPACE;
}
}
}
void MapSetStone(unsigned char map[MAP_WIDTH][MAP_WIDTH], unsigned int x, unsigned int y)
{
if((x >= MAP_WIDTH) || (y >= MAP_WIDTH))
return;
map[y][x] = MAP_STONE;
}
void MapPrint(unsigned char map[MAP_WIDTH][MAP_WIDTH])
{
for(int h = 0; h < MAP_WIDTH; ++h)
{
for(int w = 0; w < MAP_WIDTH; ++w)
{
GotoXY(w, h);
switch(map[h][w])
{
case MAP_SPACE:
puts("※");
break;
case MAP_STONE:
puts("●");
break;
}
}
}
}
int main(void)
{
HideCursor();
unsigned char map[MAP_WIDTH][MAP_WIDTH];
MapInit(map);
MapSetStone(map, 1, 1);
MapSetStone(map, 2, 1);
MapSetStone(map, 3, 5);
MapSetStone(map, 3, 4);
MapPrint(map);
return 0;
}
|