




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、俄罗斯方块c+程序(Tetris c+ program)(1) the first cpp:#include "colorConsole.h""HANDLE, initiate ()HANDLE hOutput;HOutput = GetStdHandle (STD_OUTPUT_HANDLE);Return hOutput;BOOL, TextOut (HANDLE, hOutput, int, x, int, y, WORD, wColors, int, nColors, LPTSTR, lpszString)DWORD cWritten;BOOL fSucc
2、ess;COORD coord;Coord.X = x; / / start at first cellCoord.Y = y; / / of first rowFSuccess = WriteConsoleOutputCharacterHOutput, buffer handle / / screenLpszString, to source string / / pointerLstrlen (lpszString), of string / / lengthCoord, cell to write to / / first&cWritten); / / actual number
3、 writtenIf (. FSuccess)Cout<< "error:WriteConsoleOutputCharacter" <<endl;(for; fSuccess & & coord.X < lstrlen (lpszString) +x; coord.X = nColors)FSuccess = WriteConsoleOutputAttributeHOutput, buffer handle / / screenWColors, to source string / / pointerNColors, of st
4、ring / / lengthCoord, cell to write to / / first&cWritten); / / actual number writtenIf (. FSuccess)Cout<< "error:WriteConsoleOutputAttribute" <<endl;Return 0;(2) second CPP#include <conio.h>#include <stdlib.h>#include<stdio.h>#include <windows.h>#in
5、clude <mmsystem.h>#pragma comment (LIB, winmm.lib) / / background music files#include "colorConsole.h""#include<time.h>#define SQUARE_COLOR BACKGROUD_BLUE|BACKGROUD_RED| BACKGROUD_INTENSITY / / background color#define SQUARE_COLOR FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND
6、_INTENSITY / / color box#define up 72#define down 80#define left 75#define right 77#define ESC 27#define MAPW 15 / map width#define MAPH / / 25 height mapVoid, initiate1 ();Int * (build); / / create / / initialization blockBOOL isavailable (int a, int x, int y, int w, int h); / / determine whether c
7、an let goVoid, drawblocks (int, a, int, W, int, h, int, x, int, y, WORD, wColors, int, nColors);Void (delete_cache); / / remove keyboard bufferVoid revolve (int a4, int w, int h, int *x, int y); / / rotate blockVoid, pro ();Void, end ();Void, delete_blocks (int, *a, int, W, int, h, int, x, int, y);V
8、oid, gameover ();Void, deletefull_line (int, mMAPW, int, row, int, W, int, H);/ / 消除一行int dx = 30, dy = 5; / / 屏幕上的偏移量int score = 0, level = 0;map int mapw maph;int a1 4 4 = 1, 1,1,1-trichloroethane;int a2 4 4 = 0,1, 1,1,1-trichloroethane;int a3 4 4 = 1,1, 0,1,1;int a4 4 4 = 0,0,1, 1,1,1-trichloroet
9、hane;int a5 4 4 = 1,1 0,1,1,;int a6 4 4 = 1,1,1,1;int a7 4 4 = 1,1, 1,1;int a 4 4;int main ()handle handle;handle = initiated ();word wcolors 1 = foreground _ blue | foreground _ green | foreground their _;while (1)sndplaysound ("resource dance.wav fair", snd _ loop | snd _ async); / / 用异步
10、方式播放音乐, playsound函数在开始播放后立即返回system (cls);int i = 0;printf ("目录 n1.开始游戏 n2.退出游戏 i i i");scanf ("% d", & n);switch (n)case 1:system (cls);textout (handle, 22.6, wcolors + 2.1, "请选择游戏等级:");textout (handle, 44,8, wcolors + 2.1, "1.初级");textout (handle, 32,10,
11、 wcolors + 2.1, "2.中级");textout (handle, 32,12, wcolors + 2.1, "3.高级");while (1)char choice;choice = _ getch ();if (choice = = '1')textout (handle, 22.6, wcolors + 2.1, "开始游戏, 初级");textout (handle, 44,8, wcolors + 2.1, "");textout (handle, 32,10, wcolo
12、rs + 2.1, "");textout (handle, 32,12, wcolors + 2.1, "");level = 0, score = 0;sleep (2000);textout (handle, 22.6, wcolors + 2.1, "");break;else if (choice = = '2')textout (handle, 22.6, wcolors + 2.1, "开始游戏, 中级");textout (handle, 44,8, wcolors + 2.1, &
13、quot;");textout (handle, 32,10, wcolors + 2.1, "");textout (handle, 32,12, wcolors + 2.1, "");level = 2, score = 20;sleep (2000);textout (handle, 22.6, wcolors + 2.1, "");break;else if (choice = = '3')textout (handle, 22.6, wcolors + 2.1, "开始游戏, 高级&quo
14、t;);textout (handle, 44,8, wcolors + 2.1, "");textout (handle, 32,10, wcolors + 2.1, "");textout (handle, 32,12, wcolors + 2.1, "");level = 4, score = 40;sleep (2000);textout (handle, 22.6, wcolors + 2.1, "");break;else if (choice! = '1' & & ch
15、oice! = 2 & & choice! = '3')continue;pro ();break;case 2:return 0;default:printf ("错误, 按键继续");while (! _ kbhit ();the void () / / 游戏主题 proinitiate1();int;B = build();/ /创建方块符号,空格,x,y;(1)为(int i = 0;i < 4;i+)/复制方块为(int = 0;j4;j + +)如果(一个我 J =×(B +我* 4 + J)空白=我;Y = 1-
16、blank;x = 4;delete_blocks(与 0 0 ,4,4,16,10);B = build();把手;initiate()处理=;字wcolors 1 = foreground_blue | foreground_green | foreground_intensity ;drawblocks(B,4,4,16,10,wcolors,1);wcolors 0 = square_color;drawblocks(与 0 0 ,4,4,X,Y,wcolors,1);delete_cache();字符字符串 5 ;wcolors 0 = foreground_red | foregr
17、ound_green | foreground_intensity;TextOut(手柄,dx-10,8 + Dy,wcolors、1、ITOA(评分,字符串,10);TextOut(手柄,dx-10,14 + Dy,wcolors、1、ITOA(水平,字符串,10);符号= 1;当(符号)延时= 0,max_delay = 10×水平;/ /延迟量而(延迟< max_delay)如果(_kbhit())/用如果避免按住键使方块卡住int绘图0;int key = _getch();开关(键)案子:delete_blocks(与 0 0 ,4,4,x,y);(一、二旋转,和X,
18、Y);绘图1;打破;的情况下:延迟= max_delay;打破;例左右:如果(,(与 0 0 ,X-1,Y,4,4)delete_blocks(与 0 0 ,4,4,x,y);X;绘图1;打破;权案:如果(,(与 0 0 ,x + 1,y,4,4)delete_blocks(与 0 0 ,4,4,x,y);+;绘图1;打破;案例32:/ / 32是空格键的ASCII码,按空格键暂停(1)TextOut(手柄,DX - 2 + Dy,wcolors,1,“按任意键继续”);睡眠(200);TextOut(手柄,DX - 2 + Dy,wcolors,1,“”);睡眠(200);如果(_kbhit
19、())绘图1;打破;打破;案例:/ /按键退出游戏ESC退出(exit_success);如果(画)把手;initiate()处理=;字wcolors 1 = square_color ;drawblocks(与 0 0 ,4,4,X,Y,wcolors,1);绘图0;_sleep(5);延迟+ +;如果(,(与 0 0 ,x,y + 1,4,4)/是否能下移delete_blocks(与 0 0 ,4,4,x,y);+;把手;initiate()处理=;字wcolors 1 = square_color ;drawblocks(与 0 0 ,4,4,X,Y,wcolors,1);其他的标志=
20、 0;/标记使跳出(标志),而循环,Create new diamondsIf (y<=1)System ("CLS");HANDLE handle;Handle=initiate ();WORD wColors1=FOREGROUND_RED| FOREGROUND_GREEN;TextOut (handle, 4+dx, 6+dy, wColors, 1, GAME, OVER!);TextOut (handle, 4+dx, 8+dy, wColors, 1, scores:);TextOut (handle, 10+dx, 8+dy, wColors, 1,
21、Itoa (score, string, 10);TextOut (handle, 4+dx, 10+dy, wColors, 1, producer: * * *);Delete_cache ();Exit (EXIT_SUCCESS); / be endFor (int i=0; i<4; i+) / / drop boxFor (int j=0; j<4; j+)If (aij&& (i+y) (<MAPH-1) and (j+x) <MAPW-1)Mapi+yj+x=aij;Int, full, k=0;For (i=y; i<min (y
22、+4, MAPH-1); i+)Full=1;For (int j=1; j<14; j+)If (. Mapij) full=0;If (full) / off lineDeletefull_line (map, I, MAPW, MAPH);K+;Score=score+k;Level=min (score/10,9);Void (initiate1) / / initializeInt i;For (i=0; i<25; i+)Mapi0=-2;Mapi14=-2;For (i=0; i<15; i+)Map0i=-1;Map24i=-1;Map00=-3;Map014
23、=-3;Map240=-3;Map2414=-3;HANDLE handle;Handle=initiate ();WORD wColors1=FOREGROUND_GREEN| FOREGROUND_BLUE|FOREGROUND_INTENSITY;TextOut (handle, dx-10,6+dy, wColors, 1, SCORE);TextOut (handle, dx-10,12+dy, wColors, 1, LEVEL);TextOut (handle, 32+dx, 8+dy, wColors, 1, NEXT);WColors0=FOREGROUND_RED|FORE
24、GROUND_BLUE|FOREGROUND_INTENSITY;Drawblocks (&map00, 15,25,0,0, wColors, 1);TextOut (handle, DX, Dy, wColors, 1, "one one one one one one - one one one one one one one ");WColors0=FOREGROUND_BLUE| FOREGROUND_GREEN|FOREGROUND_INTENSITY;TextOut (handle, dx+8, dy+5, wColors, 1, "pres
25、s any key to start");WColors0=FOREGROUND_BLUE|FOREGROUND_RED|FOREGROUND_INTENSITY;TextOut (handle, dx+7, DY-3, wColors, 1, producer: * * *);Int, x=_getch ();Srand (time (NULL);TextOut (handle, dx+8, dy+5, wColors, 1, "");(int * build) / / create a boxInt * a=NULL;Int c=rand ()%7;Switc
26、h (c)Case 0:A=&a100; break;Case 1:A=&a200; break;Case 2:A=&a300; break;Case 3:A=&a400; break;Case 4:A=&a500; break;Case 5:A=&a600; break;Case 6:A=&a700; break;Return a;Void drawblocks (int a, int w, int h, int x, int y, WORD wColors, int nColors) / / draw boxHANDLE handle
27、;Handle = initiate ();Int temp;For (int i=0);“我”;“h”;“+”用于(int = 0;j w;j + +)如果(i = w = j)0)如果(= = 3)TextOut(手柄、2×(x + J)+ dx,y +我+ Dy,wcolors,ncolors,“”);(30)_sleep;否则如果(= = 2)TextOut(手柄、2×(x + J)+ dx,y +我+ Dy,wcolors,ncolors,“”);(30)_sleep;否则如果(临时= 1)TextOut(手柄、2×(x + J)+ dx,y +我+ Dy,wcolors,ncolors,“”);否则如果(= = 1)TextOut(手柄、2×(x + J)+ dx,y +我+ Dy,wcolors,ncolors,“”);(30)_sleep;无效delete_cache() /清除缓冲区而(_kbhit())_getch();无效
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 食品饮料供应链合作合同
- 医学领域实习经历证明(7篇)
- 货物原材料销售协议
- 合作开展医疗业务活动协议及保密条款
- 加油站股份转让协议
- 农村电商物流合作方案与战略合作协议
- 资产评估与转让协议
- 2025年公文处理考试要点试题及答案
- 收入及奖金证明书金融行业(7篇)
- 突破自我2025年建筑工程试题及答案
- 幼儿园新生入园报名登记表
- 人工流产-清宫术知情同意书
- 中国临床戒烟指南的指导意义
- (完整版)EORTC生命质量测定量表QLQ-C30(V3.0)
- 医院医学影像科CT-MR室诊疗指南和操作规范2022版
- 金税工程(三期)总体实施方案
- ABAQUS官方培训资料PPTlecture7-job-visualization
- 苏教版四年级数学下册确定位置
- 【超星尔雅学习通】数字影视编导与制作网课章节答案
- 2023上海市成人高考《英语》(高升专)考试卷及答案(单选题型)
- 老年口腔医学 课件 老年口腔修复
评论
0/150
提交评论