#include<stdio.h>
#include<windows.h>
#include<time.h>
#define LEFT 75
#define RIGHT 77
#define UP 72
#define DOWN 80
#define SPACE 32
int map[30][30] = {0};
void gotoxy(int x,int y)
{
COORD pos= {x,y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
int main()
{
int x, y, bx=0, by=0, i, j, dx=0, dy=0;
int arcon = 0, acx=0, acy=0, view=0; // 1~23: 0~22+1
char move;
srand(time(NULL));
for(i=0; i<25; i++)
{
for(j=0; j<25; j++)
{
if(i==0 || j==0 || i==24 || j==24)
{
gotoxy(i, j);
map[i][j] = 4;
printf("#");
}
}
}
x = 5;
y = 5;
bx = 4;
by = 4;
map[x][y] = 9;
gotoxy(x, y);
printf("*");
while(1)
{
gotoxy(10, 27);
printf("tried arcon count: %d", arcon);
gotoxy(bx, by);
map[bx][by] = 0;
printf(" ");
if(view==0) {
if(rand()%10<1) {
acx = rand()%23+1;
acy = rand()%23+1;
gotoxy(acx, acy);
printf("@");
map[acx][acy] = 2;
view=1;
}
}
if(_kbhit()) {
move = _getch();
switch(move) {
case LEFT:
dx=-1;
dy=0;
break;
case RIGHT:
dx=1;
dy=0;
break;
case UP:
dx=0;
dy=-1;
break;
case DOWN:
dx=0;
dy=1;
break;
}
}
if(map[dx+x][dy+y]==2) {
map[dx+x][dy+y]=0;
gotoxy(dx+x, dy+y);
printf(" ");
arcon++;
view = 0;
}
x += dx;
y += dy;
gotoxy(x, y);
map[x][y] = 9;
printf("*");
bx = x;
by = y;
for(i=0; i<25; i++)
{
for(j=0; j<25; j++)
{
gotoxy(i+30, j);
printf("%d", map[i][j]);
}
}
Sleep(30);
}
}