조회 수 1101 추천 수 0 댓글 0

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <conio.h>

void printstr(int d)
{
     int space=0;
     int wall=1;
     int inwall=4;
     int my=2;
     int you=3;
     int move=5;
     int setcolor[10]={1,8,13,10,15,15,15};
    
     HANDLE hConsole;

     hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
     SetConsoleTextAttribute(hConsole, setcolor[d]);

     char str[10][3]={"  ","■","●","●","▧","◈","●"};
     printf("%s",&str[d][0]);
}//printstr
   
int lencheak(int maxlen)
{
    int i=1;
   
    for(i=1;i*i<maxlen;i++);
   
    return i-1;
}//lencheak
void right(int arr[100][100],int *x,int *y,int inwall, int wall,int *remember)
{
     if(arr[*x][(*y)+1]==inwall || arr[*x][(*y)+1]==wall)
     {}
     else
     {
         *remember=arr[(*x)][++(*y)];
     }
}//right
void left(int arr[100][100],int *x,int *y,int inwall, int wall,int *remember)
{
     if(arr[*x][(*y)-1]==inwall || arr[*x][(*y)-1]==wall)
     {}
     else
     {
        
         *remember=arr[(*x)][--(*y)];
     }
}//left
void up(int arr[100][100],int *x,int *y,int inwall, int wall,int *remember)
{
     if(arr[(*x)-1][*y]==inwall || arr[(*x)-1][*y]==wall)
     {}
     else
     {
         *remember=arr[--(*x)][(*y)];
     }
}//up
void down(int arr[100][100],int *x,int *y,int inwall, int wall,int *remember)
{
     if(arr[(*x)+1][*y]==inwall || arr[(*x)+1][*y]==wall)
     {}
     else
     {  
         *remember=arr[++(*x)][(*y)];
     }
}//up
void movef(int cur,int arr[100][100],int *x,int *y,int inwall, int wall,int *remember,int *zhit,int *zx,int *zy)
{  

    switch(cur)
    {
    case 77:
        
         right(arr,x,y,inwall,wall,remember);
         break;
    case 75:
        
         left(arr,x,y,inwall,wall,remember);
         break;   
    case 72:
        
         up(arr,x,y,inwall,wall,remember);
         break;        
    case 80:
        
         down(arr,x,y,inwall,wall,remember);
         break;        
    
}
}   
void movez(int cur,int arr[100][100],int *x,int *y,int inwall, int wall,int *zremember,int *zhit,int *zx,int *zy)
{
     if(*zhit==0) *zhit=1;
     else
     {   
          *zhit=0;
          arr[*x][*y]=*zremember;
          }
    
    
     *zx=*x;
     *zy=*y;
     *zremember=arr[*x][*y];
     printf("제트리멤버 %d",*zremember);
     system("pause");
}
  
int main(void)
{
    int x;
    int y;
    int ch;
    int i;
    int j;
    int maxlen;
    int stagenum;
    int arr[100][100];
    char cur=-32;
    char oldcur;
    int space=0;
    int wall=1;
    int inwall=4;
    int my=2;
    int you=3;
    int move=5;
    int remember=space;
    int zx=0;
    int zy=0;
    int zhit=0;
    int zremember=0;

    FILE *fp=fopen("stage1.txt","r");
    if(fp==NULL)
    {  
        puts("파일오픈 실패!");
        return -1;
        }
   
    fscanf(fp,"%d", &maxlen);
    fscanf(fp,"%d", &stagenum);

   
    //데이터 읽음.   
    for(i=0;i<lencheak(maxlen);i++)
    {
         for(j=0;j<lencheak(maxlen);j++)
         {
             fscanf(fp,"%d", &ch);
             arr[i][j]=ch;
         }
    }
   
    //커서 세팅.
    x=lencheak(maxlen)/2;
    y=x;
    arr[x][y]=5;
   
   
   
    while(1)
    {
           
            system("cls");
    //데이터 출력.
    for(i=0;i<lencheak(maxlen);i++)
    {   
         for(j=0;j<lencheak(maxlen);j++)
         {   
              if(zhit==1 && zx==i && zy==j) printstr(6);
              else
              printstr(arr[i][j]);
         }
             
         printf("\n");
         }

         for(;;)
         {
              if(cur!=-32)
              oldcur=cur;
       
              cur=getch();
       
              if(cur!=-32)
              break;
        }
       
        arr[x][y]=remember;
        if((cur=='z' && arr[x][y]!=space) || (cur=='z' && zhit==1))
        movez(cur,arr,&x,&y,inwall,wall,&zremember,&zhit,&zx,&zy);
        else              
        movef(cur,arr,&x,&y,inwall,wall,&remember,&zhit,&zx,&zy);
       
        arr[x][y]=move;
       
    }//while end
 
    fclose(fp);
    system("pause");
    return 0;
}



List of Articles
번호 제목 글쓴이 날짜 조회 수
공지 글쓰기는 하루 5개, 댓글은 10개만 가능합니다. 좋은아빠되기 2019.02.15 299
공지 키보드 화살표값 출력 좋은아빠되기 2016.11.19 1079
공지 원하는 좌표에 값 출력하기 좋은아빠되기 2016.11.19 2394
공지 Python(파이썬) 학습 자료 PDF 1 file 좋은아빠되기 2014.12.10 10313
공지 dev C++ 텍스트 색상변경 WinApi사용(textcolor 대용) 좋은아빠되기 2014.06.07 4719
공지 DEV-C++ 기본 코드 좋은아빠되기 2013.06.19 8269
공지 무료 C++ 컴파일러(윈도우용) DEV-C++ 좋은아빠되기 2013.06.18 18956
공지 이클립스 C++ 설치 파일들 좋은아빠되기 2013.06.18 37861
410 정올 - 문제은행 - Red and Black(1154) 조정미 2018.07.14 197
409 정올 - 문제은행 - 십자 카드 문제(1018) - Time Limit Exceed 조정미 2018.07.07 256
408 정올 - 문제은행 - 닭장 전등 관리(1084) 조정미 2018.06.30 173
407 정올 - 문제은행 - 과자게임(1319) 조정미 2018.06.30 152
406 정올 - 문제은행 - 생성 불능 숫자(1184) 조정미 2018.06.23 92
405 정올 - 문제은행 - 종이 자르기(1067) 조정미 2018.06.23 229
404 정올 - 문제은행 - 성적 관리 프로그램(1086) 조정미 2018.06.23 408
403 정올 - 문제은행 - 가장 많이 나온 자연수(1069) 조정미 2018.06.23 262
402 정올 - 문제은행 - 내리막길(1024) - Time Limit Exceed 조정미 2018.06.23 202
401 정올 - 문제은행 - 강아지와 병아리(1001) 조정미 2018.06.23 656
400 정올 - 문제은행 - 도미노(1039) 조정미 2018.06.23 236
399 정올 - 실전대비 - 비밀번호(1344) 조정미 2018.06.16 186
398 정올 - 실전대비 - Duel(1312) 조정미 2018.06.09 51
397 정올 - 실전대비 - 개미수열(1354) - Runtime Error 조정미 2018.06.09 344
396 정올 - 실전대비 - 오류교정(1037) 조정미 2018.06.09 178
395 정올 - 실전대비 - RESETO(1232) 조정미 2018.06.02 155
394 정올 - 실전대비 - PERKET(1127) 조정미 2018.06.02 152
393 정올 - 실전대비 - 선 긋기 게임(1094) - Accepted(92) 조정미 2018.06.02 220
392 정올 - 실전대비 - 질량계산(1091) 조정미 2018.06.02 304
391 정올 - 실전대비 - 3가지 숫자 정렬하기(1016) 조정미 2018.06.02 284
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 26 Next
/ 26