turboc.h 받아두는거 있지 말길
2009/03/30 - [C/C++] - UI (User Interface)  참고!!
/*
#include <turboc.h>        //Mapping
void Print_MAP(){
 int i,j;
 gotoxy(0,0);
 for(i=0;i<10;i++){
  for(j=0;j<10;j++){
   if(i==0 || j == 0 || i == 9 || j==9){
    textcolor(YELLOW);
    printf("■");
   }else{
    printf("  ");
   }
  }
  printf("\n");
 }
}
int main(){
 
 int x,y;
 
 int ch;
 x=y=3;
 system("mode con cols=22 lines=16");
 Print_MAP();
 while(1){
  gotoxy(0,13);
  textcolor(WHITE);
  printf("x = %d , y = %d \n",x,y);
  gotoxy(x,y);
  ch = getch();
  if(ch== 0xe0){ //
   ch = getch();
   switch(ch){
    case UP:
     if(y!=1)y--;
     break;
    case DOWN:
     if(y!=8)y++;
     break;
    case LEFT:
     if(x!=2)x--;
     break;
    case RIGHT:
     if(x!=17)x++;
     break;
   }
  }else{ // nomal key
   switch(ch){
    case 'q':
     gotoxy(0,15);
     return 0;
    case ' ':
     textcolor(baserand(0,10));
     printf("%c",baserand('A','Z'));
     break;
   }
  }
 }
 return 0;
}
*/
#include <turboc.h>
int main(){
 int i,j;
 int x,y;
 char ch;
 int MAP[10][10] = {
  {1,1,1,1,1,1,1,1,1,1,},
  {1,0,1,0,0,0,0,0,0,1,},
  {1,0,1,0,0,1,0,1,0,1,},
  {1,0,1,0,1,1,0,1,0,1,},
  {1,0,1,0,0,0,1,0,0,1,},
  {1,0,1,0,0,1,0,0,0,1,},
  {1,0,1,0,1,0,0,1,0,1,},
  {1,0,0,0,0,0,1,1,0,1,},
  {1,0,0,0,0,0,0,1,0,0,},
  {1,1,1,1,1,1,1,1,1,1,}
 };
 x = y = 1;
 gotoxy(0,0);
 for(i=0;i<10;i++){
  for(j=0;j<10;j++){
   if(MAP[i][j] == 1){
    printf("■");    
   }else if(MAP[i][j] == 2){
    printf("○");    
   }else{
    printf("  ");
   }
  }
  printf("\n");
 }
 MAP[x][y] = 2;
 while(1){
  gotoxy(0,13);
  printf("x = %d y = %d \n",x,y);
  gotoxy(0,0);
  for(j=0;j<10;j++){
   for(i=0;i<10;i++){
    if(MAP[i][j] == 1){
     printf("■");    
    }else if(MAP[i][j] == 2){
     printf("○");    
    }else{
     printf("  ");
    }
   }
   printf("\n");
  }
  ch = getch();
  switch(ch){
  case UP:
   if(MAP[x][y-1] == 0){
    MAP[x][y-1] = 2;
    MAP[x][y] = 0;
    y--;
   }
   break;
  case DOWN:
   if(MAP[x][y+1] == 0){
    MAP[x][y+1] = 2;
    MAP[x][y] = 0;
    y++;
   }
   break;
  case LEFT:
   if(MAP[x-1][y] == 0){
    MAP[x-1][y] = 2;
    MAP[x][y] = 0;
    x--;
   }
   break;
  case RIGHT:
   if(MAP[x+1][y] == 0){
    MAP[x+1][y] = 2;
    MAP[x][y] = 0;
    x++;
   }
   break;
  }
  if(x==8 && y == 9){
   printf("Game End... \n");
   break;
  }
 }
 return 0;
}

