디시인사이드 갤러리

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

갤러리 본문 영역

심심해서 테트리스 만드는 중인데 이거 왜이런지좀 알려줘 횽들

응잉앙앵(203.250) 2012.03.08 16:18:17
조회 94 추천 0 댓글 5

#include<iostream>
#include"windows.h"
#include"time.h"
using namespace std;

 int sys_play=1;
 unsigned char key=0;
 int framecount=0,PlayTime=0,score=0,up_press=0;
 
 int map[20][10]={0};
 int sub[20][10]={0};

int random(int x){return rand()%(x+1);}
class block{
public:
 unsigned short x,y,index,cell[5][5],maxcell;

 void step(){
  int i,j,check;
  check=1;
  y+=1;
  for(i=0;i<maxcell&✓i++)for(j=0;j<maxcell&✓j++){
   if(cell[i][j]==1&&(sub[y-1+i][x-1+j]==1||y-1+i>=20)){y-=1; check=0;}
  }
  for(i=0;i<maxcell;i++)for(j=0;j<maxcell;j++){
   if(cell[i][j]==1&&(sub[y+i][x-1+j]==1||y-0+i>=20)){stop(); break;}
  }
 }

 void stop(){
  int i,j;
  for(i=0;i<maxcell;i++)for(j=0;j<maxcell;j++){
   if(cell[i][j]==1&&y-1+i>=0){sub[y-1+i][x-1+j]=1;}
  }
  x=5;
  y=0;
  setting();
 }

 block(){
  x=5;
  y=0;
  maxcell=5;
  srand((unsigned)time(NULL));
  setting();
 }

 void setting(){
  int i,j;
  index=random(6);
  for(i=0;i<5;i++)for(j=0;j<5;j++){
   cell[i][j]=0;
  }
  switch(index)
  {
  case 0:
   cell[0][2]=1;
   cell[1][2]=1;
   cell[2][2]=1;
   cell[3][2]=1;
   break;
  case 1:
   cell[1][2]=1;
   cell[2][2]=1;
   cell[3][2]=1;
   cell[3][3]=1;
   break;
  case 2:
   cell[1][2]=1;
   cell[2][2]=1;
   cell[3][2]=1;
   cell[3][1]=1;
   break;
  case 3:
   cell[2][2]=1;
   cell[3][2]=1;
   cell[2][3]=1;
   cell[3][3]=1;
   break;
  case 4:
   cell[2][0]=1;
   cell[2][1]=1;
   cell[2][2]=1;
   cell[3][1]=1;
   break;
  case 5:
   cell[1][2]=1;
   cell[2][1]=1;
   cell[2][2]=1;
   cell[3][1]=1;
   break;
  case 6:
   cell[1][2]=1;
   cell[2][2]=1;
   cell[2][3]=1;
   cell[3][3]=1;
   break;
  }
 }
};

class turn{
public:
 int cell[5][5];
};

block instance;

void KeyInput(){
 key=0;
 if(GetAsyncKeyState(VK_ESCAPE)){
  cout<<"Game End"<<endl;
  sys_play=0;
 }
 if(GetAsyncKeyState(VK_UP)&&!up_press){
  int i,j,check;
  turn subblock;
  up_press++;
  check=1;
  while(check){
   for(i=0;i<instance.maxcell;i++)for(j=0;j<instance.maxcell;j++){
    subblock.cell[i][j]=instance.cell[i][j];
   }
   for(i=0;i<instance.maxcell;i++)for(j=0;j<instance.maxcell;j++){
    instance.cell[i][j]=subblock.cell[4-j][i];
   }
   check=0;
   for(i=0;i<instance.maxcell;i++)for(j=0;j<instance.maxcell;j++){
    if(instance.cell[i][j]==1){
     if(instance.x-1+j<0||instance.x-1+j>=10||instance.y-1+i>=20){check=1;}
     else{if(sub[instance.y-1+i][instance.x-1+j]==1){check=1;}}
    }
   }
  }
 }else{up_press=0;}
 if(GetAsyncKeyState(VK_RIGHT)){
  int i,j;
  instance.x+=1;
  for(i=0;i<instance.maxcell;i++)for(j=0;j<instance.maxcell;j++){
   if(instance.cell[i][j]==1&&(instance.x-1+j<0||instance.x-1+j>=10||sub[instance.y-1+i][instance.x-1+j]==1)){instance.x-=1;}
  }
 }
 if(GetAsyncKeyState(VK_LEFT)){
  int i,j;
  instance.x-=1;
  for(i=0;i<instance.maxcell;i++)for(j=0;j<instance.maxcell;j++){
   if(instance.cell[i][j]==1&&(instance.x-1+j<0||instance.x-1+j>=10||sub[instance.y-1+i][instance.x-1+j]==1)){instance.x+=1;}
  }
 }
 if(GetAsyncKeyState(VK_DOWN)){
  int i,j;
  instance.y+=1;
  for(i=0;i<instance.maxcell;i++)for(j=0;j<instance.maxcell;j++){
   if(instance.cell[i][j]==1&&(instance.y-1+i>=20||sub[instance.y-1+i][instance.x-1+j]==1)){instance.y-=1;}
  }
 }
}

void Draw();

void GamePlay(){

 PlayTime+=1;
 
 KeyInput();

 if(PlayTime%15==0)
 {
  instance.step();
 }

 Draw();
}

void Draw(){
 int i,j,check=0;

 for(i=0;i<20;i++)for(j=0;j<10;j++){
  map[i][j]=sub[i][j];
 }

 for(i=0;i<instance.maxcell;i++)for(j=0;j<instance.maxcell;j++){
  if(instance.cell[i][j]==1&&instance.y-1+i>=0&&instance.y-1+i<20&&instance.x-1+j<10)
   map[instance.y-1+i][instance.x-1+j]=1;
 }

 for(i=0;i<20;i++){
  check=1;
  for(j=0;j<10;j+=1){
   if(sub[i][j]==0){check=0;}
  }
  if(check){
   int k,l;
   score+=100;
   for(l=i;l>0;l--)
   {
    for(k=0;k<10;k++)
    {
     sub[l][k]=sub[l-1][k];
    }
   }
  }
 }

 [...];
 cout<<"Score : "<<score<<endl;
 cout<<"▒▒▒▒[TETRIS]▒▒▒▒"<<endl;
 for(i=0;i<20;i++){
  cout<<"▒";
  for(j=0;j<10;j++){
   if(map[i][j]==1){cout<<"■";}
   else{cout<<"  ";}
  }
  cout<<"▒"<<endl;
 }
 cout<<"▒▒▒▒▒▒▒▒▒▒▒▒"<<endl;
}

int main(){
 clock_t curtime, oldtime;

 oldtime=clock();
 framecount=0;

 while(sys_play) {
  GamePlay();

  //framework
  while(1){
   curtime=clock();
   if(curtime-oldtime>33){
    oldtime=curtime;
    break;
   }
  }
  framecount++;
 }
 return 0;
}






한번씩 왼쪽에 딱 못붙은 블럭들이 있음 ㅠㅠ

추천 비추천

0

고정닉 0

0

댓글 영역

전체 댓글 0
본문 보기

하단 갤러리 리스트 영역

왼쪽 컨텐츠 영역

갤러리 리스트 영역

갤러리 리스트
번호 제목 글쓴이 작성일 조회 추천
설문 뛰어난 운동 신경으로 남자와 싸워도 이길 것 같은 여자 스타는? 운영자 25/11/24 - -
AD 따뜻한 겨울나기! 방한용품 SALE 운영자 25/11/27 - -
306733 이거 아는횽 잇남 [7] 퐈이어애그갤로그로 이동합니다. 12.03.11 72 0
306732 정전이당!!!! 김호도갤로그로 이동합니다. 12.03.11 24 0
306730 OS 책보다가 드는 의문 [5] ㅎㅎㅎㅎㅎㅎ(211.117) 12.03.11 150 0
306729 빡스2D 써본형아없어? 김호도갤로그로 이동합니다. 12.03.11 33 0
306728 씨발 알바개같네 [5] CHALLENGER갤로그로 이동합니다. 12.03.11 98 0
306727 아무리 생각하고 찾아봐도 몰라서 여기에 질문합니다 - thread+통신 [3] ㅔㅔ(125.128) 12.03.11 88 0
306726 장기 알고리즘은 어떻게 구현하냐 [84] 으혀랴디(124.197) 12.03.11 361 0
306725 신기한 경험을 했다. [2] 116.44(203.229) 12.03.11 70 0
306724 과제 바로 다햇다 헤헤헤헤헤 [13] ㅈㅈㅈㅈ(118.47) 12.03.11 144 0
306723 ㅅㅂ 조까 내가 해결한다 ㅈㅈㅈㅈ(118.47) 12.03.11 33 0
306720 너님들은 컴터 포맷 얼마마다 함? [2] 아놔콘다갤로그로 이동합니다. 12.03.11 74 0
306719 군복무중에 보람찬일을 하고 싶어 프밍 공부중인데 고민 [1] 꼬비갤로그로 이동합니다. 12.03.11 47 0
306718 나 뭐 좀 물어볼께.... [1] 아놔콘다갤로그로 이동합니다. 12.03.11 61 0
306717 수학여행 용돈을 가장효율적으로 쓰는방법 항우(112.133) 12.03.11 63 0
306716 아..공부는 해야겠는데.... 왜이렇게..귀차니즘이 심할까.. 가람§도깨비갤로그로 이동합니다. 12.03.11 33 0
306714 아 진로걱정이막막혀 [2] CHALLENGER갤로그로 이동합니다. 12.03.11 68 0
306713 box2d 써본놈있냐. 김호도갤로그로 이동합니다. 12.03.11 33 0
306712 프로그래밍용 노트북에 대해서도와주세요ㅠㅠ 오늘구매예정 [11] 안녕하세요(183.99) 12.03.11 198 1
306711 너님들 오라클 쿼리에서 함수 쓰지 말고 비교 쿼리 어케 짜는줄 알어?? [2] 가람§도깨비갤로그로 이동합니다. 12.03.11 48 0
306710 2호선 잉여인간.swf [1] ㅁㄴㅇ(180.71) 12.03.11 103 0
306708 프로그래머 되려면.. [8] 김쫀쭈(220.121) 12.03.11 154 2
306707 어제 세번째 노트북 구입... ㅋ_ㅋ [1] .3(36.38) 12.03.11 87 0
306703 다시 질문좀요.. 미치겟슴이거 때매;;ㅠ 항우(112.133) 12.03.11 30 0
306702 랩터 기본 용어 같은거 양파같은색기(110.46) 12.03.11 43 0
306700 양파 [10] 항우(112.133) 12.03.11 65 0
306696 이렇게 순서도 짜면댐?? [2] 항우(121.189) 12.03.11 54 0
306695 Objective-C 독학하려는데 책 추천좀 pizzicato_갤로그로 이동합니다. 12.03.11 82 0
306693 아니 ㅅㅍ 걍 순서돈데 [5] 양파같은색기(110.46) 12.03.11 82 0
306691 다중상속 뭣점 물어보자 [5] 아잉(121.170) 12.03.11 94 0
306689 알고리즘 고수님들 질문좀!!! [12] 항우(112.133) 12.03.11 198 0
306688 뇌를자극하는 하드웨어 입문 이 책으로 하드웨어 기초 공부하면돼?? [10] 베짱이(118.44) 12.03.11 259 0
306687 여자 사람에게 이리 이애기해봐라 [1] 서현빠돌이갤로그로 이동합니다. 12.03.11 165 0
306683 컴공쪽도 취업할때 간판중요해?? [6] 뭐로하냐갤로그로 이동합니다. 12.03.11 280 0
306682 3가지의 값 비교 하는 방법 [6] 123(14.63) 12.03.11 90 0
306680 이거 이상한데 좀 봐주시겠습니까 [2] rnmn갤로그로 이동합니다. 12.03.11 68 0
306679 대문자야 [1] System32갤로그로 이동합니다. 12.03.11 88 0
306676 플게이형들은이시간에뭐해 [1] 중간점검갤로그로 이동합니다. 12.03.11 43 0
306674 머리에 피도 안 마른 것들이 왜 이클립스부터 쓰려 하냐? [4] 골빈사나이(121.167) 12.03.11 136 0
306671 md5 충돌 자주나요? [1] 빵신새끼갤로그로 이동합니다. 12.03.10 72 0
306670 Outlook에서 gmail 연동할 때 "등록된 폴더.." 오류 YCS(116.123) 12.03.10 67 0
306668 사전 데이터 베이스 연결하는 방법 아는횽있음? 마타버터갤로그로 이동합니다. 12.03.10 31 0
306663 거기 너, 덤벼라 [4] 정수정•‿•갤로그로 이동합니다. 12.03.10 114 0
306661 ARM CPU에 액티브 엑스 돌리는 방법 아는횽 있어? [2] 마타버터갤로그로 이동합니다. 12.03.10 78 0
306659 형들 비쥬얼스튜디오2010 쓰는형들 질문 ㅠㅠ [1] ㅋㅋㅋ(219.250) 12.03.10 86 0
306658 코딩 스타일 어떤게 보기 좋음? ㅇㅇㅇ? [13] ㅇㅇㅇ(121.144) 12.03.10 204 0
306657 이거 해결좀 해주라. [2] 히틀러킬러갤로그로 이동합니다. 12.03.10 71 0
306653 내일 기사시험이다 생각놀이갤로그로 이동합니다. 12.03.10 41 0
306648 시기보다 의지가 중요한거 아닐까 [2] ㄹㄹ(222.100) 12.03.10 78 0
306646 바다SDK 하려면 C/C++부터 마스터 해야됨? [3] 쀍쯊뛦꿲쒮갤로그로 이동합니다. 12.03.10 103 0
306645 두손가락짤 [5] 중간점검갤로그로 이동합니다. 12.03.10 127 0
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

디시미디어

디시이슈

1/2