1、/挑战模式void Block_Score();/储存分数HANDLE handle;WORD Colors1=FOREGROUND_RED;WORD BColors1=FOREGROUND_BLUE;WORD GColors1=FOREGROUND_GREEN;/设置颜色int block_cshape44,block_newshape44;/设置两个临时方块矩阵int speed=1,delay_max=100,delay,score=0,score_high,mode;/设置速度,最大延迟,延迟,分数,最高分,模式int map_shape2446;/设置地图矩阵int x_coordi
2、nate=29, y_coordinate=3;/初始横纵坐标int block_shape744=0,0,0,0, 1,1,1,1, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,1,0, 0,1,1,1, 0,1,1,0, 0,1,0,0, 0,1,1,0, 0,1,1,0, 0,0,1,0, 0,0,0,0, 0,0,1,1, 1,1,0,0, 0,0,0,0;/设置种方块void main()/主函数 handle = initiate();/屏幕初始化 srand(time(NULL); textout(handle,20,7,Colors,1,); Sleep(30
3、0); textout(handle,22,7,Colors,1, textout(handle,24,7,Colors,1, textout(handle,26,7,Colors,1, textout(handle,28,7,Colors,1, textout(handle,30,7,Colors,1, textout(handle,34,7,Colors,1, textout(handle,36,7,Colors,1, textout(handle,40,7,Colors,1, textout(handle,42,7,Colors,1, textout(handle,44,7,Colors
4、,1, textout(handle,20,11,Colors,1,Please select game mode: textout(handle,22,12,Colors,1,Press n to choosen normal mode textout(handle,22,13,Colors,1,c to choosen challenge mode int ktemp = _getch(); switch(ktemp) case 110: Start(); Begin_normal(); break; case 99: Begin_challenge(); default: PlaySou
5、nd( E:BUPT小学期c+俄罗斯方块standard俄罗斯方块kaitou.wav,0,SND_ASYNC); while(1) x_coordinate = 29, y_coordinate = 3; Block_Birth(); while(1)/一个方块下落整个过程 delay = 0; while(delaydelay_max) if (_kbhit() Block_Change(block_cshape); Sleep(8); delay+; /判断对方块的操作 if(Block_Available(block_cshape,0,1) Block_Clear(block_csha
6、pe); y_coordinate+; Block_Print(block_cshape); /判断是否下移 else Block_Intomap(block_cshape); Block_Deleteline(); break; /判断是否消行 void Start() textout(handle,50,15,BColors,1,Instruction: textout(handle,50,16,BColors,1,Please control by textout(handle,50,17,BColors,1,the textout(handle,50,18,BColors,1,Esc
7、to exit textout(handle,20,2,GColors,1,O textout(handle,20,23,GColors,1, textout(handle,45,2,GColors,1, textout(handle,45,23,GColors,1, textout(handle,50,23,BColors,1,Manufactured by LRJ in BUPT textout(handle,50,5,BColors,1,Score: textout(handle,50,3,BColors,1,Speed: char output10;/临时输出矩阵 itoa(score
8、,output,10); textout(handle,56,5,BColors,1,output); itoa(speed,output,10); textout(handle,56,3,BColors,1,output); for(int x=21;x45;x+) textout(handle,x, 2,GColors,1,= textout(handle,x, 23,GColors,1, for(int y=3;youtput;score_high; readfile.close(); textout(handle,50,6,BColors,1,Best: textout(handle,
9、56,6,BColors,1,output); /读取最高分void Begin_challenge() mode = 1; textout(handle,26,1,BColors,1,Challenge Mode int line; textout(handle,23,10,Colors,1,Please input initial textout(handle,23,11,Colors,1,blocks lines and textout(handle,23,12,Colors,1,then press Enter cinline; textout(handle,0,0,Colors,1,
10、 for(int x=22;x22-line;x-)y+=2) int n = rand()%2; map_shapexy = n; if(n) textout(handle,y,x,Colors,1, Sleep(70); /初始化地图矩阵BUPT小学期c+俄罗斯方块standard俄罗斯方块score_challenge.txtvoid Block_Print(int block_shape44)/打印方块函数4; if (block_shapexy=1) textout(handle,x_coordinate+2*y, y_coordinate+x,Colors,1,void Block
11、_Clear(int block_shape44)/擦除方块 for(int y=0; for(int x=0; if (block_shapeyx=1) textout(handle,x_coordinate+2*x,y_coordinate+y,Colors,1,void Block_Change(int block_shape44)/操作方块 int direction = _getch(); switch(direction) case 72:/up 方块变形 for(int k=0;kk+) for(int j=0;jj+) block_newshape3-jk = block_sh
12、apekj; if(Block_Available(block_newshape,0,0) Block_Clear(block_cshape); Block_Print(block_newshape); for(int k=0; for(int j=0; block_cshapekj = block_newshapekj; break; case 75:/left 方块左移 if(Block_Available(block_cshape,-2,0) x_coordinate-=2; Block_Print(block_cshape); case 77:/right 方块右移 if(Block_
13、Available(block_cshape,2,0) x_coordinate+=2; case 80:/down 方块下移 delay=delay_max; case 27:/Esc 推出暂停游戏 textout(handle,50,10,Colors,1,Do u want to exit textout(handle,50,11,Colors,1,the game(y/n) int temp = _getch(); switch(temp) case 121: textout(handle,50,10,Colors,1, textout(handle,50,11,Colors,1, t
14、extout(handle,34,11,BColors,1,score: char output10; itoa(score,output,10); textout(handle,40,11,BColors,1,output); PlaySound( BUPT小学期c+俄罗斯方块standard俄罗斯方块dead.wav,0,0); Block_Score();input error.if u want to exit, textout(handle,50,12,Colors,1,please press Esc again Sleep(1000);void Block_Intomap(int
15、 block_shape44)/更改地图矩阵 switch(y) case 0: map_shapey_coordinate+xx_coordinate+y=block_shapexy; break; case 1: case 2: case 3: map_shapey_coordinate+xx_coordinate+2*y=block_shapexy; Block_Print(block_shape);bool Block_Available(int block_shape44,int x_move,int y_move)/判断方块能否放下 for(int y=0; if (block_s
16、hapexy=1) switch(y) case 0: if (map_shapey_coordinate+y_move+xx_coordinate+x_move+y&block_shapexy) return 0; break; case 1: case 2: case 3: if (map_shapey_coordinate+y_move+xx_coordinate+x_move+2*y& return 1;void Block_Birth()/方块生成 int n = rand()%7; for(int k=0; for(int j=0; block_cshapekj=block_sha
17、penkj; block_newshapekj=block_shapenkj; /随机生成方块 if(!Block_Available(block_cshape,0,0)/判断游戏是否结束 PlaySound( textout(handle,24,10,BColors,1, Sleep(300); textout(handle,26,10,BColors,1, textout(handle,28,10,BColors,1, textout(handle,30,10,BColors,1, textout(handle,34,10,BColors,1, textout(handle,36,10,BColors,1, textout(handle,38,10,BColors,1, textout(handle,40,10,BColors,1,
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1