您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 信息化管理 > 俄罗斯方块C程序源代码
俄罗斯方块C程序源代码(好像有问题)typedefenumtetris_shape{ZShape=0,SShape,LineShape,TShape,SquareShape,LShape,MirroredLShape}shape;intmaxX();intminX();voidturn_left();voidturn_right();intout_of_table();voidtransform();intleftable();intrightable();intdownable();voidmove_left();voidmove_right();intadd_to_table();voidremove_full();voidnew_game();voidrun_game();voidnext_shape();intrandom(intseed);voidpaint();voiddraw_table();voidkey_down(WPARAMwParam);voidresize();voidinitialize();voidfinalize();LRESULTCALLBACKWndProc(HWND,UINT,WPARAM,LPARAM);#includewindows.h#includetime.h#includestdio.h#includetetris.h#defineAPP_NAMETETRIS#defineAPP_TITLETetrisGame#defineGAMEOVERGAMEOVER#defineSHAPE_COUNT7#defineBLOCK_COUNT4#defineMAX_SPEED5#defineCOLUMS10#defineROWS20#defineREDRGB(255,0,0)#defineYELLOWRGB(255,255,0)#defineGRAYRGB(128,128,128)#defineBLACKRGB(0,0,0)#defineWHITERGB(255,255,255)#defineSTONERGB(192,192,192)#defineCHARS_IN_LINE14#defineSCORESCORE%4dcharscore_char[CHARS_IN_LINE]={0};char*press_enter=PressEnterkey...;char*help[]={Pressspaceorupkeytotransformshape.,Pressleftorrightkeytomoveshape.,Pressdownkeytospeedup.,Pressenterkeytopausegame.,Enjoyit.O_omadebyC.X.,0};enumgame_state{game_start,game_run,game_pause,game_over}state=game_start;COLORREFshape_color[]={RGB(255,0,0),RGB(0,255,0),RGB(0,0,255),RGB(255,255,0),RGB(0,255,255),RGB(255,0,255),RGB(255,255,255),};intshape_coordinate[SHAPE_COUNT][BLOCK_COUNT][2]={{{0,-1},{0,0},{-1,0},{-1,1}},{{0,-1},{0,0},{1,0},{1,1}},{{0,-1},{0,0},{0,1},{0,2}},{{-1,0},{0,0},{1,0},{0,1}},{{0,0},{1,0},{0,1},{1,1}},{{-1,-1},{0,-1},{0,0},{0,1}},{{1,-1},{0,-1},{0,0},{0,1}}};intscore=0;shapenext=0;shapecurrent=0;intcurrent_coordinate[4][2]={0};inttable[ROWS][COLUMS]={0};intshapex=0;intshapey=0;intspeed=0;clock_tstart=0;clock_tfinish=0;HWNDgameWND;HBITMAPmemBM;HBITMAPmemBMOld;HDCmemDC;RECTclientRC;HBRUSHblackBrush;HBRUSHstoneBrush;HBRUSHshapeBrush[SHAPE_COUNT];HPENgrayPen;HFONTbigFont;HFONTsmallFont;intmaxX(){inti=0;intx=current_coordinate[i][0];intm=x;for(i=1;iBLOCK_COUNT;i++){x=current_coordinate[i][0];if(mx){m=x;}}returnm;}intminX(){inti=0;intx=current_coordinate[i][0];intm=x;for(i=1;iBLOCK_COUNT;i++){x=current_coordinate[i][0];if(mx){m=x;}}returnm;}voidturn_left(){inti=0;intx,y;for(i=0;i4;i++){x=current_coordinate[i][0];y=current_coordinate[i][1];current_coordinate[i][0]=y;current_coordinate[i][1]=-x;}}voidturn_right(){inti=0;intx,y;for(i=0;i4;i++){x=current_coordinate[i][0];y=current_coordinate[i][1];current_coordinate[i][0]=-y;current_coordinate[i][1]=x;}}intout_of_table(){inti=0;intx,y;for(i=0;i4;i++){x=shapex+current_coordinate[i][0];y=shapey+current_coordinate[i][1];if(x0||x(COLUMS-1)||y(ROWS-1)){return1;}if(table[y][x]){return1;}}return0;}voidtransform(){if(current==SquareShape){return;}turn_right();if(out_of_table()){turn_left();}}intleftable(){inti=0;intx,y;for(i=0;i4;i++){x=shapex+current_coordinate[i][0];y=shapey+current_coordinate[i][1];if(x=0||table[y][x-1]==1){return0;}}return1;}intrightable(){inti=0;intx,y;for(i=0;i4;i++){x=shapex+current_coordinate[i][0];y=shapey+current_coordinate[i][1];if(x=(COLUMS-1)||table[y][x+1]==1){return0;}}return1;}intdownable(){inti=0;intx,y;for(i=0;i4;i++){x=shapex+current_coordinate[i][0];y=shapey+current_coordinate[i][1];if(y=(ROWS-1)||table[y+1][x]==1){return0;}}return1;}voidmove_left(){if(leftable()){shapex--;}}voidmove_right(){if(rightable()){shapex++;}}voidmove_down(){if(downable()){shapey++;}else{if(add_to_table()){remove_full();next_shape();}else{state=game_over;}}}intadd_to_table(){inti=0;intx,y;for(i=0;i4;i++){x=shapex+current_coordinate[i][0];y=shapey+current_coordinate[i][1];if(y0||table[y][x]==1){return0;}table[y][x]=1;}return1;}voidremove_full(){intc=0;inti,j;for(i=ROWS-1;i0;i--){c=0;for(j=0;jCOLUMS;j++){c+=table[i][j];}if(c==COLUMS){memmove(table[1],table[0],sizeof(int)*COLUMS*i);memset(table[0],0,sizeof(int)*COLUMS);score++;speed=(score/100)%MAX_SPEED;i++;}elseif(c==0){break;}}}voidnew_game(){memset(table,0,sizeof(int)*COLUMS*ROWS);start=clock();next=random(SHAPE_COUNT);score=0;speed=0;}voidrun_game(){finish=clock();if((finish-start)(MAX_SPEED-speed)*100){move_down();start=clock();InvalidateRect(gameWND,NULL,TRUE);}}voidnext_shape(){current=next;memcpy(current_coordinate,shape_coordinate[next],sizeof(int)*BLOCK_COUNT*2);shapex=(COLUMS-((maxX(current)-minX(current))))/2;shapey=0;next=random(SHAPE_COUNT);}intrandom(intseed){if(seed==0){return0;}srand((unsigned)time(NULL));return(rand()%seed);}voidpaint(){PAINTSTRUCTps;HDChdc;draw_table();hdc=BeginPaint(gameWND,&ps);BitBlt(hdc,clientRC.left,clientRC.top,clientRC.right,clientRC.bottom,memDC,0,0,SRCCOPY);EndPaint(gameWND,&ps);}voiddraw_table(){HBRUSHhBrushOld;HPENhPenOld;HFONThFontOld;RECTrc;intx0,y0,w;intx,y,i,j;char*str;w=clientRC.bottom/(ROWS+2);x0=y0=w;FillRect(memDC,&clientRC,blackBrush);if(state==game_start||state==game_over){memcpy(&rc,&clientRC,sizeof(RECT));rc.bottom=rc.bottom/2;hFontOld=SelectObject(memDC,bigFont);SetBkColor(memDC,BLACK);if(state==game_start){st
本文标题:俄罗斯方块C程序源代码
链接地址:https://www.777doc.com/doc-3365333 .html