디시인사이드 갤러리

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

갤러리 본문 영역

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

응잉앙앵(203.250) 2012.03.08 16:18:17
조회 92 추천 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 - -
이슈 [디시人터뷰] 충무로가 주목하는 신예, '세계의 주인' 서수빈 운영자 25/11/24 - -
AD 대학생 필수템! What's in my Bag 운영자 25/11/21 - -
306631 프로그래밍 중2부터 시작하면 늦은거임?/ [19] 항우(112.133) 12.03.10 211 0
306628 논리회로.. 장학금받고싶어요갤로그로 이동합니다. 12.03.10 127 0
306627 설마 주말인데 일하고 있냐??? 걸그룹 뮤비나 보자 서현빠돌이갤로그로 이동합니다. 12.03.10 35 0
306624 [꾸준한 질문글] 이제 1차원 배열 마지막 단계예요 ㅠㅠ [5] 엠엠데쓰갤로그로 이동합니다. 12.03.10 63 0
306623 알고리즘 배운지1달 정도되는데 이건 생각해봐도 모르겠다;; [5] 항우(112.133) 12.03.10 125 0
306622 함수형 언어 쓰는 사람 있음? [1] 아놔콘다갤로그로 이동합니다. 12.03.10 99 0
306620 이거 프로그래밍중 뭐야? [4] ㅇㅇ(1.176) 12.03.10 94 0
306619 친한여동생이 내게묻는다 CHALLENGER갤로그로 이동합니다. 12.03.10 70 0
306618 학점 21학점에 운동에 연애에 과외에 이게 어떻게 다 되지??? 에이시아(125.31) 12.03.10 62 0
306617 여러분들이 고1로 돌아간다면.. [5] 공립개나줘(114.206) 12.03.10 93 0
306616 1.#INF00 이거 인식하는 조건문 같은게 있나? [3] C++(125.129) 12.03.10 82 0
306614 형들 어셈블리에서 문자열 길이 얻는 방법이 뭐가 있을까요??? [1] SoliCode갤로그로 이동합니다. 12.03.10 41 0
306613 C++로 나노초 구할수 있냐 형들 [1] 근데(58.234) 12.03.10 64 0
306612 델파이나 오라클 배울수 있는곳 있나요? [2] ㅇㅇ(210.113) 12.03.10 62 0
306611 C언어로 뭔가 하고싶다... [4] 남대생.갤로그로 이동합니다. 12.03.10 111 0
306610 역시 프갤은 어떤 '상징' 과 같은 것이야. [1] 바보플머(218.155) 12.03.10 118 0
306609 왠지 좀 씁쓸하구만. 바보플머(218.155) 12.03.10 51 0
306608 multiprogramming 에서 [6] ㅁㄴㅇㄹ(211.117) 12.03.10 83 0
306607 피자한판 시켜줄테니까 운영체제 파트 하나 설명좀 해줄사람 [1] ㅁㄴㅇㄹ(211.117) 12.03.10 98 0
306606 질문있어요 [1] ㅇㅇ(119.197) 12.03.10 54 0
306605 아크로에디트는 c언어 컴파일 안되죠? [1] ㅇㅇ(210.113) 12.03.10 40 0
306604 죄송한데요; 12학번 대학생인데; 비쥬얼스튜디오 이거 왜그런거에요? [14] 브리쯔갤로그로 이동합니다. 12.03.10 227 0
306603 수학(?)이라는 언어에 대한 도전을 시작해 볼까? 바보플머(218.155) 12.03.10 85 0
306601 피자 두판을 세명이 나눠먹는 가장 효율적인 방법. [7] 바보플머(218.155) 12.03.10 190 0
306599 복수의 첨부파일 땡칠도사갤로그로 이동합니다. 12.03.10 43 0
306598 XPath 툴 땡칠도사갤로그로 이동합니다. 12.03.10 50 0
306596 동아리 들었는데 [1] 생물학(110.11) 12.03.10 62 0
306595 괴수님에게 도움을 요청함 [3] 갤러링(203.226) 12.03.10 69 0
306591 야밤에 C++ for문 질문.. [3] C++(125.129) 12.03.10 78 0
306590 아바님께 기사 낙방을 알려드림 [5] dot(114.202) 12.03.10 77 0
306589 형들, IT산업체 들가면 [1] 응잉앙앵(175.201) 12.03.10 121 0
306588 나의 이상한 타자법 [4] 품궈니갤로그로 이동합니다. 12.03.10 94 0
306587 우리학교는 메모장으로 코딩시킴 [3] elwlwlwk갤로그로 이동합니다. 12.03.10 266 0
306584 할일없는 프갤분들 꼬꼬마가 만든 테트리스하고 노세요 [7] 응잉앙앵(175.201) 12.03.09 112 0
306582 초기화되지않은 지역변수가 뭐임? [6] 마실나감갤로그로 이동합니다. 12.03.09 88 0
306579 형들은 하던일 정년 끝남 뭐할꺼? [1] Reki_갤로그로 이동합니다. 12.03.09 62 0
306578 형들 막간을 이용해 질문 좀 [6] (125.134) 12.03.09 41 0
306577 확장자. json 파일은 Json오브젝트 내용물임? [1] 공돌이대장갤로그로 이동합니다. 12.03.09 234 0
306576 로또 사러 간다 [2] 116.44(203.229) 12.03.09 49 0
306575 오늘 s/w 관리병 면접 후기 [7] 추상화갤로그로 이동합니다. 12.03.09 454 0
306574 성격 개싸가지인데 코딩실력있고, 성격진짜 좋고 완전회사 분위기조인데... [5] 신입(121.129) 12.03.09 135 0
306572 VC 6.0 강요하는 교수 [5] ㅂㅈㄷ(14.45) 12.03.09 134 0
306571 형들 문과로 교차지원 해서 [6] (114.203) 12.03.09 66 0
306570 가장큰 무부호 32비트 2진수는 무엇인가 이게 먼말이에요? [5] ㅇㅇ(58.127) 12.03.09 186 0
306569 형들 나에게 힘을줘.. 다른일하다가 30대 초반에 1년빡세게 학원다니고 [1] ㅇㅇ(1.253) 12.03.09 135 0
306568 연세대컴공의 패기에 지린경험 [1] ap(1.253) 12.03.09 879 1
306567 판다보드 파는데 아는분 있음? [4] 마타버터갤로그로 이동합니다. 12.03.09 60 0
306566 6비트 2의보수로 -32를 어떻게 씀? [8] 1231(211.226) 12.03.09 135 0
306564 이거 뭐가 잘못된다는거에요? [12] -(122.34) 12.03.09 113 0
306562 씨언어 파일질문점 [3] 중간점검갤로그로 이동합니다. 12.03.09 62 0
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

디시미디어

디시이슈

1/2