c语言编写俄罗斯方块源代码

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

#includestdio.h#includestdlib.h#includedos.h#includegraphics.h/*ͼÐκ¯Êý¿â*//*¶¨Òå°´¼üÂë*/#defineVK_LEFT0x4b00#defineVK_RIGHT0x4d00#defineVK_DOWN0x5000#defineVK_UP0x4800#defineVK_ESC0x011b#defineTIMER0x1c/*ÉèÖÃÖжϺÅ*//*¶¨Òå³£Á¿*/#defineMAX_BOX19/*×ܹ²ÓÐ19ÖÖÐÎ̬µÄÓÎÏ··½¿é*/#defineBSIZE20/*ÓÎÏ··½¿éµÄ±ß³¤ÊÇ20¸öÏñËØ*/#defineSys_x160/*ÏÔʾÓÎÏ··½¿é½çÃæµÄ×óÉϽÇx×ø±ê*/#defineSys_y25/*ÏÔʾÓÎÏ··½¿é½çÃæ×óÉϽÇy×ø±ê*/#defineHorizontal_boxs10/*ˮƽ·½ÏòÒÔС·½¿éΪµ¥Î»µÄ³¤¶È*/#defineVertical_boxs15/*´¹Ö±µÄ·½ÏòÒÔС·½¿éΪµ¥Î»µÄ³¤¶È£¬Ò²¾ÍÊÇ˵³¤ÊÇ15¸öС·½¿éµÄ³¤¶È*/#defineBegin_boxs_xHorizontal_boxs/2/*²úÉúµÚÒ»¸öÓÎÏ··½¿éʱ³öÏÖµÄÆäʵλÖÃ*/#defineFgColor0/*Ç°¾°ÑÕÉ«£¬ÈçÎÄ×Ö.2-green*/#defineBgColor3/*±³¾°ÑÕÉ«0-black*/#defineLeftWin_xSys_x+Horizontal_boxs*BSIZE+46/*ÓÒ±ß״̬À¸µÄx×ø±ê*/#definefalse0#definetrue1/*Òƶ¯µÄ·½Ïò*/#defineMoveLeft1#defineMoveRight2#defineMoveDown3#defineMoveRoll4/*ÒÔºó×ø±êµÄÿ¸öС·½¿é¿ÉÒÔ¿´×öÊÇÏñËصãÊÇBSIZE*BSIZEµÄÕý·½ÐÎ*//*¶¨ÒåÈ«¾Ö±äÁ¿*/intcurrent_box_numb;/*±£´æµ±Ç°ÓÎÏ··½¿é±àºÅ*/intCurbox_x=Sys_x+Begin_boxs_x*BSIZE,Curbox_y=Sys_y;/*x,yÊDZ£´æÓÎÏ··½¿éµÄµ±Ç°×ø±êµÄ*/intflag_newbox=false;/*ÊÇ·ñÒª²úÉúÐÂÓÎÏ··½¿éµÄ±ê¼Ç0*/intspeed=1;intscore=0;intspeed_step=30;voidinterrupt(*oldtime)(void);/////////////////////////////////////////////////////*Ö¸ÏòÔ­À´Ê±ÖÓÖжϴ¦Àí¹ý³ÌÈë¿ÚµÄÖжϴ¦Àíº¯ÊýÖ¸Õë*//*ÓÎÏ·µ×°å½á¹¹£¬±íʾÿ¸öС·½¿éËù¾ßÓеÄÊôÐÔ*/structBOARD{intvar;/*µ±Ç°×´Ì¬£¬Ö»ÓÐ0ºÍ1,1±íʾ´ËС·½¿éÒѾ­±»Õ¼ÓÃ*/intcolor;/*ÑÕÉ«£¬ÓÎÏ·µ×°åµÄÿ¸öС·½¿é¿ÉÒÔÓµÓв»Í¬µÄÑÕÉ«£¬ÒÔÔöÇ¿ÃÀ¹Û*/}Table_board[Vertical_boxs][Horizontal_boxs];/*ÓÎÏ··½¿é½á¹¹*/structSHAPE{charbox[2];/*Ò»¸ö×Ö½Ú=8λ£¬Ã¿ËÄλÀ´±íʾһ¸öÓÎÏ··½¿éµÄÒ»ÐУ¬È磺box[0]=0x88,box[1]=0xc0±íʾµÄÊÇ£º1000100011000000*/intcolor;/*ÿ¸öÓÎÏ··½¿éµÄÑÕÉ«*/intnext;/*ϸöÓÎÏ··½¿éµÄ±àºÅ*/};/*³õʼ»¯ÓÎÏ··½¿éÄÚÈÝ£¬¼´¶¨ÒåMAX-BOX¸öSHAPEÀàÐ͵ĽṹÊý×飬²¢³õʼ»¯*/structSHAPEshapes[MAX_BOX]={/*¡ö¡õ¡õ¡õ¡ö¡ö¡ö¡õ¡ö¡ö¡õ¡õ¡õ¡õ¡õ¡õ¡ö¡õ¡õ¡õ¡ö¡õ¡õ¡õ¡õ¡ö¡õ¡õ¡õ¡õ¡ö¡õ¡ö¡ö¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡ö¡õ¡õ¡ö¡ö¡ö¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡õ*/{0x88,0xc0,CYAN,1}{0xe8,0x0,CYAN,2}{0xc4,0x40,CYAN,3}{0x2e,0x0,CYAN,0}//¡õ¡ö¡õ¡õ¡ö¡õ¡õ¡õ¡ö¡ö¡õ¡õ¡ö¡ö¡ö¡õ//¡õ¡ö¡õ¡õ¡ö¡ö¡ö¡õ¡ö¡õ¡õ¡õ¡õ¡õ¡ö¡õ//¡ö¡ö¡õ¡õ¡õ¡õ¡õ¡õ¡ö¡õ¡õ¡õ¡õ¡õ¡õ¡õ//¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡õ{0x44,0xc0,MAGENTA,5},{0x8e,0x0,MAGENTA,6},{0xc8,0x80,MAGENTA,7},{0xe2,0x0,MAGENTA,4},//¡ö¡õ¡õ¡õ¡õ¡ö¡ö¡õ//¡ö¡ö¡õ¡õ¡ö¡ö¡õ¡õ//¡õ¡ö¡õ¡õ¡õ¡õ¡õ¡õ//¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡õ{0x8c,0x40,YELLOW,9},{0x6c,0x0,YELLOW,8},//¡õ¡ö¡õ¡õ¡ö¡ö¡õ¡õ//¡ö¡ö¡õ¡õ¡õ¡ö¡ö¡õ//¡ö¡õ¡õ¡õ¡õ¡õ¡õ¡õ//¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡õ{0x4c,0x80,BROWN,11},{0xc6,0x0,BROWN,10},//¡õ¡ö¡õ¡õ¡ö¡õ¡õ¡õ¡ö¡ö¡ö¡õ¡õ¡ö¡õ¡õ//¡ö¡ö¡ö¡õ¡ö¡ö¡õ¡õ¡õ¡ö¡õ¡õ¡ö¡ö¡õ¡õ//¡õ¡õ¡õ¡õ¡ö¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡ö¡õ¡õ//¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡õ{0x4e,0x0,WHITE,13},{0x8c,0x80,WHITE,14},{0xe4,0x0,WHITE,15},{0x4c,0x40,WHITE,12},//¡ö¡õ¡õ¡õ¡ö¡ö¡ö¡ö//¡ö¡õ¡õ¡õ¡õ¡õ¡õ¡õ//¡ö¡õ¡õ¡õ¡õ¡õ¡õ¡õ//¡ö¡õ¡õ¡õ¡õ¡õ¡õ¡õ{0x88,0x88,RED,17},{0xf0,0x0,RED,16},//¡ö¡ö¡õ¡õ//¡ö¡ö¡õ¡õ//¡õ¡õ¡õ¡õ//¡õ¡õ¡õ¡õ{0xcc,0x0,BlUE,18},};unsignedintTimerCounter=0;/*¶¨Ê±¼ÆÊýÆ÷±äÁ¿*/voidmain(){intGameOver=0;intkey,nextbox;intCurrentaction=0;/*±ê¼Çµ±Ç°¶¯×÷״̬*/intgd=VGA,gm=VGAHI,errorcode;initgraph(&gd,&gm,);errorcode=graphresult();if(errorcode!=grOK){printf(\nNotice:Graphicserror:%s\n,grapherrormsg(errorcode));printf(pressanykeytoquit!);getch();exit(1);}setbkcolor(Bgcolor);setcolor(FgColor);randomize();SetTimer(newtimer);initialize(Sys_x,Sys_y,Horizontal_boxs,Vertical_boxs);/*³õʼ»¯*/newbox=MKNextBox(-1);show_box(Curbox_x,Curbox_y,currentz_box_numb,shapes[current_box_numb].color);show_box(LeftWin_x,Curbox_y+200,nextbox,shapes[nextbox].color);show_help(Sys_x,Curbox_y+320);getch();while(1){Currentaction=0;flag_newbox=false;/*¼ì²âÊÇ·ñÓа´¼ü*/if(bioskey(1)){key=bioskey(0);}else{key=0;}switch(key){caseVK_LEFT:if(MoveAble(Curbox_x,Curbox_y,current_box_numb,MoveLeft)){EraseBox(Curbox_x,Curbox_y,current_box_numb);Curbox_x-=BSIZE;Currentaction=MoveLeft;}break;caseVK_RIGHT:if(MoveAble(Curbox_x,Curbox_y,current_box_numb,MoveRight)){EraseBox(Curbox_x,Curbox_y,current_box_numb);Curbox_x+=BSIZE;Currentaction=MoveRight;}break;caseVK_DOWN:if(MoveAble(Curbox_x,Curbox_y,current_box_numb,MoveDown)){EraseBox(Curbox_x,Curbox_y,current_box_numb);Curbox_y+=BSIZE;Currentaction=MoveDown;}elseflag_newbox=true;break;caseVK_UP:/*ÐýתÓÎÏ··½¿é*/if(MoveAble(Curbox_x,Curbox_y,shapes[current_box_numb].next,MoveRoll)){EraseBox(Curbox_x,Curbox_y,current_box_numb);current_box_numb=shapes[current_box_numb].next;Currentaction=MoveRoll;}break;caseVK_ESC:GameOver=1;break;default:break;}if(Currentaction){/*±íʾµ±Ç°Óж¯×÷£¬Òƶ¯»òת¶¯*/show_box(Curbox_x,Curbox_y,current_box_numb,shapes[current_box_numb].color);Currentaction=0;}/*°´ÁËÍùϼü£¬µ«²»ÄÜÏÂÒÆ£¬¾Í²úÉúеÄÓÎÏ··½¿é*/if(flag_newbox){/*ÕâʱÏ൱ÓÚÓÎÏ··½¿éµ½Á˵ײ¿£¬°ÑÆäÖгöÏÖµãÂúÒ»ÐеÄÇåÈ¥£¬ÖÃ0*/ErasePreBox(LeftWin_x,Sys_y+200,nextbox);nextbox=MkNextBox(nextbox);show_box(LeftWin_x,Curbox_y+200,nextbox,shapes[nextbox].color);if(!MoveAble(Curbox_x,Curbox_y,current_box_numb,MoveDown))/*¸ÕÒ»¿ªÊ¼£¬ÓÎÏ·½áÊø*/{show_box(Curbox_x,Curbox_y,current_box_numb,shapes[current_box_numb].color);GameOver=1;}else{flag_newbox=false;}Cu

1 / 17
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功