디시인사이드 갤러리

갤러리 이슈박스, 최근방문 갤러리

갤러리 본문 영역

누가 질문한건데...

warota(221.150) 2009.10.13 21:49:42
조회 112 추천 0 댓글 4



 아래 링크에서 퍼옴.


 제가 c공부 하다가 테트리스를 하게 되었는데... 변형해서 2인용으로 만들어야 하는데..

 

한쪽은 잘 내려오고 점수도 올라가는데

 

다른 한쪽은 도형이 아예 내려오지가 않네요..ㅋ

 

뭐가 잘못됬는지 좀 알려주세요

 

터보c로 돌립니다..

 

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

#define LEFT 75
#define RIGHT 77
#define UP 72
#define DOWN 80
#define ESC 27
#define a 97
#define d 100
#define w 119
#define s 115

void brick(int flag);
void brick1(int flag);
void nextbrick(int flag);
void nextbrick1(int flag);
void leftmove();
void rightmove();
int downmove();
void rotate();
void leftmove1();
void rightmove1();
int downmove1();
void rotate1();
int whataround(int, int);
void isfull();
int inkey();
void printstage();
void printstage1();
int whataround1(int, int);
void isfull1();
int inkey1();
void Cursor_ON();
void Cursor_OFF();
int tet[19][25];
int tet1[19][25];
int pat[9][40]=
{
 {0,0,2,0,4,0,-2,0,0,0,0,1,0,-1,0,-2,},
 {0,0,-2,0,0,-1,-2,-1,},
 {0,0,-2,0,0,-1,2,-1,0,0,0,1,-2,0,-2,-1,},
 {0,0,-2,-1,0,-1,2,0,0,0,-2,0,-2,1,0,-1,},
 {0,0,-2,0,2,0,0,0,0,1,0,-1,},
 {0,0,2,0,0,1,0,0,0,0,2,0,0,-1,0,0,0,0,-2,0,0,-1,0,0,0,0,-2,0,0,1,0,0},
 {0,0,0,-1,2,0,4,0,0,0,-2,0,0,-1,0,-2,0,0,-2,0,-4,0,0,1,0,0,2,0,0,1,0,2},
 {0,0,-2,0,-4,0,0,-1,0,0,-2,0,0,1,0,2,0,0,0,1,2,0,4,0,0,0,2,0,0,-1,0,-2},
 {0,0,-2,0,2,0,0,1,0,0,0,-1,0,1,2,0,0,0,-2,0,2,0,0,-1,0,0,-2,0,0,-1,0,1}
};
int pat1[9][40]=
{
 {0,0,2,0,4,0,-2,0,0,0,0,1,0,-1,0,-2,},
 {0,0,-2,0,0,-1,-2,-1,},
 {0,0,-2,0,0,-1,2,-1,0,0,0,1,-2,0,-2,-1,},
 {0,0,-2,-1,0,-1,2,0,0,0,-2,0,-2,1,0,-1,},
 {0,0,-2,0,2,0,0,0,0,1,0,-1,},
 {0,0,2,0,0,1,0,0,0,0,2,0,0,-1,0,0,0,0,-2,0,0,-1,0,0,0,0,-2,0,0,1,0,0},
 {0,0,0,-1,2,0,4,0,0,0,-2,0,0,-1,0,-2,0,0,-2,0,-4,0,0,1,0,0,2,0,0,1,0,2},
 {0,0,-2,0,-4,0,0,-1,0,0,-2,0,0,1,0,2,0,0,0,1,2,0,4,0,0,0,2,0,0,-1,0,-2},
 {0,0,-2,0,2,0,0,1,0,0,0,-1,0,1,2,0,0,0,-2,0,2,0,0,-1,0,0,-2,0,0,-1,0,1}
};

int brickpatnum[9]={2, 1, 2, 2, 2, 4, 4, 4, 4};
int brickpatnum1[9]={2, 1, 2, 2, 2, 4, 4, 4, 4};
int i, j, k, score, score1;
int newbrick, nowbrick, nowrot, newbrick1, nowbrick1, nowrot1;
int nowx, nowy, nowx1, nowy1;
int key, quitflag, key1, quitflag1;
long de, nowdelay, de1, nowdelay1;


main() {
 Cursor_OFF();
 nowdelay=50000;
 nowdelay1=40000;
 randomize();

 clrscr();
 score=0;
        score1=0;
 printstage();
 printstage1();
 newbrick=random(9);
 newbrick1=random(9);
 nextbrick(1);
 nextbrick1(1);
 for(;;){
  nextbrick(0);
  nowbrick=newbrick;
  newbrick=random(9);
  nextbrick(1);
  nowx=50;
  nowy=3;
  nowrot=0;
  brick(1);

  nextbrick1(0);
  nowbrick1=newbrick1;
  newbrick1=random(9);
  nextbrick1(1);
  nowx1=20;
  nowy1=3;
  nowrot1=0;
  brick1(1);
 if(whataround((nowx-30)/2, nowy-2)!=0){
  gotoxy(45, 15);
  printf("G A M E  O V E R");
  Cursor_ON();
  exit(0);
 }


 for(;;){
  if(downmove()==0)
   break;
   quitflag=0;
  for(de=0; de<nowdelay; de++){
   key=inkey();
   switch(key){
    case LEFT:
     leftmove();
     break;
    case UP:
     rotate();
     break;
    case RIGHT:
     rightmove();
     break;
    case DOWN:
     while(downmove());
      quitflag=1;
      de=nowdelay;
      break;
     case ESC:

     clrscr();
     Cursor_ON();
     exit(0);
     }
    }
    if(quitflag) break;
   }
 for(;;){
  if(downmove1()==0)
   break;
   quitflag1=0;
  for(de1=0; de1<nowdelay1; de1++){
   key1=inkey1();
   switch(key1){
    case \'a\':
     leftmove1();
     break;
    case \'w\':
     rotate1();
     break;
    case \'d\':
     rightmove1();
     break;
    case \'s\':
     while(downmove1());
      quitflag1=1;
      de1=nowdelay1;
      break;
     case ESC:

     clrscr();
     Cursor_ON();
     exit(0);
     }
    }
    if(quitflag1) break;
   }
  }
 }

 void printstage(){
  for(i=0; i<25; i++){
   gotoxy(i+41, 1);
   putch(0xcd);
   gotoxy(i+41, 25);
   putch(0xcd);
  }

  for(i=1; i<25; i++){
   gotoxy(41, i);
   putch(0xba);
   gotoxy(66, i);
   putch(0xba);
  }

  gotoxy(41, 1);
  putch(0xc9);
  gotoxy(66, 1);
  putch(0xbb);
  gotoxy(41, 25);
  putch(0xc8);
  gotoxy(66, 25);
  putch(0xbe);


  for(i=0; i<25; i++)
   for(j=5; j<19; j++)
    if(i==23 || j==5 || j==18)
     tet[j][i]=2;
    else
     tet[j][i]=0;

  gotoxy(70, 2);
  printf("NEXT");
  gotoxy(70, 10);
  printf("SCORE : %d ", score);


 }

 void printstage1(){
  for(i=0; i<25; i++){
   gotoxy(i+11, 1);
   putch(0xcd);
   gotoxy(i+11, 25);
   putch(0xcd);
  }

  for(i=1; i<25; i++){
   gotoxy(11, i);
   putch(0xba);
   gotoxy(36, i);
   putch(0xba);
  }


  gotoxy(11, 1);
  putch(0xc9);
  gotoxy(36, 1);
  putch(0xbb);
  gotoxy(11, 25);
  putch(0xc8);
  gotoxy(36, 25);
  putch(0xbe);


  for(i=0; i<25; i++)
   for(j=5; j<19; j++)
    if(i==23 || j==5 || j==18)
     tet1[j][i]=2;
    else
     tet1[j][i]=0;


  gotoxy(3, 2);
  printf("NEXT");
  gotoxy(1, 10);
  printf("SCORE : %d ", score1);
 }

 int inkey(void){
  if(kbhit())
   return getch();
 }
 int inkey1(void){
  if(kbhit())
   return getch();
 }

 void brick(int flag){
  char c;
  if(flag==0)
   c=\' \';
  else
   c=219;

  for(i=0; i<4; i++){
   gotoxy(nowx+pat[nowbrick][nowrot*8+i*2], nowy+pat[nowbrick][nowrot*8+i*2+1]);
   putch(c);
   putch(c);
  }
 }

 void nextbrick(int flag){
  char c;
  if(flag==0)
   c=\' \';
  else
   c=219;

  for(i=0; i<4; i++){
   gotoxy(73+pat[newbrick][i*2], 6+pat[newbrick][i*2+1]);
   putch(c);
   putch(c);
  }
 }
 void brick1(int flag){
  char c;
  if(flag==0)
   c=\' \';
  else
   c=219;

  for(i=0; i<4; i++){
   gotoxy(nowx1+pat1[nowbrick1][nowrot1*8+i*2], nowy1+pat1[nowbrick1][nowrot1*8+i*2+1]);
   putch(c);
   putch(c);
  }
 }

 void nextbrick1(int flag){
  char c;
  if(flag==0)
   c=\' \';
  else
   c=219;

  for(i=0; i<4; i++){
   gotoxy(6+pat1[newbrick1][i*2], 6+pat1[newbrick1][i*2+1]);
   putch(c);
   putch(c);
  }
 }
 int downmove() {
  if(whataround((nowx-30)/2, nowy-2+1)!=0){
   isfull();
   return 0;
  }
  brick(0);
  nowy++;
  brick(1);
  return 1;
 }

 void leftmove() {
  if(whataround((nowx-30)/2-1, nowy-2)!=0)
   return;
  brick(0);
  nowx-=2;
  brick(1);
 }

 void rightmove(){
  if(whataround((nowx-30)/2+1, nowy-2)!=0)
   return;
  brick(0);
  nowx+=2;
  brick(1);
 }

 void rotate() {
  int imsi, imsi2;
  imsi=nowrot;
  nowrot++;
  if(nowrot==brickpatnum[nowbrick])
   nowrot=0;
  if(whataround((nowx-30)/2, nowy-2)!=0){
   nowrot=imsi;
   return;
  }
  imsi2=nowrot;
  nowrot=imsi;
  brick(0);
  nowrot=imsi2;
  brick(1);
 }

     int downmove1() {
 if(whataround1((nowx1-30)/2, nowy1-2+1)!=0){
  isfull1();
  return 0;
 }
 brick1(0);
 nowy1++;
 brick1(1);
 return 1;
 }

 void leftmove1() {
  if(whataround1((nowx1-30)/2-1, nowy1-2)!=0)
   return;
  brick1(0);
  nowx1-=2;
  brick1(1);
 }

 void rightmove1(){
  if(whataround1((nowx1-30)/2+1, nowy1-2)!=0)
   return;
  brick1(0);
  nowx1+=2;
  brick1(1);
 }

 void rotate1() {
  int imsi, imsi2;
  imsi=nowrot1;
  nowrot1++;
  if(nowrot1==brickpatnum1[nowbrick1])
   nowrot1=0;
  if(whataround1((nowx1-30)/2, nowy1-2)!=0){
   nowrot1=imsi;
   return;
  }
  imsi2=nowrot1;
  nowrot1=imsi;
  brick1(0);
  nowrot1=imsi2;
  brick1(1);
 }

 int whataround(int x, int y) {
  k=0;
  for(i=0; i<4; i++){
   j=tet[x+pat[nowbrick][nowrot*8+i*2]/2]
     [y+pat[nowbrick][nowrot*8+i*2+1]];
   if(j>k)
   k=j;
  }
  return k;
 }

 void isfull() {
  int check, check2;
  for(i=0; i<4; i++)
   tet[(nowx-30)/2+pat[nowbrick][nowrot*8+i*2]/2]
   [nowy-2+pat[nowbrick][nowrot*8+i*2+1]]=1;
   check2=0;
  for(i=22; i>=0; i--){
   check=0;
   for(j=5; j<18; j++)
    if(tet[j][i]==0)
    check=1;

   if(check==0){
    score+=10;
    gotoxy(70, 10);
    printf("SCORE : %d ", score);
    check2=1;
    for(k=i-1; k>0; k--)
     for(j=1; j<13; j++)
      tet[j][k+1]=tet[j][k];
      i++;
   }
  }

  if(check2==0)
   return;
  for(i=0; i<23; i++)
   for(j=1; j<13; j++){
    gotoxy(j*2+30, i+2);
    if(tet[j][i]==0){
     putch(\' \');
     putch(\' \');
    }
    else {
     putch(219);
     putch(219);
    }
   }
  }

 int whataround1(int x, int y) {
  k=0;
  for(i=0; i<4; i++){
   j=tet1[x+pat1[nowbrick1][nowrot1*8+i*2]/2]
     [y+pat1[nowbrick1][nowrot1*8+i*2+1]];
   if(j>k)
   k=j;
  }
  return k;
 }

 void isfull1() {
  int check, check2;
  for(i=0; i<4; i++)
   tet1[(nowx1-30)/2+pat1[nowbrick1][nowrot1*8+i*2]/2]
   [nowy1-2+pat1[nowbrick1][nowrot1*8+i*2+1]]=1;
   check2=0;
  for(i=22; i>=0; i--){
   check=0;
   for(j=5; j<18; j++)
    if(tet1[j][i]==0)
    check=1;

   if(check==0){
    score1+=10;
    gotoxy(1, 10);
    printf("SCORE : %d ", score1);
    check2=1;
    for(k=i-1; k>0; k--)
     for(j=1; j<13; j++)
      tet1[j][k+1]=tet1[j][k];
      i++;
   }
  }

  if(check2==0)
   return;
  for(i=0; i<23; i++)
   for(j=1; j<13; j++){
    gotoxy(j*2+30, i+2);
    if(tet1[j][i]==0){
     putch(\' \');
     putch(\' \');
    }
    else {
     putch(219);
     putch(219);
    }
   }
  }
  void Cursor_ON() {
   union REGS r;
   r.h.ah=1;
   r.h.ch=15;
   r.h.cl=16;
   int86(0x10, &r, &r);
  }

  void Cursor_OFF() {
   union REGS r;
   r.h.ah=1;
   r.h.ch=17;
   r.h.cl=16;
   int86(0x10, &r, &r);
  }

추천 비추천

0

고정닉 0

0

원본 첨부파일 1

댓글 영역

전체 댓글 0
등록순정렬 기준선택
본문 보기

하단 갤러리 리스트 영역

왼쪽 컨텐츠 영역

갤러리 리스트 영역

갤러리 리스트
번호 제목 글쓴이 작성일 조회 추천
설문 힘들게 성공한 만큼 절대 논란 안 만들 것 같은 스타는? 운영자 24/06/10 - -
164118 니덜의 인터넷 활동은 감시당하고 있다능 [5] 오사카(221.153) 09.12.25 134 0
164117 아마존 drm 뚤렷다는데 메가스터디는 안뚤릴려낭..ㅋ 쿠쿠두두(121.169) 09.12.25 103 0
164115 ㅠㅠ이거왜안되요? rdbdr(118.127) 09.12.25 36 0
164114 scjp시험질문좀 123(116.126) 09.12.25 50 0
164109 올해 크리스마스는 분위기가 안산다 양희철갤로그로 이동합니다. 09.12.25 55 0
164108 누구 탓도 하지 말어 이것들아... [3] 오사카(221.153) 09.12.25 149 0
164104 독서실 또는 도서관에서 쓸만한 키보드 없나요? [6] Recursive갤로그로 이동합니다. 09.12.25 196 0
164103 크리스마스를 맞아 정전스킬을 시전합니다 [2] algo갤로그로 이동합니다. 09.12.25 62 0
164102 2009-12-25 01:20:30 씁쓸하구만... [1] ChiChi갤로그로 이동합니다. 09.12.25 80 0
164101 Ogre 엔진 공부하면 재밌음? [3] Rei@디씨갤로그로 이동합니다. 09.12.25 200 0
164100 메리 크리스마스~ algo갤로그로 이동합니다. 09.12.25 28 0
164099 충격의 점수 비교, 보급형과 고급형 [1] Vita500갤로그로 이동합니다. 09.12.25 166 0
164098 주예수 와쪄염 뿌우 'ㅅ') [4] JuEUS-U갤로그로 이동합니다. 09.12.25 102 0
164097 it기업 평균연봉과 근속 [4] 빕뱟뱟갤로그로 이동합니다. 09.12.25 377 0
164095 메리크리스마스 [1] 덕후♥로리갤로그로 이동합니다. 09.12.25 69 0
164094 열혈강의 C 주문했어 형들 ㅋㅋ [1] 우동국물갤로그로 이동합니다. 09.12.24 136 0
164093 난 잉여인가..? [4] ssonacy갤로그로 이동합니다. 09.12.24 102 0
164092 어떡해 일기 #16 :: 열혈강의 C 완독, 내일부터 프로젝트. [24] 어떡해갤로그로 이동합니다. 09.12.24 908 0
164091 횽들 저학점나왔는데 [1] ST(219.240) 09.12.24 93 0
164090 메리크리스마스 dolbak갤로그로 이동합니다. 09.12.24 17 0
164089 뉴스 보는 중인데.. [1] ㅁㄴㄷㄹㄴㅁ(119.193) 09.12.24 33 0
164087 오랬만에 팩토리얼을 돌렸는데, [1] Vita500갤로그로 이동합니다. 09.12.24 83 0
164086 형들 이제 막 프로그래밍을 공무하기 시작한 잉여야.. [9] 우동국물갤로그로 이동합니다. 09.12.24 180 0
164085 이정도는 되야 웃는다 cp(210.218) 09.12.24 60 0
164084 방송 사고 한번 모아볼까?.swf [1] 숙신갤로그로 이동합니다. 09.12.24 118 0
164083 캐꼬꼬닭 횽은 봅니다. 숙신갤로그로 이동합니다. 09.12.24 38 0
164082 저 횽아들~~~!!! c언어 공부하기 좋은 사이트 추천좀영!1 으흙흙갤로그로 이동합니다. 09.12.24 58 0
164081 큰일이다 독대(121.165) 09.12.24 32 0
164080 C 프로그래밍 간단한거좀 푸는데 도움좀주시면 정말감사드릴게요.. [2] AOL(121.141) 09.12.24 87 0
164078 이시간에 출석체크.. [6] 물속의다이아갤로그로 이동합니다. 09.12.24 61 0
164076 컴터공학으로 편입하는데 C++질문! [5] 도전자(125.135) 09.12.24 159 0
164075 리눅스 질문점여 ㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠ [2] 컴터강(211.193) 09.12.24 78 0
164074 내년에 34살 되는데 [1] dnpq(124.153) 09.12.24 114 0
164073 일하는 프갤러가 없다니? [1] 아주아슬갤로그로 이동합니다. 09.12.24 85 0
164072 미친 당나귀 밴드 이모군(210.218) 09.12.24 48 0
164071 웹 질문점 reverse-ajax [4] 덕후♥로리갤로그로 이동합니다. 09.12.24 112 0
164070 대륙의 쿨가이 LightEach갤로그로 이동합니다. 09.12.24 96 0
164068 NC소프트 전직원 아이폰지원 [1] Vita500갤로그로 이동합니다. 09.12.24 240 0
164067 학생이 가고 싶은 학교.jpg [1] 닭왔다~(110.8) 09.12.24 199 0
164066 여기는 사무실입니다. [1] DMW(143.248) 09.12.24 102 0
164063 대학 문제중 교수들이 주관식 채점할때 이런경우는 과연 점수를 획득가능할까 [4] werwerwe(118.218) 09.12.24 138 0
164062 횽아들 내가 정보보안관이 꿈인데 리버싱에 대해서 갈켜줄 횽 구해. [3] 씬입사원갤로그로 이동합니다. 09.12.24 117 0
164059 잘생긴 횽들 내 글 좀 봐죠 문맥[]=\"바닥(116.124) 09.12.24 46 0
164058 WIN API공부하려고 하는데 페졸드랑 WINDOW INTERNAL둘중에 [3] ㄴ윺(211.212) 09.12.24 89 0
164056 아이폰이 망해야 대한민국이 산다 [3] Vita500갤로그로 이동합니다. 09.12.24 160 0
164055 트래픽 초과.. Vita500갤로그로 이동합니다. 09.12.24 50 0
164054 타격왕의 진실 ㅎ3(112.222) 09.12.24 78 0
164053 여고생을 안아보고 싶다...swf 숙신갤로그로 이동합니다. 09.12.24 174 0
164052 마린 탄생의 위엄.swf [1] 숙신갤로그로 이동합니다. 09.12.24 126 0
164051 대학교재 솔루션 말야 [2] prismatic갤로그로 이동합니다. 09.12.24 90 0
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

뉴스

디시미디어

디시이슈

1/2