프로필
소개
#include<stdio.h>
#include<windows.h>
#include<time.h>
#include<conio.h>
int px=5, py=5; // player1의 초기위치
int dx=1,dy=1;
int p2x=25,p2y=25;
int player1score=0;
int player2score=0;
int x2=1, y2=1;
int map[100][100] = {0};
void info()
{
gotoxy(5,115); //23,90
printf("x : %2d y : %2d",px,py);
gotoxy(7,100);
printf("1.방향키로 플레이어를 움직이세요.");
gotoxy(10,100);
printf("player1 score : %2d", player1score);
}
void view_map()
{
int i;
for (i=0; i<=91; i+=2)
{
gotoxy(41,i);
printf("x");
gotoxy(0,i);
printf("x");
}
for (i=0; i<=41; i++)
{
gotoxy(i,91);
printf("x");
gotoxy(i,0);
printf("x");
}
}
void gotoxy(int x,int y)
{
COORD pos= {y,x};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}
int main()
{
char c;
view_map();
while(1)
{
if(_kbhit())
{
info();
c = _getch();
// together use
if((c !='a' && c !='w' && c !='s' && c != 'd')) {
gotoxy(px, py);
map[px][py] = 0;
printf(" ");
if(c==72&&px>1) px--;
else if(c==75&&py>1) py--;
else if(c==77&&py<90) py++;
else if(c==80&&px<40) px++;
gotoxy(px, py);
//map[px][py] = 1;
printf("*");
//////////////////////////////////
gotoxy(p2x, p2y);
map[p2x][p2y] = 0;
printf(" ");
if(map[px][py]==2)
{
player1score++;
map[px][py]=0;
gotoxy(10,100);
printf("player1 score : %2d", player1score);
}
}
if((c=='w' || c=='W')&& p2x>1) p2x--;
else if((c=='d' || c=='D')&& p2y<90) p2y++;
else if((c=='a' || c=='A')&& p2y>1) p2y--;
else if((c=='s' || c=='S')&&p2x<40) p2x++;
gotoxy(p2x, p2y);
map[p2x][p2y] = 2;
printf("A");
// int x = rand()%40+1;
// int y = rand()%90+1;
// gotoxy(x,y);
// map[x][y]=2;
// printf("N");
}
}