#include <stdio.h>
#include <windows.h>
#include <string.h>
#include <conio.h>
#define LEFT 75
#define RIGHT 77
#define UP 72
#define DOWN 80
#define SPACEC 32
int x, y;
int map[100][100] = {0};
int playerType = 1;
void gotoXY(int x, int y)
{
COORD Pos;
Pos.X = x;
Pos.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Pos);
}
int main()
{
char c;
int a;
x = 5;
y = 5;
a=100;
SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 11 );
for(int i=0; i<20; i++) {
for(int j=0; j<40; j++) {
if(i==0 || j==0 || i==19 ||j==39) {
map[i][j] = 9;
printf("~");
}
else {
printf(" ");
}
}
printf("\n");
}
gotoXY(36,17);
printf("?");
gotoXY(50,4);
printf("1~9 의 수를 누르면 플레이어의 색이 바뀝니다");
gotoXY(50,2);
printf("%HP:");
gotoXY(53,2);
printf("%d",a);
gotoXY(50,3);
printf("asdw는 A를, 방향키는 *을 조종합니다");
gotoXY(x, y);
printf("*");
while(1)
{
if (kbhit()) //키보드 입력 확인 (true / false)
{
c = _getch();
switch(c)
{
case 49:
{
SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 1 );
break;
}
case 50:
{
SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 2 );
break;
}
case 51:
{
SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 3 );
break;
}
case 52:
{
SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 4 );
break;
}
case 53:
{
SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 5 );
break;
}
case 54:
{
SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 6 );
break;
}
case 55:
{
SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 7 );
break;
}
case 56:
{
SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 8 );
break;
}
case 57:
{
SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 9 );
break;
}
case 75:
if(x==1) {
continue;
}
map[x][y] = 0;
gotoXY(x, y);
printf(" ");
x--;
map[x][y] = 7;
gotoXY(x, y);
printf("%c", playerType==1 ? '*' : 'A');
break;
case 77: // RIGHT
if(x==38) {
continue;
}
map[x][y] = 0;
gotoXY(x, y);
printf(" ");
x++;
map[x][y] = 7;
gotoXY(x, y);
printf("%c", playerType==1 ? '*' : 'A');
break;
case 72: // UP
if(y==1) {
continue;
}
map[x][y] = 0;
gotoXY(x, y);
printf(" ");
y--;
map[x][y] = 7;
gotoXY(x, y);
printf("%c", playerType==1 ? '*' : 'A');
break;
case 80: // DOWN
if(y==18) {
continue;
}
map[x][y] = 0;
gotoXY(x, y);
printf(" ");
y++;
map[x][y] = 7;
gotoXY(x, y);
printf("%c", playerType==1 ? '*' : 'A');
break;
case 97:
if(x==1) {
continue;
}
map[x][y] = 0;
gotoXY(x, y);
printf(" ");
x--;
map[x][y] = 7;
gotoXY(x, y);
printf("%c", playerType==2 ? '*' : 'A');
break;
case 100:
if(x==38) {
continue;
}
map[x][y] = 0;
gotoXY(x, y);
printf(" ");
x++;
map[x][y] = 7;
gotoXY(x, y);
printf("%c", playerType==2 ? '*' : 'A');
break;
case 119:
if(y==1) {
continue;
}
map[x][y] = 0;
gotoXY(x, y);
printf(" ");
y--;
map[x][y] = 7;
gotoXY(x, y);
printf("%c", playerType==2 ? '*' : 'A');
break;
case 115:
if(y==18) {
continue;
}
map[x][y] = 0;
gotoXY(x, y);
printf(" ");
y++;
map[x][y] = 7;
gotoXY(x, y);
printf("%c", playerType==2 ? '*' : 'A');
break;
}
}
}
}