文档详情

c++扫雷游戏代码.doc

发布:2017-10-17约字共10页下载文档
文本预览下载声明
// 扫雷游戏在C++中编译即可 作者 范训占 QQ:363299541 #include stdio.h #include iostream #include time.h #include conio.h #include windows.h using namespace std; #define N 48 //地图的行大小 ,最好不要超过165 #define M 20 //地图的列大小,不要超过45 #define T 100 //需要布雷总数 HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE); HANDLE hin=GetStdHandle(STD_INPUT_HANDLE); SYSTEMTIME st1,st2; INPUT_RECORD mouse; DWORD state=0,res; COORD pos={0,0}; char lei[N][N]; unsigned int num=0,TT=0; //num是用来统计扫过的数组数,TT用来统计标志雷的数 int cai[N][N]; int doubt[N][N]; int seek[2]={0,0}; void super(){ //用来设置地图的大小 hout=GetStdHandle(STD_OUTPUT_HANDLE); COORD size={N+1,M+2}; SetConsoleScreenBufferSize(hout,size); SMALL_RECT rc = {0,0, N+1, M+2}; //4个数字的大小分别指的是底部,左边,右边,顶部 SetConsoleWindowInfo(hout,true,rc); } void gotoxy(int x, int y) { COORD position; CONSOLE_CURSOR_INFO cursor; cursor.bVisible=false; //为了不显示光标 cursor.dwSize=10; //光标显示的百分度 position.X=x;position.Y=y; SetConsoleCursorInfo(hout,cursor); SetConsoleCursorPosition (hout, position); // CloseHandle(hout); } void disptime(){ GetLocalTime(st2); //获取时时系统时间 CONSOLE_SCREEN_BUFFER_INFO info; GetConsoleScreenBufferInfo(hout,info); gotoxy(38,info.srWindow.Bottom); printf( 已用时间: %02d:%02d:%02d, st2.wHour-st1.wHour, st2.wMinute-st1.wMinute, st2.wSecond-st1.wSecond); //输出运行时间差时 } void menu(){ //主菜单函数 SetConsoleTitle(扫雷游戏); //设置控制台窗口标题 gotoxy(0,0); coutendl; cout 欢迎来玩扫雷游戏 endl; cout****************************游戏说明*************************************endl; cout 用鼠标的左键扫雷,用鼠标的右键标记雷,标志出雷后同时按下左右键周围扫雷endl; cout 胜利的条件是把所有的*的格子打开,并且不能遇到雷endl; cout 游戏过程中按下鼠标中的滚动键退出游戏endl; cout 地图大小:N*Mendl; cout 地雷总数:Tendl; cout*********************************************************************endl; cout按任意键开始游戏endl; getch(); } void dispmine(){//用于显示数组中的雷 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE);//用紫色显示雷 fo
显示全部
相似文档