當前位置:編程學習大全網 - 源碼下載 - 菜刀源代碼公告

菜刀源代碼公告

# include & ltiostream & gt

# include & ltfstream & gt

# include & ltctime & gt

# include & ltcmath & gt

# include & ltstdlib.h & gt

# include & ltstdio.h & gt//時間//文件

# include & lt字符串& gt

#定義random(x)(rand()%x)

使用命名空間std

void thunder(int Dif,int Row,int Column,char *USer)

{

int r,c,all[22][22],back stage[22][22]= { 0 };

srand((int)time(0));

for(r = 1;r & lt=行;R++) //生成all(0 ~ 1)1是雷。

{

for(c = 1;c & lt=列;c++)

{

if(random(6)& lt;1){ all[r][c]= 1;} else { all[r][c]= 0;};

}

};

for(r = 0;r & lt= Row+1;R++) //後臺生成(正確答案)

{

for(int c = 0;c & lt=列+1;c++)

{

if(alls[r][c]==1)

{

(int)back stage[r][c]= ' * ';//雷霆把1改成*。

}

其他

{

for(int I = r-1;我& lt= r+1;I++) //把0變成壹個數(代表身邊的雷數)

for(int j = c-1;j & lt= c+1;j++)

{

if(all[I][j]!= all s[r][c]& amp;& ampall[I][j]= = 1){ back stage[r][c]++;};

}

};//否則結束

};//的結尾

};//的結尾

cout & lt& lt" = = = = = = = = = = = = = = = = = = = = = = = * * * * * * * = = = = = = = = = = = = = = = = = = = = = = = = = = = = " & lt;& ltendl

炭化表面[22][22];//生成表面(用戶界面)

for(r = 0;r & lt22;R++) //全為零

for(c = 0;c & lt22;c++)

{

surface[r][c]= ' 0 ';

}

for(r = 1;r & lt=行;R++) //中間#形成0括#(通過數字#-->的形式;當(* ||數字)獲勝時停止循環)

for(c = 1;c & lt=列;c++)

{

surface[r][c]= ' # ';

}

for(r = 1;r & lt=行;R++) //輸出表面接口,便於檢查。

{

for(c = 1;c & lt=列;c++){ cout & lt;& lt" " " & lt& ltsurface[r][c];};

cout & lt& ltendl

};

cout & lt& lt"請按格式輸入"

& lt& lt“前兩個數字是坐標,最後壹個數字‘1’表示這個位置是雷霆,‘0’表示沒有。”& lt& lt恩德爾

& lt& lt“比如:1 3 1表示壹行三列是雷;2 4 0表示兩行四列不打雷”

& lt& lt“提示:當數字周圍的雷全部被掃光後,可以按要求再次進入這個位置,以獲得周圍的數字。”& lt& ltendl

龍I = 1000000 l;//計算時間的開始

clock_t開始,結束;

雙倍時長;

start =時鐘();

while(I-);//計算時間的開始

int num = Row * Column//計算#號的數量

而(num!=0) //控制是否點擊所有位置。

{

int x,y,judge

CIN & gt;& gtx & gt& gty & gt& gt法官;

if(all[x][y]!=法官)

{

cout & lt& lt“妳輸了!!!"& lt& ltendl

cout & lt& lt答案是:“& lt& ltendl

for(r = 1;r & lt=行;R++) //輸入輸出後臺顯示正確答案。

{

for(int c = 1;c & lt=列;c++)

{

cout & lt& lt" " " & lt& lt(char)(後臺[r][c]==42?backstage[r][c]:backstage[r][c]+' 0 ');//後臺輸出

}

cout & lt& ltendl

}

打破;

}

其他

{

if(all[x][y]= = 1){ if(surface[x][y]= = ' # '){ num-;} surface[x][y]= ' @ ';}//雷判斷“@”顯示正確;計數“#”

其他

{

如果(後臺[x][y]!=0) //數字判斷正確顯示數字。

{

if(surface[x][y]= = ' # '){ num-;surface[x][y]= back stage[x][y]+' 0 ';}//數字“#”

其他

{

int lei _ num = 0;

for(int I = x-1;我& lt= x+1;I++) //數雷圍數。

for(int j = y-1;j & lt= y+1;j++)

{

if(surface[i][j]=='@ ')

lei _ num++;

}

If(後臺[x][y]==lei_num) //看數字周圍的雷是否全部被掃出提示顯示數字。

{

for(int I = x-1;我& lt= x+1;i++)

for(int j = y-1;j & lt= y+1;j++)

if(surface[I][j]= ' # ')//number " # "

{

surface[I][j]= back stage[I][j]+' 0 ';

num-;

}

}

}

}

Else //當數字為零時,在零附近顯示零。

{

if(surface[x][y]= = ' # '){ num-;};//數字“#”

surface[x][y]= back stage[x][y]+' 0 ';

for(int I = x-1;我& lt= x+1;I++) //顯示零附近的數字。

for(int j = y-1;j & lt= y+1;j++)

if(surface[I][j]= ' # ')//避免無限循環。

{

surface[I][j]= back stage[I][j]+' 0 ';

num-;//數字“#”

}

for(int k = 0;k & lt20;K++) //最多20層零(指出最外側的零)

{

for(int R = 1;R & lt=行;R++) //檢查所有零

for(int C = 1;C & lt=列;C++) //再次顯示零周圍的數字。

{

if(surface[R][C]=='0 ')

{

for(int I = R-1;我& lt= R+1;i++)

for(int j = C-1;j & lt= C+1;j++)

{

if(surface[I][j]= ' # ')//避免無限循環號" # "

{

surface[I][j]= back stage[I][j]+' 0 ';

num-;

}

}

}

}//在中匹配

}//匹配外部for

}//匹配else

}//匹配else

}//匹配els

cout & lt& ltendl

cout & lt& lt" = = = = = = = = = = = = = = = = = = = = = = = * * * * * * * = = = = = = = = = = = = = = = = = = = = = = = = = = = = " & lt;& ltendl

for(r = 1;r & lt=行;R++) //輸出接口(已修改)

{

for(c = 1;c & lt=列;c++){ cout & lt;& lt" " " & lt& ltsurface[r][c];};

cout & lt& ltendl

};

}//匹配同時

finish = clock();//計算時間結束

duration =(double)(finish-start)/CLOCKS _ PER _ SEC;//時間變量

If(num==0) // all

{

cout & lt& lt“妳贏了!恭喜妳!! "& lt& ltendl

cout & lt& lt"您的時間是:" & lt& lt持續時間& lt& ltendl

If(Dif==1) //讀取簡單掃雷的存儲文件。

{

字符串名稱;

字符串名稱[6];

雙倍時間,響了;

雙倍[6];

int I = 0;

Ifstream inf("簡單掃雷。txt ");

for(I = 0;我& lt5;I++) //文件中的信息導入到數組中。

{

inf & gt& gt姓名;inf & gt& gtrang & gt& gt時間;

Name[I]= Name;

times[I]=時間;

}

INF . close();

name[5]=用戶;//本輪選手信息

times[5]=持續時間;

double t 1 = 0;

字符串T2;

for(int j = 0;j & lt5;J++) //冒泡排序方法

{

for(I = 0;我& lt5-j;i++)

{

if(times[I]& gt;次[i+1])

{

t 1 = times[I];

times[I]= times[I+1];

times[I+1]= t 1;

T2 = name[I];

name[I]= name[I+1];

name[I+1]= T2;

}

}

}

Ofstream outf("簡單掃雷。txt ");

for(I = 0;我& lt5;I++) //將前五名玩家的信息存儲在壹個文件中。

{

cout & lt& ltname[I]& lt;& lt" " " & lt& ltI+1 & lt;& lt" " " & lt& lttimes[I]& lt;& ltendl

outf & lt& ltname[I]& lt;& lt" " " & lt& ltI+1 & lt;& lt" " " & lt& lttimes[I]& lt;& ltendl

}

outf . close();

}

If(Dif==2) //讀取壹般掃雷的存儲文件。

{

字符串名稱;

字符串名稱[6];

雙倍時間,響了;

雙倍[6];

int I = 0;

Ifstream inf("壹般排雷。txt ");

for(I = 0;我& lt5;I++) //文件中的信息導入到數組中。

{

inf & gt& gt姓名;inf & gt& gtrang & gt& gt時間;

Name[I]= Name;

times[I]=時間;

}

INF . close();

name[5]=用戶;//本輪選手信息

times[5]=持續時間;

double t 1 = 0;

字符串T2;

for(int j = 0;j & lt5;J++) //冒泡排序方法

{

for(I = 0;我& lt5-j;i++)

{

if(times[I]& gt;次[i+1])

{

t 1 = times[I];

times[I]= times[I+1];

times[I+1]= t 1;

T2 = name[I];

name[I]= name[I+1];

name[I+1]= T2;

}

}

}

Ofstream outf("壹般排雷。txt ");

for(I = 0;我& lt5;I++) //將前五名玩家的信息存儲在壹個文件中並輸出。

{

cout & lt& ltname[I]& lt;& lt" " " & lt& ltI+1 & lt;& lt" " " & lt& lttimes[I]& lt;& ltendl

outf & lt& ltname[I]& lt;& lt" " " & lt& ltI+1 & lt;& lt" " " & lt& lttimes[I]& lt;& ltendl

}

outf . close();

}

If(Dif==3) //讀取難以挖掘的存儲文件。

{

字符串名稱;

字符串名稱[6];

雙倍時間,響了;

雙倍[6];

int I = 0;

Ifstream inf("掃雷難度。txt ");

for(I = 0;我& lt5;I++) //文件中的信息導入到數組中。

{

inf & gt& gt姓名;inf & gt& gtrang & gt& gt時間;

Name[I]= Name;

times[I]=時間;

}

INF . close();

name[5]=用戶;//本輪選手信息

times[5]=持續時間;

double t 1 = 0;

字符串T2;

for(int j = 0;j & lt5;J++) //冒泡排序方法

{

for(I = 0;我& lt5-j;i++)

{

if(times[I]& gt;次[i+1])

{

t 1 = times[I];

times[I]= times[I+1];

times[I+1]= t 1;

T2 = name[I];

name[I]= name[I+1];

name[I+1]= T2;

}

}

}

Ofstream outf(“掃雷困難。txt ");

for(I = 0;我& lt5;I++) //將前五名玩家的信息存儲在壹個文件中。

{

cout & lt& ltname[I]& lt;& lt" " " & lt& ltI+1 & lt;& lt" " " & lt& lttimes[I]& lt;& ltendl

outf & lt& ltname[I]& lt;& lt" " " & lt& ltI+1 & lt;& lt" " " & lt& lttimes[I]& lt;& ltendl

}

outf . close();

}

}

}

Void scale(int dif,char *User) //選擇難度。

{

int row,column

if(dif = = 1){ row = 3;列= 3;}

if(dif = = 2){ row = 7;列= 7;}

if(dif = = 3){ row = 10;列= 10;}

cout & lt& lt“尺度是:“& lt& ltrow & lt& lt" * " & lt& lt列& lt& ltendl

迅雷(dif,行,列,用戶);

};

int main()

{

int Continue = 1;

int難度;

char用戶[10];

cout & lt& lt“歡迎來看比賽!”& lt& lt恩德爾

& lt& lt"請輸入用戶名!"& lt& ltendl

CIN & gt;& gt用戶;

while(Continue==1)

{

cout & lt& lt" = = = = = = = = = = = = = = = = = = = = = = = * * * * * * * * * * * * * * = = = = = = = = = = = = = = = = = = = = = = " & lt;& lt恩德爾

& lt& lt“請選擇難度!”& lt& lt恩德爾

& lt& lt"簡單-1 "

& lt& lt"常規-2 "

& lt& lt“困難-3”

CIN & gt;& gt難度;

尺度(難度,用戶);

cout & lt& lt“繼續遊戲-1結束遊戲-0”< & lt;endl

CIN & gt;& gt繼續;

}

返回0;

}

掃雷遊戲,自己的代碼。

  • 上一篇:德州撲克怎麽玩?
  • 下一篇:保稅區發貨的壹定是正品嗎
  • copyright 2024編程學習大全網