俄罗斯方块C语言源代码

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

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

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

资源描述

俄罗斯方块C语言源代码.txt逆风的方向,更适合飞翔。我不怕万人阻挡,只怕自己投降。你发怒一分钟,便失去60分钟的幸福。忙碌是一种幸福,让我们没时间体会痛苦;奔波是一种快乐,让我们真实地感受生活;疲惫是一种享受,让我们无暇空虚。生活就像呼吸呼是为出一口气,吸是为争一口气。#includestdio.h#includedos.h#includeconio.h#includegraphics.h#includestdlib.h#ifdef__cplusplus#define__CPPARGS...#else#define__CPPARGS#endif#defineMINBOXSIZE15/*最小方块的尺寸*/#defineBGCOLOR7/*背景着色*/#defineGX200#defineGY10#defineSJNUM10000/*每当玩家打到一万分等级加一级*//*按键码*/#defineVK_LEFT0x4b00#defineVK_RIGHT0x4d00#defineVK_DOWN0x5000#defineVK_UP0x4800#defineVK_HOME0x4700#defineVK_END0x4f00#defineVK_SPACE0x3920#defineVK_ESC0x011b#defineVK_ENTER0x1c0d/*定义俄罗斯方块的方向(我定义他为4种)*/#defineF_DONG0#defineF_NAN1#defineF_XI2#defineF_BEI3#defineNEXTCOL20/*要出的下一个方块的纵坐标*/#defineNEXTROW12/*要出的下一个方块的横从标*/#defineMAXROW14/*游戏屏幕大小*/#defineMAXCOL20#defineSCCOL100/*游戏屏幕大显示器上的相对位置*/#defineSCROW60intgril[22][16];/*游戏屏幕坐标*/intcol=1,row=7;/*当前方块的横纵坐标*/intboxfx=0,boxgs=0;/*当前寺块的形壮和方向*/intnextboxfx=0,nextboxgs=0,maxcol=22;/*下一个方块的形壮和方向*/intminboxcolor=6,nextminboxcolor=6;intnum=0;/*游戏分*/intdj=0,gamedj[10]={18,16,14,12,10,8,6,4,2,1};/*游戏等级*//*以下我用了一个3维数组来纪录方块的最初形状和方向*/intboxstr[7][4][16]={{{1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0},{0,1,0,0,1,1,0,0,1,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,0,0,1,1,0,0,1,0,0,0,0,0,0,0}},{{0,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0},{1,0,0,0,1,1,0,0,0,1,0,0,0,0,0,0},{0,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0},{1,0,0,0,1,1,0,0,0,1,0,0,0,0,0,0}},{{1,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0},{1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0},{1,0,0,0,1,0,0,0,1,1,0,0,0,0,0,0},{0,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0}},{{1,1,0,0,1,0,0,0,1,0,0,0,0,0,0,0},{1,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0},{0,1,0,0,0,1,0,0,1,1,0,0,0,0,0,0},{1,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0}},{{0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0},{0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0},{0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0},{0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0}},{{1,1,0,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},{1,1,0,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}},{{0,0,0,0,1,1,1,0,0,1,0,0,0,0,0,0},{1,0,0,0,1,1,0,0,1,0,0,0,0,0,0,0},{0,1,0,0,1,1,1,0,0,0,0,0.0,0,0,0},{0,1,0,0,1,1,0,0,0,1,0,0,0,0,0,0}}};/*随机得到当前方块和下一个方块的形状和方向*/voidboxrad(){minboxcolor=nextminboxcolor;boxgs=nextboxgs;boxfx=nextboxfx;nextminboxcolor=random(14)+1;if(nextminboxcolor==4||nextminboxcolor==7||nextminboxcolor==8)nextminboxcolor=9;nextboxfx=F_DONG;nextboxgs=random(7);}/*初始化图形模试*/voidinit(intgdrive,intgmode){interrorcode;initgraph(&gdrive,&gmode,D:\\tc\\);errorcode=graphresult();if(errorcode!=grOk){printf(errorof:%s,grapherrormsg(errorcode));exit(1);}}/*在图形模式下的清屏*/voidcls(){setfillstyle(SOLID_FILL,0);setcolor(0);bar(0,0,640,480);}/*在图形模式下的高级清屏*/voidclscr(inta,intb,intc,intd,intcolor){setfillstyle(SOLID_FILL,color);setcolor(color);bar(a,b,c,d);}/*最小方块的绘制*/voidminbox(intasc,intbsc,intcolor,intbdcolor){inta=0,b=0;a=SCCOL+asc;b=SCROW+bsc;clscr(a+1,b+1,a-1+MINBOXSIZE,b-1+MINBOXSIZE,color);if(color!=BGCOLOR){setcolor(bdcolor);line(a+1,b+1,a-1+MINBOXSIZE,b+1);line(a+1,b+1,a+1,b-1+MINBOXSIZE);line(a-1+MINBOXSIZE,b+1,a-1+MINBOXSIZE,b-1+MINBOXSIZE);line(a+1,b-1+MINBOXSIZE,a-1+MINBOXSIZE,b-1+MINBOXSIZE);}}/*游戏中出现的文字*/voidtxt(inta,intb,char*txt,intfont,intcolor){setcolor(color);settextstyle(0,0,font);outtextxy(a,b,txt);}/*windows绘制*/voidwin(inta,intb,intc,intd,intbgcolor,intbordercolor){clscr(a,b,c,d,bgcolor);setcolor(bordercolor);line(a,b,c,b);line(a,b,a,d);line(a,d,c,d);line(c,b,c,d);}/*当前方块的绘制*/voidfunbox(inta,intb,intcolor,intbdcolor){inti,j;intboxz[4][4];for(i=0;i16;i++)boxz[i/4][i%4]=boxstr[boxgs][boxfx][i];for(i=0;i4;i++)for(j=0;j4;j++)if(boxz[i][j]==1)minbox((j+row+a)*MINBOXSIZE,(i+col+b)*MINBOXSIZE,color,bdcolor);}/*下一个方块的绘制*/voidnextfunbox(inta,intb,intcolor,intbdcolor){inti,j;intboxz[4][4];for(i=0;i16;i++)boxz[i/4][i%4]=boxstr[nextboxgs][nextboxfx][i];for(i=0;i4;i++)for(j=0;j4;j++)if(boxz[i][j]==1)minbox((j+a)*MINBOXSIZE,(i+b)*MINBOXSIZE,color,bdcolor);}/*时间中断定义*/#defineTIMER0x1cintTimerCounter=0;voidinterrupt(*oldhandler)(__CPPARGS);voidinterruptnewhandler(__CPPARGS){TimerCounter++;oldhandler();}voidSetTimer(voidinterrupt(*IntProc)(__CPPARGS)){oldhandler=getvect(TIMER);disable();setvect(TIMER,IntProc);enable();}/*由于游戏的规则,消掉都有最小方块的一行*/voiddelcol(inta){inti,j;for(i=a;i1;i--)for(j=1;j15;j++){minbox(j*MINBOXSIZE,i*MINBOXSIZE,BGCOLOR,BGCOLOR);gril[i][j]=gril[i-1][j];if(gril[i][j]==1)minbox(j*MINBOXSIZE,i*MINBOXSIZE,minboxcolor,0);}}/*消掉所有都有最小方块的行*/voiddelete(){inti,j,zero,delgx=0;char*nm=00000;for(i=1;i21;i++){zero=0;for(j=1;j15;j++)if(gril[i][j]==0)zero=1;if(zero==0){delcol(i);delgx++;}}num=num+delgx*delgx*10;dj=num/10000;sprintf(nm,%d,num);clscr(456,173,500,200,4);txt(456,173,Number:,1,15);txt(456,193,nm,1,15);}/*时间中断结束*/voidKillTimer(){disable();setvect(TIMER,oldhandler);enable();}/*测试当前方块是否可以向下落*/intdownok(){inti,j,k=1,a[4][4];for(i=0;i16;i++)a[i/4][i%4]=boxstr[boxgs][boxfx][i];for(i=0;i4;i++)for(j=0;j4;j++)if(a[i][j]&&gril[col+i+1][row+j])k=0;return(k);}/*测试当前方块是否可以向左行*/intleftok(){inti,j,k=1,a[4][4];for(i=0;i16;i++)a[i/4][i%4]=boxstr[boxgs][boxfx][i];for(i=0;i4;i++)for(j=0;j4;j++)if(a[i]

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

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

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

×
保存成功