2017.04.01 12:09

핵맨

조회 수 246 추천 수 0 댓글 0

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <windows.h> 
void design(char (*a)[70], int f_maxr, int f_maxc, int dr, int dc);
void output(char (*a)[70], int f_maxr, int f_maxc, int *cnt);
int setcolor(int k);
int setsim(char (*a)[70], char (*p)[3], int x, int y, int k, int *cnt);
int removesim(char (*a)[70], int x, int y);
    
int main()
{
 char a[20][70];
    int maxr=40;
    int maxc=60;
    int cnt=0;
    
    int i, j;
    int r=10, c=35;
    char ch;
    char p[4][3] = { "▲",  "▼", "◀", "▶"};           
    int x=10, y=10, k=0;                 
                     
//디자인    
    design ( a, 20, 70, r, c);
//    setcolor(63);
//    setsim(a, p, 10, 10, 0);

    while(1) {
     y=(70+y)%70; x=(x+20)%20;
     
     if(y>=66) y=66;
     if(y<=2) y=2; 
     if(x<=1) x=1;
     if(x>=18) x=18;
     
     setsim(a, p, x, y, k, &cnt);
     
     output(a, 20, 70, &cnt);
     removesim(a, x, y);
     setcolor(7);
     
     ch=getch();
     if(ch==-32) ch=getch();
     
//     if(ch==75) {y=y-2; k=2;}
//     if(ch==77) {y=y+2; k=3;}
        int oldk=0; oldk=k;
        
        switch (ch) {
      case 72: 
            
     k=0;
     break;
      case 80: 
            
     k=1;
     break;
      case 75: 
           
     k=2;
     break;
      case 77: 
            
     k=3;
     break;
  }

     if(oldk==k) {
  
     switch (ch) {
      case 72: 
           x--; 
     
     break;
      case 80: 
           x++; 
     
     break;
      case 75: 
           y=y-2;
    
     break;
      case 77: 
           y=y+2; 
     
     break;
  }//switch
 }//if

     system("cls");
    }

    setcolor(15);
//출력

    
    return 0;
}//main

void design(char (*a)[70], int f_maxr, int f_maxc,int dr, int dc) 
{
 int i, j;
 
 for(i=0; i<f_maxr; i++) {
     for(j=0; j<f_maxc; j++) {

  a[i][j] ='A';
  if(i==0) a[i][j]='A';
  if(j==0 || j==f_maxc-1) a[i][j]='A';
  if(i==f_maxr-1) a[i][j]='A';
        }
    }
     
}

void output(char (*a)[70], int f_maxr, int f_maxc, int *cnt)
{ 
    int i, j; 
    
    for(i=0; i<20; i++) {
     setcolor((i%15)+1);
     
        for(j=0; j<70; j++) {
            printf("%c",a[i][j]);
        }
        printf("\n");
    }
    printf("cnt:%d", *cnt);
}


int setcolor(int k)
{
 HANDLE hConsole; 
 hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
 SetConsoleTextAttribute(hConsole, k);
 return 0;
}

int setsim(char (*a)[70], char (*p)[3], int x, int y, int k, int *cnt) 
{
 if(a[x][y]=='A') *cnt=*cnt+2;
 if(a[x][y]=='A') printf("찾음");
 a[x][y]=p[k][0];
 a[x][y+1]=p[k][1]; 
 
 return 0;
}

int removesim(char (*a)[70], int x, int y)
{
 a[x][y]=' ';
 a[x][y+1]=' ';
} 



List of Articles
번호 제목 글쓴이 날짜 조회 수
공지 글쓰기는 하루 5개, 댓글은 10개만 가능합니다. 좋은아빠되기 2019.02.15 318
공지 키보드 화살표값 출력 좋은아빠되기 2016.11.19 1100
공지 원하는 좌표에 값 출력하기 좋은아빠되기 2016.11.19 2411
공지 Python(파이썬) 학습 자료 PDF 1 file 좋은아빠되기 2014.12.10 10366
공지 dev C++ 텍스트 색상변경 WinApi사용(textcolor 대용) 좋은아빠되기 2014.06.07 4731
공지 DEV-C++ 기본 코드 좋은아빠되기 2013.06.19 8314
공지 무료 C++ 컴파일러(윈도우용) DEV-C++ 좋은아빠되기 2013.06.18 18975
공지 이클립스 C++ 설치 파일들 좋은아빠되기 2013.06.18 37874
310 정올 기초다지기(배열2-자가진단3) killerjack 2014.05.31 1572
309 정올 기초다지기(문자열2-자가진단2) killerjack 2014.09.27 831
308 정올 기초다지기(문자열1-자가진단9)ver 2. killerjack 2014.09.20 708
307 정올 기초다지기(문자열1-자가진단9)ver 1. killerjack 2014.09.20 686
306 정올 기초다지기(문자열1-자가진단8) killerjack 2014.09.20 505
305 정올 기초다지기(문자열1-자가진단7) killerjack 2014.09.20 568
304 정올 기초다지기(문자열1-자가진단6) killerjack 2014.09.20 727
303 정올 기초다지기(문자열1-자가진단5) killerjack 2014.09.20 413
302 정올 기초다지기(문자열1-자가진단4) killerjack 2014.09.20 573
301 정올 기초다지기(문자열1-자가진단2) killerjack 2014.09.20 584
300 정올 기초다지기(문자열1-자가진단1) killerjack 2014.09.20 590
299 정올 기초다지기(구조체-자가진단6) killerjack 2014.10.11 857
298 정올 기초다지기(구조체-자가진단5) killerjack 2014.10.11 513
297 정올 기초다지기(구조체-자가진단4) killerjack 2014.10.11 562
296 정올 기초다지기(구조체-자가진단3) killerjack 2014.10.11 310
295 정올 기초다지기(구조체-자가진단2) killerjack 2014.10.11 403
294 정올 기초다지기(aG005-포인터5) killerjack 2014.11.22 536
293 정올 기초다지기(aG004-포인터4) killerjack 2014.11.15 365
292 정올 기초다지기(aG003-포인터3) killerjack 2014.11.15 428
291 정올 기초다지기(aG002-포인터2) killerjack 2014.11.15 473
Board Pagination Prev 1 ... 6 7 8 9 10 11 12 13 14 15 ... 26 Next
/ 26