俄罗斯方块C语言代码Word文件下载.docx

上传人:b****6 文档编号:18889720 上传时间:2023-01-02 格式:DOCX 页数:9 大小:17.20KB
下载 相关 举报
俄罗斯方块C语言代码Word文件下载.docx_第1页
第1页 / 共9页
俄罗斯方块C语言代码Word文件下载.docx_第2页
第2页 / 共9页
俄罗斯方块C语言代码Word文件下载.docx_第3页
第3页 / 共9页
俄罗斯方块C语言代码Word文件下载.docx_第4页
第4页 / 共9页
俄罗斯方块C语言代码Word文件下载.docx_第5页
第5页 / 共9页
点击查看更多>>
下载资源
资源描述

俄罗斯方块C语言代码Word文件下载.docx

《俄罗斯方块C语言代码Word文件下载.docx》由会员分享,可在线阅读,更多相关《俄罗斯方块C语言代码Word文件下载.docx(9页珍藏版)》请在冰豆网上搜索。

俄罗斯方块C语言代码Word文件下载.docx

#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};

/*游戏等级*/

/*以下我用了一个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},

{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},

{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,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}},

{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,"

e:

\\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){

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;

i<

16;

i++)

boxz[i/4][i%4]=boxstr[boxgs][boxfx][i];

4;

for(j=0;

j<

j++)

if(boxz[i][j]==1)

minbox((j+row+a)*MINBOXSIZE,(i+col+b)*MINBOXSIZE,color,bdcolor);

/*下一个方块的绘制*/

voidnextfunbox(inta,intb,intcolor,intbdcolor){

boxz[i/4][i%4]=boxstr[nextboxgs][nextboxfx][i];

minbox((j+a)*MINBOXSIZE,(i+b)*MINBOXSIZE,color,bdcolor);

/*时间中断定义*/

#defineTIMER0x1c

intTimerCounter=0;

voidinterrupt(*oldhandler)(__CPPARGS);

voidinterruptnewhandler(__CPPARGS){

TimerCounter++;

oldhandler();

voidSetTimer(voidinterrupt(*IntProc)(__CPPARGS)){

oldhandler=getvect(TIMER);

disable();

setvect(TIMER,IntProc);

enable();

/*由于游戏的规则,消掉都有最小方块的一行*/

voiddelcol(inta){

for(i=a;

i>

1;

i--)

for(j=1;

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);

/*消掉所有都有最小方块的行*/

voiddelete(){

inti,j,zero,delgx=0;

char*nm="

00000"

;

for(i=1;

21;

i++){

zero=0;

if(gril[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(){

setvect(TIMER,oldhandler);

/*测试当前方块是否可以向下落*/

intdownok(){

inti,j,k=1,a[4][4];

a[i/4][i%4]=boxstr[boxgs][boxfx][i];

if(a[j]&

&

gril[col+i+1][row+j])

k=0;

return(k);

/*测试当前方块是否可以向左行*/

intleftok(){

gril[col+i][row+j-1])

/*测试当前方块是否可以向右行*/

intrightok(){

gril[col+i][row+j+1])

/*测试当前方块是否可以变形*/

intupok(){

a[i/4][i%4]=boxstr[boxgs][boxfx+1][i];

for(i=3;

=0;

for(j=3;

j>

j--)

gril[col+i][row+j])

/*当前方块落下之后,给屏幕坐标作标记*/

voidsetgril(){

inti,j,a[4][4];

funbox(0,0,minboxcolor,0);

if(a[j])

gril[col+i][row+j]=1;

col=1;

row=7;

/*游戏结束*/

voidgameover(){

for(i=20;

0;

minbox(j*MINBOXSIZE,i*MINBOXSIZE,2,0);

txt(103,203,"

GameOver"

3,10);

/*按键的设置*/

voidcall_key(intkeyx){

switch(keyx){

caseVK_DOWN:

{/*下方向键,横坐标加一。

*/

if(downok()){

col++;

else{

setgril();

nextfunbox(NEXTCOL,NEXTROW,4,4);

boxrad();

nextfunbox(NEXTCOL,NEXTROW,nextminboxcolor,0);

delete();

break;

caseVK_UP:

{/*上方向键,方向形状旋转90度*/

if(upok())

boxfx++;

if(boxfx>

3)

boxfx=0;

caseVK_LEFT:

{/*左方向键,纵坐标减一*/

if(leftok())

row--;

caseVK_RIGHT:

{/*右方向键,纵坐标加一*/

if(rightok())

row++;

caseVK_SPACE:

/*空格键,直接落到最后可以落到的们置*/

while(downok())

default:

txt(423,53,"

worngkey!

1,4);

txt(428,80,"

PleseEnterAnlyKeyAG!

getch()();

clscr(420,50,622,97,BGCOLOR);

/*时间中断开始*/

voidtimezd(void){

intkey;

SetTimer(newhandler);

for(;

){

if(bioskey

(1)){

key=bioskey(0);

funbox(0,0,BGCOLOR,BGCOLOR);

if(key==VK_ESC)

call_key(key);

if(TimerCounter>

gamedj[dj]){

TimerCounter=0;

else{

if(col==1){

gameover();

/*主程序开始*/

voidmain(void){

init(VGA,VGAHI);

cls();

/*屏幕坐标初始化*/

=MAXCOL+1;

=MAXROW+1;

gril[i][j]=0;

i++){

gril[i][0]=1;

gril[i][15]=1;

=MAXROW;

gril[0][j]=1;

gril[21][j]=1;

clscr(0,0,640,480,15);

win(1,1,639,479,4,15);

win(SCCOL+MINBOXSIZE-2,SCROW+MINBOXSIZE-2,SCCOL+15*MINBOXSIZE+2,SCROW+21*MINBOXSIZE+2,BGCOLOR,0);

nextboxgs=random(8);

nextboxfx=random(4);

txt(456,243,"

NextBox:

timezd();

KillTimer();

closegraph();

}

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 人文社科 > 设计艺术

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1