디시인사이드 갤러리

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

갤러리 본문 영역

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

응잉앙앵(203.250) 2012.03.08 16:18:17
조회 91 추천 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 - -
306683 컴공쪽도 취업할때 간판중요해?? [6] 뭐로하냐갤로그로 이동합니다. 12.03.11 280 0
306682 3가지의 값 비교 하는 방법 [6] 123(14.63) 12.03.11 90 0
306680 이거 이상한데 좀 봐주시겠습니까 [2] rnmn갤로그로 이동합니다. 12.03.11 67 0
306679 대문자야 [1] System32갤로그로 이동합니다. 12.03.11 87 0
306676 플게이형들은이시간에뭐해 [1] 중간점검갤로그로 이동합니다. 12.03.11 42 0
306674 머리에 피도 안 마른 것들이 왜 이클립스부터 쓰려 하냐? [4] 골빈사나이(121.167) 12.03.11 135 0
306671 md5 충돌 자주나요? [1] 빵신새끼갤로그로 이동합니다. 12.03.10 71 0
306670 Outlook에서 gmail 연동할 때 "등록된 폴더.." 오류 YCS(116.123) 12.03.10 66 0
306668 사전 데이터 베이스 연결하는 방법 아는횽있음? 마타버터갤로그로 이동합니다. 12.03.10 31 0
306663 거기 너, 덤벼라 [4] 정수정•‿•갤로그로 이동합니다. 12.03.10 113 0
306661 ARM CPU에 액티브 엑스 돌리는 방법 아는횽 있어? [2] 마타버터갤로그로 이동합니다. 12.03.10 78 0
306659 형들 비쥬얼스튜디오2010 쓰는형들 질문 ㅠㅠ [1] ㅋㅋㅋ(219.250) 12.03.10 85 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 101 0
306645 두손가락짤 [5] 중간점검갤로그로 이동합니다. 12.03.10 127 0
306641 횽들은 코드 짤때 이렇게 함? [3] 생물학(211.234) 12.03.10 109 0
306639 ㅇㅇㅇ 중간점검갤로그로 이동합니다. 12.03.10 31 0
306638 예전에 프갤에 누가 별찍기 물어보길래 [2] ㅇㅇㅇ(211.117) 12.03.10 89 0
306634 내 친구중에 플밍완전 잘하는애가 있거등용.. [2] 항우(112.133) 12.03.10 148 0
306632 호솽 [1] 항우(112.133) 12.03.10 30 0
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 39 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
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

디시미디어

디시이슈

1/2