最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C++基于CMD命令行實(shí)現(xiàn)掃雷小游戲

 更新時(shí)間:2022年05月07日 11:38:49   作者:雨者  
這篇文章主要為大家詳細(xì)介紹了C++基于CMD命令行實(shí)現(xiàn)掃雷小游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了C++基于CMD命令行實(shí)現(xiàn)掃雷小游戲的具體代碼,供大家參考,具體內(nèi)容如下

這個(gè)小游戲是筆者在大一C語(yǔ)言課程設(shè)計(jì)的時(shí)候?qū)懙?,基于命令行,為了顯得漂亮一些,特別加上了彩色特效。

注意:Win10系統(tǒng)須將命令行調(diào)為舊版命令行,否則有可能會(huì)顯示亂碼!

代碼示例:

#include <stdio.h> ?
#include <conio.h> ?
#include <stdlib.h> ?
#include <time.h> ?
#include <stdlib.h> ?
#include <windows.h> ?
?
// 由于棋盤(pán)格與邏輯雷區(qū)格有一定差別,所以為了坐標(biāo)能夠相互映射,設(shè)置宏I,J,分別映射邏輯表的i,j。
#define I (i+2)
#define J (2*(j+1)+1)
?
/*字體顏色處理函數(shù)*/ ?
??
void SetColor(unsigned short ForeColor,unsigned short BackGroundColor){ ?
? ? HANDLE hCon=GetStdHandle(STD_OUTPUT_HANDLE); ?
? ? SetConsoleTextAttribute(hCon,(ForeColor%16)|(BackGroundColor%16*16)); ?
} ?
??
/*游戲主程序*/ ?
??
void showmine(); ? ? ? ?//顯示所有地雷 ?
void setmine(int x); ?//布雷 ?
void printmine(); ? ? ? //打印所有地雷 ?
void countmine(int rowno, int colno); ? ?//數(shù)雷算法 ?
//構(gòu)建棋盤(pán) ?
char row[16][80]={ ?
? ? {"----------Platform---------------------"}, ?
? ? {"------------------------------------------------------------------------"}, ?
? ? {"01|\x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02"}, ?
? ? {"02|\x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02"}, ?
? ? {"03|\x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02"}, ?
? ? {"04|\x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02"}, ?
? ? {"05|\x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02"}, ?
? ? {"06|\x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02"}, ?
? ? {"07|\x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02"}, ?
? ? {"08|\x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02"}, ?
? ? {"09|\x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02"}, ?
? ? {"10|\x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02"}, ?
? ? {"11|\x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02"}, ?
? ? {"12|\x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02"}, ?
? ? {"13|\x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02"}, ?
? ? {"14|\x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02 \x02"}, ?
}; ?
構(gòu)建雷區(qū)// ?
int mines[14][14]={ ? ? ? ? ? ? //雷區(qū)模擬圖(01二值化,標(biāo)記地雷) ?
? ? {0,0,0,0,0,0,0,0,0,0,0,0,0,0}, ?
? ? {0,0,0,0,0,0,0,0,0,0,0,0,0,0}, ?
? ? {0,0,0,0,0,0,0,0,0,0,0,0,0,0}, ?
? ? {0,0,0,0,0,0,0,0,0,0,0,0,0,0}, ?
? ? {0,0,0,0,0,0,0,0,0,0,0,0,0,0}, ?
? ? {0,0,0,0,0,0,0,0,0,0,0,0,0,0}, ?
? ? {0,0,0,0,0,0,0,0,0,0,0,0,0,0}, ?
? ? {0,0,0,0,0,0,0,0,0,0,0,0,0,0}, ?
? ? {0,0,0,0,0,0,0,0,0,0,0,0,0,0}, ?
? ? {0,0,0,0,0,0,0,0,0,0,0,0,0,0}, ?
? ? {0,0,0,0,0,0,0,0,0,0,0,0,0,0}, ?
? ? {0,0,0,0,0,0,0,0,0,0,0,0,0,0}, ?
? ? {0,0,0,0,0,0,0,0,0,0,0,0,0,0}, ?
? ? {0,0,0,0,0,0,0,0,0,0,0,0,0,0}, ?
}; ?
??
??
int mines_demo[14][14]={ ? ? ? ? ?//雷數(shù)統(tǒng)計(jì)圖(用于顯示周?chē)卓倲?shù)) ?
? ? {0,0,0,0,0,0,0,0,0,0,0,0,0,0}, ?
? ? {0,0,0,0,0,0,0,0,0,0,0,0,0,0}, ?
? ? {0,0,0,0,0,0,0,0,0,0,0,0,0,0}, ?
? ? {0,0,0,0,0,0,0,0,0,0,0,0,0,0}, ?
? ? {0,0,0,0,0,0,0,0,0,0,0,0,0,0}, ?
? ? {0,0,0,0,0,0,0,0,0,0,0,0,0,0}, ?
? ? {0,0,0,0,0,0,0,0,0,0,0,0,0,0}, ?
? ? {0,0,0,0,0,0,0,0,0,0,0,0,0,0}, ?
? ? {0,0,0,0,0,0,0,0,0,0,0,0,0,0}, ?
? ? {0,0,0,0,0,0,0,0,0,0,0,0,0,0}, ?
? ? {0,0,0,0,0,0,0,0,0,0,0,0,0,0}, ?
? ? {0,0,0,0,0,0,0,0,0,0,0,0,0,0}, ?
? ? {0,0,0,0,0,0,0,0,0,0,0,0,0,0}, ?
? ? {0,0,0,0,0,0,0,0,0,0,0,0,0,0}, ?
}; ?
??
// ?
??
int countstep=0; ?//已挖坑數(shù)目(計(jì)數(shù)器),用于判定玩家獲勝
int n=5; ?//布雷數(shù)(待輸入)
/主函數(shù)開(kāi)始/// ?
void main() ?
{ ?
? ? int i=0,j=0; ?
? ? int flag=1; ?
? ? int temp=0; ?
? ? char ch1; ?
? ? SetColor(3,0); ?
? ? printf("歡樂(lè)掃雷\n\n"); ?
? ? printf("w-上 s-下 a-左 d-右 q-挖雷\n\n"); ?
? ? SetColor(7,0); ?
? ? printf("作者:PeterZheng\n"); ?
? ? printf("EagleEyes 工作室\n"); ?
? ? printf("EagleEyes.Inc\n\n"); ?
? ? getch(); ?
? ? system("cls"); ?
? ? printf("你想要布幾顆雷?(1< mines <196)"); ?
? ? scanf("%d",&n); ? ?
?? ?system("cls");
? ? setmine(n); ?
? ? row[I][J]='\x01'; ?
? ? system("cls"); ?
? ? showmine(); ?
?? ?printf("\n\n");
?? ?//按鍵消息處理核心代碼
? ? while(flag) ?
? ? { ?
? ? ? ? ch1=getch(); ?
? ? ? ? if(ch1=='w'){ ?
? ? ? ? ? ? if(i==0){ ?
? ? ? ? ? ? ? ? system("cls"); ?
? ? ? ? ? ? ? ? showmine(); ?
? ? ? ? ? ? ? ? continue; ?
? ? ? ? ? ? }else{ ?
? ? ? ? ? ? ? ? system("cls"); ?
? ? ? ? ? ? ? ? if(row[I][J]<'9' && row[I][J]>='0'){ ?//確認(rèn)移動(dòng)前的位置屬于已被挖雷(在上一次光標(biāo)移動(dòng)時(shí)已經(jīng)恢復(fù)數(shù)字,只是還沒(méi)有showmine()而已)
? ? ? ? ? ? ? ? ? ? i--; ?//光標(biāo)移動(dòng)
? ? ? ? ? ? ? ? ? ? if(row[I][J]<'9' && row[I][J]>='0'){ ?//確認(rèn)移動(dòng)后的位置已被挖雷
? ? ? ? ? ? ? ? ? ? ? ? temp=row[I][J]; ?//用temp記錄該位置原數(shù)字
? ? ? ? ? ? ? ? ? ? ? ? row[I][J]='\x01'; ?//將該位置標(biāo)記為選中
? ? ? ? ? ? ? ? ? ? ? ? showmine(); ?//顯示雷區(qū)圖
? ? ? ? ? ? ? ? ? ? ? ? row[I][J]=temp; ?//將選中位置改回原數(shù)字
? ? ? ? ? ? ? ? ? ? ? ? continue; ?
? ? ? ? ? ? ? ? ? ? } ?
? ? ? ? ? ? ? ? ? ? row[I][J]='\x01'; //如果不會(huì)被覆蓋,則直接選中即可 ?
? ? ? ? ? ? ? ? ? ? showmine(); ?//顯示雷區(qū)圖
? ? ? ? ? ? ? ? ? ? continue; ? ?
? ? ? ? ? ? ? ? } ?
?? ??? ??? ??? ?//移動(dòng)前的位置未被挖雷情況
? ? ? ? ? ? ? ? row[I][J]='\x02'; ?
? ? ? ? ? ? ? ? i--; ?
? ? ? ? ? ? ? ? if(row[I][J]<'9' && row[I][J]>='0'){ ?
? ? ? ? ? ? ? ? ? ? temp=row[I][J]; ?
? ? ? ? ? ? ? ? ? ? row[I][J]='\x01'; ?
? ? ? ? ? ? ? ? ? ? showmine(); ?
? ? ? ? ? ? ? ? ? ? row[I][J]=temp; ?
? ? ? ? ? ? ? ? ? ? continue; ?
? ? ? ? ? ? ? ? } ?
? ? ? ? ? ? ? ? row[I][J]='\x01'; ?
? ? ? ? ? ? ? ? showmine(); ?
? ? ? ? ? ? } ?
? ? ? ? }else if(ch1=='s'){ ?
? ? ? ? ? ? if(i==13){ ?
? ? ? ? ? ? ? ? system("cls"); ?
? ? ? ? ? ? ? ? showmine(); ?
? ? ? ? ? ? ? ? continue; ?
? ? ? ? ? ? }else{ ?
? ? ? ? ? ? ? ? system("cls"); ?
? ? ? ? ? ? ? ? if(row[I][J]<'9' && row[I][J]>='0'){//防止當(dāng)前位數(shù)字覆蓋 ?
? ? ? ? ? ? ? ? ? ? i++; ?
? ? ? ? ? ? ? ? ? ? if(row[I][J]<'9' && row[I][J]>='0'){ //防止下一位數(shù)字覆蓋 ?
? ? ? ? ? ? ? ? ? ? ? ? temp=row[I][J]; ?
? ? ? ? ? ? ? ? ? ? ? ? row[I][J]='\x01'; ?
? ? ? ? ? ? ? ? ? ? ? ? showmine(); ?
? ? ? ? ? ? ? ? ? ? ? ? row[I][J]=temp; ?
? ? ? ? ? ? ? ? ? ? ? ? continue; ?
? ? ? ? ? ? ? ? ? ? } ?
? ? ? ? ? ? ? ? ? ? row[I][J]='\x01'; ?
? ? ? ? ? ? ? ? ? ? showmine(); ?
? ? ? ? ? ? ? ? ? ? continue; ?
? ? ? ? ? ? ? ? } ?
? ? ? ? ? ? ? ? row[I][J]='\x02'; ?
? ? ? ? ? ? ? ? i++; ?
? ? ? ? ? ? ? ? if(row[I][J]<'9' && row[I][J]>='0'){ ?
? ? ? ? ? ? ? ? ? ? temp=row[I][J]; ?
? ? ? ? ? ? ? ? ? ? row[I][J]='\x01'; ?
? ? ? ? ? ? ? ? ? ? showmine(); ?
? ? ? ? ? ? ? ? ? ? row[I][J]=temp; ?
? ? ? ? ? ? ? ? ? ? continue; ?
? ? ? ? ? ? ? ? } ?
? ? ? ? ? ? ? ? row[I][J]='\x01'; ?
? ? ? ? ? ? ? ? showmine(); ?
? ? ? ? ? ? } ?
? ? ? ? }else if (ch1=='a'){ ?
? ? ? ? ? ? if(j==0){ ?
? ? ? ? ? ? ? ? system("cls");
?? ??? ??? ??? ?if(row[I][J]<'9' && row[I][J]>='0'){ ?
?? ??? ??? ??? ??? ?temp=row[I][J]; ?
?? ??? ??? ??? ??? ?row[I][J]='\x01'; ?
?? ??? ??? ??? ??? ?showmine(); ?
?? ??? ??? ??? ??? ?row[I][J]=temp; ?
?? ??? ??? ??? ??? ?continue; ?
? ? ? ? ? ? ? ? }?
? ? ? ? ? ? ? ? showmine(); ?
? ? ? ? ? ? ? ? continue; ?
? ? ? ? ? ? }else{ ?
? ? ? ? ? ? ? ? system("cls"); ?
? ? ? ? ? ? ? ? if(row[I][J]<'9' && row[I][J]>='0'){ ?
? ? ? ? ? ? ? ? ? ? j--; ?
? ? ? ? ? ? ? ? ? ? if(row[I][J]<'9' && row[I][J]>='0'){ ?
? ? ? ? ? ? ? ? ? ? ? ? temp=row[I][J]; ?
? ? ? ? ? ? ? ? ? ? ? ? row[I][J]='\x01'; ?
? ? ? ? ? ? ? ? ? ? ? ? showmine(); ?
? ? ? ? ? ? ? ? ? ? ? ? row[I][J]=temp; ?
? ? ? ? ? ? ? ? ? ? ? ? continue; ?
? ? ? ? ? ? ? ? ? ? } ?
? ? ? ? ? ? ? ? ? ? row[I][J]='\x01'; ?
? ? ? ? ? ? ? ? ? ? showmine(); ?
? ? ? ? ? ? ? ? ? ? continue; ?
? ? ? ? ? ? ? ? } ?
? ? ? ? ? ? ? ? row[I][J]='\x02'; ?
? ? ? ? ? ? ? ? j--; ?
? ? ? ? ? ? ? ? if(row[I][J]<'9' && row[I][J]>='0'){ ?
? ? ? ? ? ? ? ? ? ? temp=row[I][J]; ?
? ? ? ? ? ? ? ? ? ? row[I][J]='\x01'; ?
? ? ? ? ? ? ? ? ? ? showmine(); ?
? ? ? ? ? ? ? ? ? ? row[I][J]=temp; ?
? ? ? ? ? ? ? ? ? ? continue; ?
? ? ? ? ? ? ? ? } ?
? ? ? ? ? ? ? ? row[I][J]='\x01'; ?
? ? ? ? ? ? ? ? showmine(); ?
? ? ? ? ? ? } ?
? ? ? ? }else if (ch1=='d'){ ?
? ? ? ? ? ? if(j==13){ ?
? ? ? ? ? ? ? ? system("cls"); ?
? ? ? ? ? ? ? ? showmine(); ?
? ? ? ? ? ? ? ? continue; ?
? ? ? ? ? ? }else{ ?
? ? ? ? ? ? ? ? system("cls"); ?
? ? ? ? ? ? ? ? if(row[I][J]<'9' && row[I][J]>='0'){ ?
? ? ? ? ? ? ? ? ? ? j++; ?
? ? ? ? ? ? ? ? ? ? if(row[I][J]<'9' && row[I][J]>='0'){ ?
? ? ? ? ? ? ? ? ? ? ? ? temp=row[I][J]; ?
? ? ? ? ? ? ? ? ? ? ? ? row[I][J]='\x01'; ?
? ? ? ? ? ? ? ? ? ? ? ? showmine(); ?
? ? ? ? ? ? ? ? ? ? ? ? row[I][J]=temp; ?
? ? ? ? ? ? ? ? ? ? ? ? continue; ?
? ? ? ? ? ? ? ? ? ? } ?
? ? ? ? ? ? ? ? ? ? row[I][J]='\x01'; ?
? ? ? ? ? ? ? ? ? ? showmine(); ?
? ? ? ? ? ? ? ? ? ? continue; ?
? ? ? ? ? ? ? ? } ?
? ? ? ? ? ? ? ? row[I][J]='\x02'; ?
? ? ? ? ? ? ? ? j++; ?
? ? ? ? ? ? ? ? if(row[I][J]<'9' && row[I][J]>='0'){ ?
? ? ? ? ? ? ? ? ? ? temp=row[I][J]; ?
? ? ? ? ? ? ? ? ? ? row[I][J]='\x01'; ?
? ? ? ? ? ? ? ? ? ? showmine(); ?
? ? ? ? ? ? ? ? ? ? row[I][J]=temp; ?
? ? ? ? ? ? ? ? ? ? continue; ?
? ? ? ? ? ? ? ? } ?
? ? ? ? ? ? ? ? row[I][J]='\x01'; ?
? ? ? ? ? ? ? ? showmine(); ?
? ? ? ? ? ? } ?
? ? ? ? }else if(ch1=='q'){ //挖雷消息識(shí)別&處理 ?
? ? ? ? ? ? system("cls"); ?
? ? ? ? ? ? if (mines[i][j]==1) ?//如果踩雷
? ? ? ? ? ? { ?
? ? ? ? ? ? ? ? printmine(); ?//打印全圖雷區(qū),游戲結(jié)束...
? ? ? ? ? ? ? ? printf("\n BOOM!\n\n"); ?
? ? ? ? ? ? ? ? flag=0; ?
? ? ? ? ? ? ? ? getch(); ?
? ? ? ? ? ? ? ? fflush(stdin); ?
? ? ? ? ? ? ? ? break;?
? ? ? ? ? ? }else{ ?
?? ??? ??? ??? ?//如果沒(méi)有踩雷...標(biāo)示本位地雷數(shù)目(從雷數(shù)統(tǒng)計(jì)圖讀?。?
? ? ? ? ? ? ? ? if(i>0 && j>0 && row[I][J]=='\x01'){ ?
? ? ? ? ? ? ? ? ? ? row[I][J]=(char)(mines_demo[i][j]+48); ?
?? ??? ??? ??? ??? ?countstep++;
? ? ? ? ? ? ? ? }else if(i==0 && j>0 && row[I][J]=='\x01'){ ?
? ? ? ? ? ? ? ? ? ? row[I][J]=(char)(mines_demo[i][j]+48);?
?? ??? ??? ??? ??? ?countstep++;
? ? ? ? ? ? ? ? }else if(i>0 && j==0 && row[I][J]=='\x01'){ ?
? ? ? ? ? ? ? ? ? ? row[I][J]=(char)(mines_demo[i][j]+48);?
?? ??? ??? ??? ??? ?countstep++;
? ? ? ? ? ? ? ? }else if(i==0 && j==0 && row[I][J]=='\x01'){ ?
? ? ? ? ? ? ? ? ? ? row[I][J]=(char)(mines_demo[i][j]+48); ?
?? ??? ??? ??? ??? ?countstep++;
? ? ? ? ? ? ? ? } ?
? ? ? ? ? ? ? ? if(mines_demo[i][j]==0 && i>0 && j>0 && i<13 && j<13){ ? ? ?//無(wú)雷地區(qū)自動(dòng)展開(kāi) ?
? ? ? ? ? ? ? ? ? ? if(mines_demo[i+1][j]==0 && row[I+1][J]=='\x02'){ ?
? ? ? ? ? ? ? ? ? ? ? ? row[I+1][J]=(char)(mines_demo[i+1][j]+48); ?
?? ??? ??? ??? ??? ??? ?countstep++;
? ? ? ? ? ? ? ? ? ? } ?
? ? ? ? ? ? ? ? ? ? if(mines_demo[i-1][j]==0 && row[I-1][J]=='\x02'){ ?
? ? ? ? ? ? ? ? ? ? ? ? row[I-1][J]=(char)(mines_demo[i-1][j]+48); ?
?? ??? ??? ??? ??? ??? ?countstep++;
? ? ? ? ? ? ? ? ? ? } ?
? ? ? ? ? ? ? ? ? ? if(mines_demo[i][j+1]==0 && row[I][2*(j+1+1)+1]=='\x02'){ ?
? ? ? ? ? ? ? ? ? ? ? ? row[I][2*(j+1+1)+1]=(char)(mines_demo[i][j+1]+48); ?
?? ??? ??? ??? ??? ??? ?countstep++;
? ? ? ? ? ? ? ? ? ? } ?
? ? ? ? ? ? ? ? ? ? if(mines_demo[i][j-1]==0 && row[I][2*(j-1+1)+1]=='\x02'){ ?
? ? ? ? ? ? ? ? ? ? ? ? row[I][2*(j-1+1)+1]=(char)(mines_demo[i][j+1]+48); ?
?? ??? ??? ??? ??? ??? ?countstep++;
? ? ? ? ? ? ? ? ? ? } ?
? ? ? ? ? ? ? ? ? ? if(mines_demo[i+1][j+1]==0 && row[I+1][2*(j+1+1)+1]=='\x02'){ ?
? ? ? ? ? ? ? ? ? ? ? ? row[I+1][2*(j+1+1)+1]=(char)(mines_demo[i+1][j+1]+48); ?
?? ??? ??? ??? ??? ??? ?countstep++;
? ? ? ? ? ? ? ? ? ? } ?
? ? ? ? ? ? ? ? ? ? if(mines_demo[i+1][j-1]==0 && row[I+1][2*(j-1+1)+1]=='\x02'){ ?
? ? ? ? ? ? ? ? ? ? ? ? row[I+1][2*(j-1+1)+1]=(char)(mines_demo[i+1][j+1]+48); ?
?? ??? ??? ??? ??? ??? ?countstep++;
? ? ? ? ? ? ? ? ? ? } ?
? ? ? ? ? ? ? ? ? ? if(mines_demo[i-1][j+1]==0 && row[I-1][2*(j+1+1)+1]=='\x02'){ ?
? ? ? ? ? ? ? ? ? ? ? ? row[I-1][2*(j+1+1)+1]=(char)(mines_demo[i-1][j+1]+48); ?
?? ??? ??? ??? ??? ??? ?countstep++;
? ? ? ? ? ? ? ? ? ? } ?
? ? ? ? ? ? ? ? ? ? if(mines_demo[i-1][j-1]==0 && row[I-1][2*(j-1+1)+1]=='\x02'){ ?
? ? ? ? ? ? ? ? ? ? ? ? row[I-1][2*(j-1+1)+1]=(char)(mines_demo[i-1][j+1]+48); ?
?? ??? ??? ??? ??? ??? ?countstep++;
? ? ? ? ? ? ? ? ? ? } ?
? ? ? ? ? ? ? ? } ?
? ? ? ? ? ? ? ? system("cls"); ?
? ? ? ? ? ? ? ? showmine(); ?
? ? ? ? ? ? ? ? if(countstep==196-n) ?
? ? ? ? ? ? ? ? { ?
? ? ? ? ? ? ? ? ? ? printf("\nYou Win!\n\n"); ?
? ? ? ? ? ? ? ? ? ? getch(); ?
? ? ? ? ? ? ? ? ? ? flag=0; ?
? ? ? ? ? ? ? ? ? ? break; ?
? ? ? ? ? ? ? ? } ?
? ? ? ? ? ? } ?
? ? ? ? } ?
? ? } ?
} ?
??
主函數(shù)結(jié)束/ ?
??
//數(shù)雷算法開(kāi)始// ?
void countmine(int rowno, int colno) ?
{ ?
? ? int count; ?
? ? int i,j; ?
? ? i=rowno; ?
? ? j=colno; ?
? ? mines_demo[i][j]=mines[i-1][j]+mines[i+1][j]+mines[i][j-1]+mines[i][j+1]+mines[i-1][j-1]+mines[i-1][j+1]+mines[i+1][j-1]+mines[i+1][j+1]; ? ?
? ? return; ?
} ?
/數(shù)雷算法結(jié)束 ?
void DebugMines()
{
?? ?int i=0 , j=0;
?? ?printf("\n\n");
?? ?for (i = 0 ; i < 14 ; i++)
?? ?{
?? ??? ?for (j=0;j<14;j++)
?? ??? ?{
?? ??? ??? ?printf("%d ",mines[i][j]);
?? ??? ?}
?? ??? ?printf("\n");
?? ?}
?? ?printf("\n\n");
?? ?for (i = 0 ; i < 14 ; i++)
?? ?{
?? ??? ?for (j=0;j<14;j++)
?? ??? ?{
?? ??? ??? ?printf("%d ",mines_demo[i][j]);
?? ??? ?}
?? ??? ?printf("\n");
?? ?}
}
///棋盤(pán)顯示/// ?
void showmine(){ ?
? ? int i=0,j=0; ?
? ? for(i=0;i<16;i++){ ?
? ? ? ? for(j=0;j<30;j++){ ?
? ? ? ? ? ? if(row[i][j]=='\xf'){ ?
? ? ? ? ? ? ? ? SetColor(4,0); ?
? ? ? ? ? ? ? ? printf("%c",row[i][j]); ?
? ? ? ? ? ? ? ? SetColor(7,0); ?
? ? ? ? ? ? ? ? continue; ?
? ? ? ? ? ? }else if(row[i][j]<='8' && row[i][j]>='0' && j>2){ ?
? ? ? ? ? ? ? ? SetColor(2,0); ?
? ? ? ? ? ? ? ? printf("%c",row[i][j]); ?
? ? ? ? ? ? ? ? SetColor(7,0); ?
? ? ? ? ? ? ? ? continue; ?
? ? ? ? ? ? } ?
? ? ? ? ? ? printf("%c",row[i][j]); ?
? ? ? ? } ?
? ? ? ? printf("\n"); ?
? ? }
?
} ?
??
/隨機(jī)布雷/// ?
void setmine(int x){ ?
? ? int i,j,k; ?
? ? //初始化棋盤(pán) ?
? ? for(i=0;i<14;i++){ ?
? ? ? ? for(j=0;j<14;j++){ ?
? ? ? ? ? ? mines[i][j]=0; ?
? ? ? ? } ?
? ? } ?
? ? //設(shè)置隨機(jī)種子 ?
? ? srand(time(0)); ?
? ? //隨機(jī)布雷開(kāi)始 ?
? ? for(k=1;k<=x;){ ?
? ? ? ? i=rand()%14; ?
? ? ? ? j=rand()%14; ?
? ? ? ? if(mines[i][j]!=1){ ?
? ? ? ? ? ? mines[i][j]=1; ?
? ? ? ? ? ? k++; ?
? ? ? ? }else{ ?
? ? ? ? ? ? continue; ?
? ? ? ? } ?
? ? } ?
?? ?//方格雷數(shù)計(jì)算開(kāi)始
? ? for(i=0;i<14;i++){ ?
? ? ? ? for(j=0;j<14;j++){ ?
? ? ? ? ? ? if(i>0 && j>0 && i<13 && j<13){ ?
? ? ? ? ? ? ? ? countmine(i,j); ?
? ? ? ? ? ? }else{ //預(yù)置方格雷數(shù)計(jì)算?
? ? ? ? ? ? ? ? //if(mines[i][j]!=1){ ?
? ? ? ? ? ? ? ? ? ? if(i==0 && j!=0 && j!=13){ ?
? ? ? ? ? ? ? ? ? ? ? ? mines_demo[0][j]=mines[0][j-1]+mines[1][j]+mines[0][j+1]+mines[1][j-1]+mines[1][j+1]; ?
? ? ? ? ? ? ? ? ? ? }else if(j==0 && i!=0 && i!=13){ ?
? ? ? ? ? ? ? ? ? ? ? ? mines_demo[i][0]=mines[i-1][0]+mines[i+1][0]+mines[i-1][1]+mines[i+1][1]+mines[i][1]; ?
? ? ? ? ? ? ? ? ? ? }else if(i==0 && j==0){ ?
? ? ? ? ? ? ? ? ? ? ? ? mines_demo[0][0]=mines[0][1]+mines[1][1]+mines[1][0]; ?
? ? ? ? ? ? ? ? ? ? }else if(i==13 && j==13){ ?
? ? ? ? ? ? ? ? ? ? ? ? mines_demo[13][13]=mines[12][13]+mines[12][12]+mines[13][12]; ?
? ? ? ? ? ? ? ? ? ? }else if(i==0 && j==13){ ?
? ? ? ? ? ? ? ? ? ? ? ? mines_demo[0][13]=mines[0][12]+mines[1][12]+mines[1][13]; ?
? ? ? ? ? ? ? ? ? ? }else if(i==13 && j==0){ ?
? ? ? ? ? ? ? ? ? ? ? ? mines_demo[13][0]=mines[12][0]+mines[12][1]+mines[13][1]; ?
? ? ? ? ? ? ? ? ? ? }else if(i==13 && j!=0 && j!=13){
?? ??? ??? ??? ??? ??? ?mines_demo[i][j] = mines[i][j-1]+mines[i][j+1]+mines[i-1][j-1]+mines[i-1][j]+mines[i-1][j+1];
?? ??? ??? ??? ??? ?}else if (j==13 && i!=0 && i!=13)
?? ??? ??? ??? ??? ?{
?? ??? ??? ??? ??? ??? ?mines_demo[i][j] = mines[i+1][j]+mines[i-1][j]+mines[i-1][j-1]+mines[i][j-1]+mines[i+1][j-1];
?? ??? ??? ??? ??? ?}
? ? ? ? ? ? ? ? //} ?
? ? ? ? ? ? } ?
? ? ? ? } ?
? ? } ?
? ? return; ?
} ?
??
/打印雷區(qū)(失敗時(shí))/// ?
void printmine() ?
{ ?
? ? int i,j; ?
? ? system("cls"); ?
? ? for(i=0;i<14;i++) ?
? ? { ?
? ? ? ? for(j=0;j<14;j++){ ?
? ? ? ? ? ? if( mines[i][j]==1){ ?
? ? ? ? ? ? ? ? row[I][J]='\xf'; ?
? ? ? ? ? ? }else{ ?
? ? ? ? ? ? ? ? row[I][J]='\x02'; ?
? ? ? ? ? ? } ?
? ? ? ? } ?
??
? ? } ?
? ? showmine(); ?
? ? return; ?
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • C++中std::thread線(xiàn)程用法

    C++中std::thread線(xiàn)程用法

    本文主要介紹了C++中std::thread線(xiàn)程用法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-01-01
  • C語(yǔ)言實(shí)現(xiàn)520表白代碼 祝你表白成功!

    C語(yǔ)言實(shí)現(xiàn)520表白代碼 祝你表白成功!

    這篇文章主要為大家詳細(xì)介紹了C語(yǔ)言實(shí)現(xiàn)520表白代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-05-05
  • C++實(shí)現(xiàn)LeetCode(23.合并k個(gè)有序鏈表)

    C++實(shí)現(xiàn)LeetCode(23.合并k個(gè)有序鏈表)

    這篇文章主要介紹了C++實(shí)現(xiàn)LeetCode(23.合并k個(gè)有序鏈表),本篇文章通過(guò)簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-07-07
  • 深入串的模式匹配算法(普通算法和KMP算法)的詳解

    深入串的模式匹配算法(普通算法和KMP算法)的詳解

    本篇文章是對(duì)串的模式匹配算法(普通算法和KMP算法)的應(yīng)用進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-05-05
  • C語(yǔ)言實(shí)現(xiàn)猜數(shù)字小游戲的示例代碼

    C語(yǔ)言實(shí)現(xiàn)猜數(shù)字小游戲的示例代碼

    猜數(shù)字小游戲是我們小時(shí)候喜歡我們一個(gè)經(jīng)典小游戲。這篇文章將利用C語(yǔ)言中的循環(huán)語(yǔ)句、分支語(yǔ)句和函數(shù)實(shí)現(xiàn)這一游戲,需要的可以參考一下
    2022-10-10
  • C++類(lèi)與對(duì)象的詳細(xì)說(shuō)明

    C++類(lèi)與對(duì)象的詳細(xì)說(shuō)明

    這篇文章主要為大家詳細(xì)介紹了C++的類(lèi)與對(duì)象,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助
    2022-02-02
  • C++中const關(guān)鍵字的用法圖文詳解

    C++中const關(guān)鍵字的用法圖文詳解

    在C++中const是一個(gè)關(guān)鍵字,用于聲明常量,它可以用于多種情況,包括聲明常量變量、常量指針、以及成員函數(shù)中的常量性,這篇文章主要給大家介紹了關(guān)于C++中const關(guān)鍵字用法的相關(guān)資料,需要的朋友可以參考下
    2024-08-08
  • C++日歷拼圖的解法你了解嗎

    C++日歷拼圖的解法你了解嗎

    這篇文章主要為大家詳細(xì)介紹了日歷拼圖C++的解法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助
    2022-02-02
  • OpenCV透視變換應(yīng)用之書(shū)本視圖矯正+廣告屏幕切換

    OpenCV透視變換應(yīng)用之書(shū)本視圖矯正+廣告屏幕切換

    透視變換是指利用透視中心、像點(diǎn)、目標(biāo)點(diǎn)三點(diǎn)共線(xiàn)的條件,按透視旋轉(zhuǎn)定律使承影面繞跡線(xiàn)旋轉(zhuǎn)某一角度,破壞原有的投影光線(xiàn)束,仍能保持承影面上投影幾何圖形不變的變換。本文將為大家介紹兩個(gè)OpenCV透視變換應(yīng)用,需要的可以參考一下
    2022-08-08
  • C++直接初始化與復(fù)制初始化的區(qū)別深入解析

    C++直接初始化與復(fù)制初始化的區(qū)別深入解析

    這篇文章主要介紹了C++直接初始化與復(fù)制初始化的區(qū)別深入解析,是很多C++初學(xué)者需要深入了解的重要概念,需要的朋友可以參考下
    2014-09-09

最新評(píng)論

阿合奇县| 灯塔市| 志丹县| 涿州市| 甘肃省| 黑河市| 温宿县| 庆城县| 山西省| 抚州市| 遂宁市| 安龙县| 贞丰县| 页游| 遵义县| 丽江市| 明光市| 新河县| 宝丰县| 东阿县| 阿拉善右旗| 白城市| 高州市| 舒兰市| 阿荣旗| 江城| 潜山县| 武山县| 灵丘县| 青海省| 夏津县| 江阴市| 泰来县| 新民市| 隆林| 龙胜| 五华县| 宁南县| 枣庄市| 大荔县| 夏津县|