俄罗斯方块C语言源代码(共74页).doc
《俄罗斯方块C语言源代码(共74页).doc》由会员分享,可在线阅读,更多相关《俄罗斯方块C语言源代码(共74页).doc(74页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、精选优质文档-倾情为你奉上俄罗斯方块C语言源代码.txt43风帆,不挂在桅杆上,是一块无用的布;桅杆,不挂上风帆,是一根平常的柱;理想,不付诸行动是虚无缥缈的雾;行动,而没有理想,是徒走没有尽头的路。44成功的门往往虚掩着,只要你勇敢去推,它就会豁然洞开。#include #include #include #include #include #ifdef _cplusplus #define _CPPARGS .#else#define _CPPARGS#endif#define MINBOXSIZE 15 /* 最小方块的尺寸 */#define BGCOLOR 7 /* 背景着色 */#
2、define GX 200#define GY 10#define SJNUM 10000 /* 每当玩家打到一万分等级加一级*/* 按键码*/#define VK_LEFT 0x4b00#define VK_RIGHT 0x4d00#define VK_DOWN 0x5000#define VK_UP 0x4800#define VK_HOME 0x4700#define VK_END 0x4f00#define VK_SPACE 0x3920#define VK_ESC 0x011b#define VK_ENTER 0x1c0d/* 定义俄罗斯方块的方向(我定义他为4种)*/#define
3、 F_DONG 0#define F_NAN 1#define F_XI 2#define F_BEI 3#define NEXTCOL 20 /* 要出的下一个方块的纵坐标*/#define NEXTROW 12 /* 要出的下一个方块的横从标*/#define MAXROW 14 /* 游戏屏幕大小*/#define MAXCOL 20#define SCCOL 100 /*游戏屏幕大显示器上的相对位置*/#define SCROW 60int gril2216; /* 游戏屏幕坐标*/int col=1,row=7; /* 当前方块的横纵坐标*/int boxfx=0,boxgs=0;
4、/* 当前寺块的形壮和方向*/int nextboxfx=0,nextboxgs=0,maxcol=22;/*下一个方块的形壮和方向*/int minboxcolor=6,nextminboxcolor=6;int num=0; /*游戏分*/int dj=0,gamedj10=18,16,14,12,10,8,6,4,2,1;/* 游戏等级*/* 以下我用了一个3维数组来纪录方块的最初形状和方向*/int boxstr7416=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
5、,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
6、,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
7、,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;/* 随机得到当前方块和下一个方块的形状和方向*/void boxrad()minboxcolor=nextminboxcolor;boxgs=nextboxgs;boxfx
8、=nextboxfx;nextminboxcolor=random(14)+1;if(nextminboxcolor=4|nextminboxcolor=7|nextminboxcolor=8)nextminboxcolor=9;nextboxfx=F_DONG;nextboxgs=random(7);/*初始化图形模试*/void init(int gdrive,int gmode)int errorcode;initgraph(&gdrive,&gmode,D:tc);errorcode=graphresult();if(errorcode!=grOk)printf(error of: %
9、s,grapherrormsg(errorcode);exit(1);/* 在图形模式下的清屏 */void cls()setfillstyle(SOLID_FILL,0);setcolor(0);bar(0,0,640,480);/*在图形模式下的高级清屏*/void clscr(int a,int b,int c,int d,int color)setfillstyle(SOLID_FILL,color);setcolor(color);bar(a,b,c,d);/*最小方块的绘制*/void minbox(int asc,int bsc,int color,int bdcolor)int
10、 a=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);/*游戏
11、中出现的文字*/void txt(int a,int b,char *txt,int font,int color)setcolor(color);settextstyle(0,0,font);outtextxy(a,b,txt);/*windows 绘制*/void win(int a,int b,int c,int d,int bgcolor,int bordercolor)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);/* 当前方块的
12、绘制*/void funbox(int a,int b,int color,int bdcolor)int i,j;int boxz44;for(i=0;i16;i+)boxzi/4i%4=boxstrboxgsboxfxi;for(i=0;i4;i+)for(j=0;j4;j+)if(boxzij=1)minbox(j+row+a)*MINBOXSIZE,(i+col+b)*MINBOXSIZE,color,bdcolor);/*下一个方块的绘制*/void nextfunbox(int a,int b,int color,int bdcolor)int i,j;int boxz44;for
13、(i=0;i16;i+)boxzi/4i%4=boxstrnextboxgsnextboxfxi;for(i=0;i4;i+)for(j=0;j1;i-)for(j=1;j15;j+)minbox(j*MINBOXSIZE,i*MINBOXSIZE,BGCOLOR,BGCOLOR);grilij=grili-1j;if(grilij=1)minbox(j*MINBOXSIZE,i*MINBOXSIZE,minboxcolor,0);/*消掉所有都有最小方块的行*/void delete()int i,j,zero,delgx=0;char *nm=00000;for(i=1;i21;i+)ze
14、ro=0;for(j=1;j15;j+)if(grilij=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);/*时间中断结束*/void KillTimer()disable();setvect(TIMER,oldhandler);enable();/* 测试当前方块是否可以向下落*/int downok()int i,
15、j,k=1,a44;for(i=0;i16;i+)ai/4i%4=boxstrboxgsboxfxi;for(i=0;i4;i+)for(j=0;j4;j+)if(aij & grilcol+i+1row+j)k=0;return(k);/* 测试当前方块是否可以向左行*/int leftok()int i,j,k=1,a44;for(i=0;i16;i+)ai/4i%4=boxstrboxgsboxfxi;for(i=0;i4;i+)for(j=0;j4;j+)if(aij & grilcol+irow+j-1)k=0;return(k);/* 测试当前方块是否可以向右行*/int righ
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 俄罗斯方块 语言 源代码 74
限制150内