c语言俄罗斯方块视频(c语言俄罗斯方块源代码)

苏怡震
导读 大家好,乐天来为大家解答以下的问题,关于c语言俄罗斯方块视频,c语言俄罗斯方块源代码这个很多人还不知道,现在让我们一起来看看吧!1、 in

大家好,乐天来为大家解答以下的问题,关于c语言俄罗斯方块视频,c语言俄罗斯方块源代码这个很多人还不知道,现在让我们一起来看看吧!

1、#include #include #include #define mDRAW 5 #define mLINE 6 #define mADOWN 7 #define mGEN 8 #define mLEFT 75 #define mRIGHT 77 #define mSPACE 57 #define mDOWN 80 #define mESC 1 #define TIMEINT 2 #define MAXX 9 #define MAXY 30 #define BACKCOLOR BLACK #define WINX 50 #define WINY 470 #define GAP 6 #define AREAX (WINX+GAP) #define AREAY (WINY-GAP) #define BOXW 15 int oldarea[MAXY+1][MAXX]; int area[MAXY+1][MAXX]; int actW,actH,actX,actY; int curX,curY,curColor,curW,curH; int newX,newY,newColor,newW,newH; int active; int box[4][4]; int FORCOLOR; int MESSAGE; int BOX[7][4][4]={ { {1,1,1,1}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0} },{ {1,1,1,0}, {1,0,0,0}, {0,0,0,0}, {0,0,0,0} },{ {1,1,1,0}, {0,0,1,0}, {0,0,0,0}, {0,0,0,0} },{ {1,1,1,0}, {0,1,0,0}, {0,0,0,0}, {0,0,0,0} },{ {1,1,0,0}, {0,1,1,0}, {0,0,0,0}, {0,0,0,0} },{ {0,1,1,0}, {1,1,0,0}, {0,0,0,0}, {0,0,0,0} },{ {1,1,0,0}, {1,1,0,0}, {0,0,0,0}, {0,0,0,0} } }; void init(); void draw(); int genBox(); int getKey(); void lineFull(); int moveLeft(); int moveRight(); int moveDown(); int rotate(); int getW(); int getH(); void clearOldBox(); void putNewBox(); int collisionRotate(int box[][4]); void getMessage(); void dispatchMessage(); int timeCome(); void fallDown(); int gameOver(); main() { int i; init(); do { getMessage(); dispatchMessage(); } while(!gameOver()); getch(); closegraph(); } void getMessage() { if(MESSAGE) return; if(timeCome()) { MESSAGE=mADOWN; return; } if(bioskey(1)) { MESSAGE=bioskey(0)>>8; return; } } void dispatchMessage() { switch(MESSAGE) { case mLEFT: moveLeft();break; case mRIGHT: moveRight();break; case mADOWN: moveDown();break; case mSPACE: rotate();break; case mDOWN: fallDown(); break; case mDRAW: draw();break; case mLINE: lineFull();break; case mGEN: genBox();break; case mESC: closegraph(); exit(0); default: MESSAGE=0; } } void fallDown() { while(active) { moveDown(); draw(); } MESSAGE=mLINE; } int timeCome() { static long tm, old; tm=biostime(0,tm); if(tm-old=MAXX)curX=MAXX-1-curW; curY=MAXY-1-curH; newX=curX; newY=curY; actX=curX;actY=curY; actW=newW=curW; actH=newH=curH; active=1; if(collision(box)) return 0; putNewBox(); draw(); MESSAGE=0; return 1; } void lineFull() { int row,col, rowEnd,full,i,j; rowEnd=newY+newH; if(rowEnd>=MAXY-1) rowEnd=MAXY-2; for(row=newY; row<=rowEnd;) { full=1; for(col=0;colcurH? newH:curH; actW=curX+actH-newX; actX=newX; actY=newY; curX=newX; curY=newY; curW=newW; curH=newH; MESSAGE=mDRAW; return 1; } int getW() { int i,j; for(i=3;i>0;i--) for(j=0;j<4;j++) if(box[j][i]) return i; return 0; } int getH() { int i,j; for(j=3;j>0;j--) for(i=0;i<4;i++) if(box[j][i]) return j; return 0; } void clearOldBox() { int i,j; for(j=0;j<=curH; j++) for(i=0;i<=curW; i++) if(box[j][i]) area[curY+j][curX+i]=0; } void putNewBox() { int i,j; for(j=0;j<=newH;j++) for(i=0;i<=newW;i++) if(box[j][i]) area[newY+j][newX+i]=FORCOLOR; } int collision(int cbox[][4]) { int i,j; if(newX<0) return 1; if(newX+newW>=MAXX) return 1; if(newY<0) return 1; for(j=0;j<=newH;j++) for(i=0;i<=newW;i++) if(area[newY+j][newX+i]&&cbox[j][i]) return 1; return 0; } int collisionRotate(int cbox[][4]) { int i,j; if(newX+newW>=MAXX) newX=MAXX-1-newW; if(newY+newH>=MAXY) newY=MAXY-1-newH; if(collision(cbox)) return 1; for(i=0;i<=newW;i++) for(j=0;j<=newH;j++) if(area[newY+j][newX+i]) { newX-=newW-i+1; goto L; } L: return collision(cbox); } int gameOver() { if(!active &&(curY+curH>MAXY-3)) return 1; else return 0; }。

本文分享完毕,希望对大家有所帮助。

标签:

免责声明:本文由用户上传,如有侵权请联系删除!