admin 管理员组文章数量: 887021
2024年3月1日发(作者:sizeof int 的值是)
俄罗斯方块C语言代码
#include
#include#include#include#ifdef uuuucplusplus
#define__#else
#定义_ucpargs#endif
#defineminboxsize15/*最小方块的尺寸*/#definebgcolor7/*背景着色*/
#定义200#定义10
#definesjnum10000/*每当玩家打到一万分等级加一级*//*按键码*/
#定义左0x4B00#定义右0x4D00#定义下0x5000#定义上0x4800
#definevk_home0x4700#definevk_end0x4f00#definevk_space0x3920#definevk_esc0x011b#definevk_enter0x1c0d
/*定义俄罗斯方块的方向(我把它定义为4)*/#definef_uuu0#definef_uu1#definef_u2#definef_3
#definenextcol20/*要出的下一个方块的纵坐标*/#definenextrow12/*要出的下一个方块的横从标*/#definemaxrow14/*游戏屏幕大小*/
#definemaxcol20
#definesccol100/*游戏屏幕大显示器上的相对位置*/#definescrow60
intgril[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};/*在游戏级别之下*//*我使用了一个三维组来记录盒子的初始形状和方向*/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;
如果(nextminboxcolor==4 | | nextminboxcolor==7 | | nextminboxcolor==8)nextminboxcolor=9;nextboxfx=f_2;dong;nextboxgs=random(7);}
/*初始化图形模试*/
voidinit(intgdrive,intgmode){interrocode;
initgraph(&gdrive,&gmode,
errorcode=graphresult();如果(错误代码!=grok){
printf(exit(1);}}
/*图形模式下的屏幕清除*/void CLS(){
setfillstyle(solid_fill,0);setcolor(0);
巴(0,0640480);}
/*在图形模式下的高级清屏*/
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!=bgcolor){setcolor(bdcolor);
line(a+1,b+1,a-1+minboxsize,b+1);
线路(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,字体);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;i<16;i++)
boxz[i/4][i%4]=boxstr[boxgs][boxfx][i];对于(i=0;i<4;i++)对于(j=0;j<4;j++)
if(boxz[i][j]==1)
minbox((j+row+a)*minboxsize,(i+col+b)*minboxsize,color,bdcolor);}
/*下一个方块的绘制*/
voidNextFunbX(inta,intb,intcolor,intbdcolor){inti,j;
intboxz[4][4];for(i=0;i<16;i++)
boxz[i/4][i%4]=boxstr[nextboxgs][nextboxfx][i];对于(i=0;i<4;i++)
for(j=0;j<4;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(定时器,intproc);启用();}
/*由于游戏的规则,消掉都有最小方块的一行*/voiddelcol(inta){
因蒂,j;
for(i=a;i>1;i--)for(j=1;j<15;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);}
版权声明:本文标题:俄罗斯方块C语言代码 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/jishu/1709282186h541896.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论