2014.05.24 12:46

작대기 그리기 함수

조회 수 943 추천 수 0 댓글 0

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
void show(int arr[10][10])
{
     system("cls");
     int i,j;
     for(i=0;i<10;i++)
    { 
       for(j=0;j<10;j++)
       {  
           printf("%c ",arr[i][j]);
         
       }
        printf("\n");
    }  
}


void changij(int arr[10][10], int *pi, int *pj, char *ch, char *oldch, char *store, char *wall, int *k, char *inwall, char *point, int mode)
{
             if(*ch==*oldch)
             {
                 if(*k==1)
                 {    
                       if(mode==1 || mode==2)
                       {   
                           if(*pi==0)
                           arr[*pi][*pj]=22;
                           else if(*pi==9)
                           arr[*pi][*pj]=21;
                           else
                           arr[*pi][*pj]=16;
                       }
                       else
                       {  
                           if(*pj==0)
                           arr[*pi][*pj]=25;
                           else if(*pj==9)
                           arr[*pi][*pj]=23;
                           else
                           arr[*pi][*pj]=16;
                       }
                 }
                 else{
                     
                 if(mode==1 || mode==2) arr[*pi][*pj]='-';
                 else
                 arr[*pi][*pj]='|';
                
                 }
                
                 switch (mode){
                 case 1 :
                      *store=arr[*pi][*(pj)+1];//분석
                      if(*store!=*wall)(*pj)++; //분석
                      if(*store==' ' || *store=='-') *k=0; else *k=1;
                      break;

                 case 2 :
                      *store=arr[*pi][*(pj)-1];//분석
                      if(*store!=*wall)(*pj)--; //분석
                      if(*store==' ' || *store=='-') *k=0; else *k=1;
                      break;
                     
                 case 3 :
                      *store=arr[*(pi)-1][*pj];//분석
                      if(*store!=*wall)(*pi)--; //분석
                      if(*store==' ' || *store=='|') *k=0; else *k=1;
                      break;

                 case 4 :
                      *store=arr[*(pi)+1][*pj];//분석
                      if(*store!=*wall)(*pi)++; //분석
                      if(*store==' ' || *store=='|') *k=0; else *k=1;
                      break;

                      }
                    

//                     if(*store==' ' || *store=='-')*k=0; else *k=1;
                                         
                
             }//move

    
 }//changij
 
int main(void)
{
    char eat=' ';
    char inwall=' ';
    char point=15;
    int arr[10][10]={
        {eat,eat,eat,eat,eat,eat,eat,eat,eat,eat},
        {inwall,eat,eat,eat,inwall,eat,eat,eat,eat,eat},
        {inwall,eat,inwall,eat,inwall,eat,eat,eat,inwall,eat},
        {inwall,eat,eat,eat,inwall,eat,eat,inwall,eat,eat},
        {inwall,eat,inwall,eat,inwall,inwall,eat,eat,inwall,eat},
        {eat,eat,inwall,eat,eat,eat,eat,eat,inwall,eat},
        {eat,inwall,inwall,inwall,eat,inwall,inwall,eat,inwall,eat},
        {eat,eat,inwall,eat,eat,inwall,inwall,inwall,inwall,eat},
        {inwall,eat,inwall,inwall,eat,eat,eat,inwall,eat,eat},
        {inwall,inwall,inwall,inwall,inwall,inwall,eat,eat,eat,inwall}
        };
       
       
    inwall='*';
    int i=0, j=0;
    int pi=0, pj=0;
    char ch=-32;
    char store=eat;
    char wall=inwall;
    char oldch=14;
    int k=0;
    arr[pi][pj]=point;
    show(arr);
   
    for(;;)
    {
        if(ch!=-32)
        oldch=ch;
       
        ch=getch();
       
        if(ch==-32)
        continue;

        if((ch=='l' || ch==77) && pj<9)
        {
            point=62;          
            changij(arr, &pi, &pj, &ch, &oldch, &store, &wall, &k, &inwall, &point, 1);
    
         }//(ch=='l' || ch==77) && pj<9


        if((ch=='j' || ch==75) && pj>0)
        {
            point=60;
            changij(arr, &pi, &pj, &ch, &oldch, &store, &wall, &k, &inwall, &point, 2);

        }//if
        if((ch=='i' || ch==72) && pi>0)
        {
             point=30;
             changij(arr, &pi, &pj, &ch, &oldch, &store, &wall, &k, &inwall, &point, 3);
                 }//if 
        if((ch=='k' || ch==80) && pi<9)
        {
             point=31;
             changij(arr, &pi, &pj, &ch, &oldch, &store, &wall, &k, &inwall, &point, 4);
                 }//if            
       
       
        arr[pi][pj]=point;
        show(arr);         
         
         
          }//for

   
   
   
   
    system("pause");
    return 0;
}



List of Articles
번호 제목 글쓴이 날짜 조회 수
공지 글쓰기는 하루 5개, 댓글은 10개만 가능합니다. 좋은아빠되기 2019.02.15 588
공지 키보드 화살표값 출력 좋은아빠되기 2016.11.19 1365
공지 원하는 좌표에 값 출력하기 좋은아빠되기 2016.11.19 2681
공지 Python(파이썬) 학습 자료 PDF 1 file 좋은아빠되기 2014.12.10 10848
공지 dev C++ 텍스트 색상변경 WinApi사용(textcolor 대용) 좋은아빠되기 2014.06.07 5015
공지 DEV-C++ 기본 코드 좋은아빠되기 2013.06.19 8721
공지 무료 C++ 컴파일러(윈도우용) DEV-C++ 좋은아빠되기 2013.06.18 19264
공지 이클립스 C++ 설치 파일들 좋은아빠되기 2013.06.18 38154
89 정올 기초다지기(aD002-함수2) killerjack 2014.06.07 1117
88 정올 기초다지기(함수1-자가진단8) killerjack 2014.06.07 1392
87 정올 기초다지기(함수1-자가진단7) killerjack 2014.06.07 1211
86 정올 기초다지기(함수1-자가진단6) killerjack 2014.05.31 1455
85 정올 기초다지기(함수1-자가진단5) killerjack 2014.05.31 2605
84 정올 기초다지기(aA009-배열2 9) killerjack 2014.05.31 1324
83 정올 기초다지기(aA006-배열2 6) killerjack 2014.05.31 1212
82 정올 기초다지기(aA003-배열2 3) killerjack 2014.05.31 1433
81 정올 기초다지기(aA002-배열2 2) killerjack 2014.05.31 1291
80 정올 기초다지기(aA001-배열2 1) killerjack 2014.05.31 1445
79 정올 기초다지기(배열2-자가진단7) killerjack 2014.05.31 1515
78 정올 기초다지기(배열2-자가진단6) killerjack 2014.05.31 1438
77 정올 기초다지기(배열2-자가진단3) killerjack 2014.05.31 1589
76 정올 기초다지기 (배열2-자가진단2) killerjack 2014.05.31 1648
75 대문자 입력받아서 입력받은 횟수 출력하기 (정올 배열2-자기진단1) killerjack 2014.05.31 1717
74 작대기 그리기 노가다 killerjack 2014.05.24 1016
» 작대기 그리기 함수 killerjack 2014.05.24 943
72 별표 잡아먹기 killerjack 2014.05.17 1211
71 시계~~~ killerjack 2014.05.17 1381
Board Pagination Prev 1 ... 17 18 19 20 21 22 23 24 25 26 Next
/ 26