扫雷6代码说明.doc
文本预览下载声明
#includestdio.h
#include stdlib.h
#include time.h
#include string.h
#include conio.h
#include windows.h
int system(const char *string);
int b[25][25]={{0}},d,t=0,t1,time1=0; /*定义全局变量 二维数组b(设定随机数和对雷的判断)d控制游戏难度系数*/
char a[25][25]={{0}}; /*d控制游戏难度系数,二维数组a用于显示图形画面*/
HANDLE hMutex;
void gotoxy(int x, int y) /*输出坐标函数,只知道功能即可,用于指定输出位置*/
{
COORD pos;
pos.X = x;
pos.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
void color(int b) /*输出颜色函数,只知道功能即可,用于指定输出结果颜色*/
{
HANDLE hConsole = GetStdHandle((STD_OUTPUT_HANDLE)) ;
SetConsoleTextAttribute(hConsole,b) ;
}
int time()/*时钟函数,记录整个程序开始运行的时间*/
{
clock_t t=clock()/CLOCKS_PER_SEC;
return t;
}
void hide(int k)/*隐藏光标函数,知道功能即可*/
{
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cci;
GetConsoleCursorInfo(hOut,cci);
cci.bVisible=k;
SetConsoleCursorInfo(hOut,cci);
}
DWORD WINAPI ThreadProc(LPVOID lpParameter)/*多线程执行过程中,与本游戏move()同时执行的计时的函数*/
{
while(1)
{
if(time1) {gotoxy(65,10);color(10);printf(%d,t-t1);break;}
WaitForSingleObject(hMutex, 700);
t=time();gotoxy(65,10);color(10);printf(%d,t-t1);
ReleaseMutex(hMutex);
}
return 0;
}
void level()/*游戏选择难度系数界面(程序第一个界面)函数*/
{
char c;
int x=28,y=10;
gotoxy(15,12);
printf(请选择难度: );
gotoxy(x,y);
color(10);
printf(简单 );color(15);printf(◎);printf( W ↑);
gotoxy(x,y+2);
color(14);
printf(一般 );color(15);printf(◎);printf( M Enter);
gotoxy(x,y+4);
color(12);
printf(困难 );color(15);printf(◎);printf( S ↓);
gotoxy(x=35,y=10);color(12);printf(◎);gotoxy(x,y);
while(c=getch())/*对难度系数进行选择的循环*/
{
if(c==wy=12) {gotoxy(x,y);color(15);printf(◎);gotoxy(x,y-=2);color(12);printf(◎);gotoxy(x,y);}
else if(c==sy=12) {gotoxy(x,y);color(15);printf(◎);gotoxy(x,y+=2);color(12);printf(◎);gotoxy(x,y);}
else if(c==m) break;
}
if(y==10) d=2;
else if(y==12) d=3;
else if(y==14) d=4;
}
int victory ()/*触发游戏结束后使得游戏界面右下角出现 VICTORY字
显示全部