디시인사이드 갤러리

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

갤러리 본문 영역

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

응잉앙앵(203.250) 2012.03.08 16:18:17
조회 97 추천 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 - -
306959 뽀샵으로 피카츄 커브값 변경시켜봣음 ㅇㅁ(114.199) 12.03.13 83 0
306957 밑에 글 살춤이가 바보플머 이긴거? 생물학(203.226) 12.03.13 49 0
306955 형아들 [5] 빌어먹을야옹갤로그로 이동합니다. 12.03.13 68 0
306954 C 포인터가 어렵다던데 어디에서 어려워하면 되는거야? [4] ㅇㅁ(114.199) 12.03.13 151 0
306953 평소와 다르게 만들어주는 쿼리덕분에 머리 깨진다.. [1] SFCFS갤로그로 이동합니다. 12.03.13 54 0
306951 형들 왕초보인데 질문점... [5] ㅇㅇㅇ(61.106) 12.03.13 73 0
306947 형들 질문좀할깨 [2] ㅇㅇ(124.63) 12.03.13 47 0
306946 형들 똑같이 군대안갈라고 선택한거라도 VFV갤로그로 이동합니다. 12.03.13 62 0
306945 쿼리짜는데 화면에 있는 값을 SFCFS갤로그로 이동합니다. 12.03.13 33 0
306944 MFC로 이런 건 뭘로 만든 거냐? [1] ㅁㄴㄻㄹ갤로그로 이동합니다. 12.03.13 117 0
306943 뭔놈의 프로그램이 메모리 200G씩 써가면서 도나? [2] iljeomobolt갤로그로 이동합니다. 12.03.13 102 0
306942 쿄스케 봐라. [1] 바보플머(218.155) 12.03.13 45 0
306941 자랑처럼 들리는 것은 '사고의 기준차' 가 아니라 '복잡한 추론' 이다 [10] 바보플머(218.155) 12.03.13 111 0
306939 그 옛날에 프갤에 올라왔던 글인데 혹시 찾을수잇는사람있나? [1] 죄수(121.191) 12.03.13 63 0
306937 코드질문은아니니잠깐보고답변좀 [6] 나라용갤로그로 이동합니다. 12.03.13 70 0
306936 프로젝트는 망해가는데 회식한다... [2] 개떙보갤로그로 이동합니다. 12.03.13 126 0
306935 캠 하나로 2개 캠프로그램 실행문제좀 도와주세요 [2] ㄱㅋ(223.195) 12.03.13 41 0
306934 뉴비답게 공지부터 읽고 있는데요 [6] DeCoY갤로그로 이동합니다. 12.03.13 136 0
306932 ext4에 생성가능한 파일 갯수 아시는 횽 계세요? [2] 으흥(210.94) 12.03.13 75 0
306931 그런데 프로그래밍 입문 책으로 어떤게 좋나요? [2] DeCoY갤로그로 이동합니다. 12.03.13 105 0
306930 으아악 내일이 화이트데이 ㅡㅡ;; [3] 쿄스케갤로그로 이동합니다. 12.03.13 79 0
306929 오늘은 매우 기분이 좋아요 [4] DeCoY갤로그로 이동합니다. 12.03.13 100 0
306928 안뇽횽들 [4] 레브네인갤로그로 이동합니다. 12.03.13 85 0
306925 여기는 다들 능력자 인가보다.. [4] iljeomobolt갤로그로 이동합니다. 12.03.13 168 0
306923 자랑 좀 해보려고 한다.. [5] 아놔콘다갤로그로 이동합니다. 12.03.13 174 0
306922 나 병특인데 [3] 토페갤로그로 이동합니다. 12.03.13 142 0
306921 <h1>아! 내가 바보다!</h1> [1] 테스트(220.86) 12.03.13 36 0
306920 공비는 진리입니다 돌고래스피커갤로그로 이동합니다. 12.03.13 77 0
306918 공비인가 뭔가 왤케 잘난척해??? [9] 14114(203.246) 12.03.13 233 0
306917 비주얼베이직 asp 엑세스 3개를 연동하는데 yoexz(210.117) 12.03.13 82 0
306914 개발자들이여 지금 당장 일어나서 운동을 해라 [2] 서현빠돌이갤로그로 이동합니다. 12.03.13 136 0
306912 팩토리알 구하는게 무슨 의미가 있어??? [5] 에이시아(203.246) 12.03.13 168 0
306910 점심도 먹었는데 뮤비나 보며 잠을 깨자 서현빠돌이갤로그로 이동합니다. 12.03.13 33 0
306909 안녕하세요 늅늅 인사드려요 DeCoY갤로그로 이동합니다. 12.03.13 34 0
306908 돈조금줘도 배우고 경력쌓으러 회사 들어간다는 생각은 버려라 [1] NightWish갤로그로 이동합니다. 12.03.13 125 0
306907 SQLite 쿼리 질문입니다. Ynobe갤로그로 이동합니다. 12.03.13 44 0
306904 if 100개 정도 건너뛰는거 시간 오래 걸림? (c++) [3] ㅁㄴㅇ(61.251) 12.03.13 99 0
306902 박대기 ㅠ.ㅠ [1] iljeomobolt갤로그로 이동합니다. 12.03.13 50 0
306900 2년 9개월 SI 최저 연봉이 얼마임 ?? [5] 야요이갤로그로 이동합니다. 12.03.13 271 0
306898 프로그래머가 남들보다 좋은점 10가지 [1] 야요이갤로그로 이동합니다. 12.03.13 228 0
306895 프갤러들은 상상도 하지 못할 카톡.jpg [2] 바보플머(218.155) 12.03.13 166 0
306894 프갤러들은 절대할수없는 카톡.jpg [1] ㅇㅇ(211.208) 12.03.13 146 0
306893 고지보딩 [2] iljeomobolt갤로그로 이동합니다. 12.03.13 109 0
306892 보리차냠 봐라. [1] 바보플머(218.155) 12.03.13 63 0
306891 겨우 동전 11개 쌓아서 세계 신기록........ [1] D.B.Cooper갤로그로 이동합니다. 12.03.13 88 0
306890 컴퓨터 공부 어떻게 해야하는지 전반적으로 설명해주시면 너무 감사합니다. [4] 보리차냠갤로그로 이동합니다. 12.03.13 203 0
306889 오빠들 프로그래밍 기초 [6] Stay’갤로그로 이동합니다. 12.03.13 147 0
306888 고민덩어리 아이디만듬ㅎㅎ 프갤입갤 Volibear갤로그로 이동합니다. 12.03.13 33 0
306886 자바 끄딴거 왜 만들어 가지고 사람 힘들게 하지? iljeomobolt갤로그로 이동합니다. 12.03.13 80 0
306884 형들 연봉은 언제 올리는거임?? [8] D.B.Cooper갤로그로 이동합니다. 12.03.13 169 0
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

디시미디어

디시이슈

1/2