俄罗斯方块c语言程序带注释Word格式文档下载.docx

上传人:b****5 文档编号:16203424 上传时间:2022-11-21 格式:DOCX 页数:12 大小:18.17KB
下载 相关 举报
俄罗斯方块c语言程序带注释Word格式文档下载.docx_第1页
第1页 / 共12页
俄罗斯方块c语言程序带注释Word格式文档下载.docx_第2页
第2页 / 共12页
俄罗斯方块c语言程序带注释Word格式文档下载.docx_第3页
第3页 / 共12页
俄罗斯方块c语言程序带注释Word格式文档下载.docx_第4页
第4页 / 共12页
俄罗斯方块c语言程序带注释Word格式文档下载.docx_第5页
第5页 / 共12页
点击查看更多>>
下载资源
资源描述

俄罗斯方块c语言程序带注释Word格式文档下载.docx

《俄罗斯方块c语言程序带注释Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《俄罗斯方块c语言程序带注释Word格式文档下载.docx(12页珍藏版)》请在冰豆网上搜索。

俄罗斯方块c语言程序带注释Word格式文档下载.docx

0,0,0,0,1,0,0,0,1,1,0,0,1,0,0,0,0,0,0,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,

1,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,1,0,1,1,1,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,1,1,1,0,0,0,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,0,0,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,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,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,

};

/*方块模板*/

intshape,dir,next_shape,next_dir;

structposition

{

intx;

inty;

}now_position;

/*纪录现在方块的位置*/

intspeed_level=1;

intfall_to_land,be_lined;

/*判断方块是否着地的*/

/*----------------------------------------*/

voidclscreen();

voidsetxy(intx,inty);

voiddisplay_back();

voiddisplay_interface();

voiddisplay_fk(intx,inty,intshape,intdir);

voidinit();

//intgetkey();

/*取键盘的扫描码*/

voidgetinput();

voidm_sound(intfreq,inttime);

voideras_fk(intx,inty,intshape,intdir);

/*擦除方块*/

voidfk_down(boolquickly=false);

boolis_illegal(intx,inty,intchanged_dir);

/*判断方块移动后坐标是否非法,非法1,合法0*/

intget_random(intn);

/*生成一个0----n-1的随机数*/

voidcheck_line();

/*检查是否有行可以消去,如果有就消去*/

voidgame_over();

/*----------------------------------*/

intmain()

inti;

init();

while(true)

{

display_back();

now_position.x=10;

now_position.y=2;

/*复原初始坐标*/

be_lined=0;

/*一个方块刚出现时没有成行*/

shape=next_shape;

dir=next_dir;

next_shape=get_random(7);

next_dir=get_random(4);

eras_fk(55,5,shape,dir);

/*擦去前一个方块*/

display_fk(55,5,next_shape,next_dir);

/*显示下一个方块*/

display_fk(now_position.x,now_position.y,shape,dir);

/*显示目前方块*/

fall_to_land=0;

while(!

fall_to_land)

for(i=15000-1500*speed_level;

i>

0;

i--)

getinput();

}/*接受键盘输入*/

fk_down();

/*方块自动下落*/

}

//m_sound(350,500);

/*块落下的声音*/

check_line();

/*检查有没有可消去的行*/

if(be_lined)

m_sound(250,1000);

else

m_sound(350,500);

}

return0;

}

/*------------------------------------*/

voidinit()

inti,j;

for(i=0;

i<

20;

i++)

for(j=0;

j<

10;

j++)

background[i][j]=0;

/*背景数组赋初值0*/

next_shape=(get_random(7)+5)/7;

next_dir=(get_random(4)+2)/4;

/*预先产生一个方块*/

display_interface();

/*画界面*/

voiddisplay_interface()

clscreen();

setxy(40,5);

printf("

TheNext:

"

);

setxy(1,1);

/*-----------------------------------------*/

voiddisplay_back()/*显示背景*/

setxy(2*(j+1),i+2);

/*数组下标到屏幕坐标的变换*/

if(!

background[i][j])/*背景数组中值为0*/

[]"

/*---------------------------------------*/

voiddisplay_fk(intx,inty,intshape,intdir)/*显示方块*/

4;

if(fang_kuai[shape][dir][i][j])

setxy((x+2*j),(y+i));

/*结合现在方块的位置*/

/*-----------------------------------*/

voidgetinput()

if(GetAsyncKeyState(VK_LEFT)){

is_illegal(now_position.x-2,now_position.y,dir))

eras_fk(now_position.x,now_position.y,shape,dir);

now_position.x=now_position.x-2;

Sleep(1000);

m_sound(440,500);

/*如果没有遇阻,方块位置左移一格*/

}elseif(GetAsyncKeyState(VK_RIGHT)){

is_illegal(now_position.x+2,now_position.y,dir))

now_position.x=now_position.x+2;

/*如果没有遇阻,方块位置右移一格*/

}elseif(GetAsyncKeyState(VK_UP)){

is_illegal(now_position.x,now_position.y,(dir+1)%4))

dir=(dir+1)%4;

}elseif(GetAsyncKeyState(VK_DOWN)){

fk_down(true);

}elseif(GetAsyncKeyState(VK_SPACE)){

game_over();

voidm_sound(intfreq,inttime)

Beep(freq,time);

/*--------------------------------*/

voideras_fk(intx,inty,intshape,intdir)/*擦除方块*/

/*----------------------------------------------------*/

voidfk_down(boolquickly)/*方块下落*/

inti,j,x,y;

is_illegal(now_position.x,now_position.y+1,dir))/*下落没有阻碍*/

now_position.y=now_position.y+1;

if(quickly)

{

Sleep(10);

}else

else/*不可再下落了*/

/*方块并入背景*/

x=now_position.x;

y=now_position.y;

/*x,y表示方便*/

if(fang_kuai[shape][dir][i][j]==1)

background[(y-2+i)][(x/2-1+j)]=1;

fall_to_land=1;

/*告诉主程序方块着地*/

/*-----------------------------------------------------*/

boolis_illegal(intx,inty,intchanged_dir)

boolillegal=false;

/*先判断有没有出界,如果有x,y在界外并且此x,y处方块数组为1,就返回1*/

if(fang_kuai[shape][changed_dir][i][j]==1&

&

((x+j*2)>

21||(x+j*2)<

2||(y+i)>

21||(y+i)<

2))

illegal=true;

/*再判断是否有原方块阻碍*/

illegal)

background[(y-2+i)][(x/2-1+j)]==1)

/*有阻碍返回一*/

returnillegal;

intget_random(intn)

Sleep(500);

/*

randomize();

x=random(n);

*/

srand((unsigned)time(NULL));

x=rand()%n;

return(x);

/*--------------------------------------------------------------*/

voidcheck_line()/*待修改*/

/*检查背景数组*/

inti,j,k;

intline,n;

for(i=19;

=0;

k=1;

/*开始默认成行*/

for(j=9;

j>

j--)

if(background[i][j]==0)/*不成行的条件*/

k=0;

if(k==1)/*如果成行*/

be_lined=1;

/*成行标志*/

for(line=i;

line>

line--)

for(n=9;

n>

n--)

background[line][n]=background[line-1][n];

/*逐次下移一行*/

i=i+1;

/*把下一次待检的行重新设定*/

voidgame_over()

setxy(35,1);

GAMEOVER"

exit(0);

voidclscreen()

{

system("

cls"

}

voidsetxy(intx,inty)

HANDLEhConsole=GetStdHandle(STD_OUTPUT_HANDLE);

COORDplace;

place.X=x;

place.Y=y;

SetConsoleCursorPosition(hConsole,place);

/*ColorsdefinedforSetColor(int)*/

enum{

BLACK=0,

DARK_BLUE=1,

DARK_GREEN=2,

TEAL=3,

DARK_RED=4,

DARK_PURPLE=5,

GOLD=6,

GREY=7,

DARK_WHITE=8,

BLUE=9,

GREEN=10,

CYAN=11,

RED=12,

PURPLE=13,

YELLOW=14,

WHITE=15

voidSetColor(constintforeground,constintbackground){

intColor=foreground+(background*16);

SetConsoleTextAttribute(hConsole,Color);

return;

你把这段拿回去看哈吧,这是一个俄罗斯方块的程序,就是在控制台运行的,就是用你所说的纯数字和字符所运行,你现在只能在dos下显示那些纯数字的东西,是因为你很多技术性的手法,你还不会,但你学习到一定程度后,你就会有所领悟,也不要太心急,当你练好内功后,修炼招数,应该会很快的!

希望对你有帮助

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

当前位置:首页 > 小学教育 > 英语

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

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