扫雷游戏
2026-07-09 19:40:57
发布于:浙江
六年级小学生自制的扫雷游戏,稍有些劣质
下载链接
密码:1234
麻烦顶一下
点赞过10公开代码
2026.6.19,点赞达到十个,公开代码:
2026.7.5,更新为使用wasd移动光标翻开,并增加标记和重开功能
特别鸣谢:@bits/stdc++.h
2026.7.9,取消了部分特性,增加了按下任意键加速对话的功能
#include<bits/stdc++.h>
#include<windows.h>
#include <conio.h>
using namespace std;
void sleep(int x){
Sleep(x/10);
for(int i=1;i<=x/10*9;i++){
if(_kbhit())break;
for(int i=1;i<=4e5;i++);
}
}
bool lei[15][15];//是否有雷
int n/*长和宽*/=9,cnt1/*雷的数量*/,cnt2/*亮了几个*/;
int zhou[15][15]/*周围几颗雷*/ ,x,y,biao[15][15],first=0;
bool f[15][15];//是否亮出
void gotoxy(short x,short y){
COORD pos={x,y};
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOut,pos);
}
void start(){
srand(time(0));
memset(lei,0,sizeof(lei));
memset(zhou,0,sizeof(zhou));
memset(f,0,sizeof(f));
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(rand()%8==0)lei[i][j]=1;
if(lei[i][j])cnt1++;
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
for(int a=i-1;a<=i+1;a++){
for(int b=j-1;b<=j+1;b++){
if(lei[a][b])zhou[i][j]++;
}
}
}
}
}
void out(){
gotoxy(0,0);
cout<<"雷的数量:"<<cnt1<<"\n\n ";
for(int i=1;i<=n;i++)cout<<" "<<i<<" ";cout<<"\n ";
for(int i=1;i<=n;i++)cout<<"---";cout<<"\n";
for(int i=1;i<=n;i++){
cout<<' '<<i<<" | ";
for(int j=1;j<=n;j++){
if(f[i][j]){
if(lei[i][j]){
if(x==i&&y==j)cout<<"[*]";
else cout<<" * ";
}else{
if(zhou[i][j]!=0)if(x==i&&y==j)cout<<"["<<zhou[i][j]<<"]";
else cout<<' '<<zhou[i][j]<<' ';
else if(x==i&&y==j)cout<<"[ ]";
else cout<<" ";
}
} else{
if(x==i&&y==j)
if(biao[i][j])cout<<"[*]";
else cout<<"[?]";
else
if(biao[i][j])cout<<"(*)";
else cout<<"(?)";
}
}
cout<<"\n";
}
cout<<"\n使用wasd移动,[ ]处是当前光标,按下 O 键翻开,按下 P 键标记/取消标记\n";
}
void end(){
cout<<"雷的数量:"<<cnt1<<"\n\n ";
for(int i=1;i<=n;i++)cout<<" "<<i<<" ";cout<<"\n ";
for(int i=1;i<=n;i++)cout<<"---";cout<<"\n";
for(int i=1;i<=n;i++){
cout<<' '<<i<<" | ";
for(int j=1;j<=n;j++){
if(lei[i][j]){
cout<<" * ";
} else{
if(zhou[i][j]!=0)cout<<' '<<zhou[i][j]<<' ';
else cout<<" ";
}
}
cout<<"\n";
}
}
void fan(int x,int y){
if(zhou[x][y]==0){
for(int i=x-1;i<=x+1;i++){
for(int j=y-1;j<=y+1;j++){
if(f[i][j]==0&&i>=1&&i<=n&&j>=1&&j<=n){
cnt2++;
f[i][j]=1;
if(zhou[i][j]==0){
//cout<<x<<','<<y<<"-翻开->"<<i<<','<<j<<'\n';
//system("pause");
fan(i,j);
}
}
}
}
}
}
void slow_print(string s){
for(int i=0;i<s.size();i+=2){
cout<<s[i];
if(s[i+1]!='\0')cout<<s[i+1];
sleep(30);
}
}
void jianjie(){
first=1;
cout<<" _ ______________\n";
cout<<" | | |______ ______|\n";
cout<<" _| |_ _______ | ___ ___ |\n";
cout<<"|_ _| |_____ | | ||_|| ||_|| |\n";
cout<<" | | _____| | |_||_||__||_||_|\n";
cout<<" _| |_ |_____ | ______________\n";
cout<<"|_ _/ _____| | | ___ ___ |\n";
cout<<" | | |_______| | |___| |___| |\n";
cout<<" | | | ___ ___ |\n";
cout<<" _| | | |___| |___| |\n";
cout<<" \\__/ |______________| \n";
cout<<"";system("pause");system("cls");system("color F0");
slow_print("欢迎游玩扫雷游戏\n");sleep(500);
slow_print("作者:Little | Chen\n");sleep(500);
system("pause");system("cls");
slow_print("扫雷游戏的规则:\n");sleep(500);
slow_print("扫雷游戏的目标是点开所有安全格,胜利条件为所有非雷格被打开。\n");sleep(500);
slow_print("一个非雷格旁的八格里如果存在地雷,那么这个格子被翻开时就会显示周围八个格子中有几个雷\n");sleep(500);
slow_print("Tips:建议使用英文输入法游玩\n");sleep(500);
system("pause");
}
int main(){
memset(lei,0,sizeof(lei));
memset(zhou,0,sizeof(zhou));
memset(biao,0,sizeof(biao));
memset(f,0,sizeof(f));
cnt1=cnt2=0;
system("color F0");
if(first==0)jianjie();//去掉这行就没有自我介绍
start();//去掉这行没有雷
//end();
//return 0;
x=1,y=1;
system("cls");
while(cnt2+cnt1!=n*n){
out();
char c;
c=getch();
if((c=='a'||c=='A')&&y>1)y--;
else if((c=='w'||c=='W')&&x>1)x--;
else if((c=='s'||c=='S')&&x<n)x++;
else if((c=='d'||c=='D')&&y<n)y++;
else if((c=='p'||c=='P')&&f[x][y]==0)biao[x][y]=!biao[x][y];
if((c=='o'||c=='O')&&biao[x][y]==0){
if(lei[x][y]){
system("cls");
system("color F4");
cout<<"你输了!\n";
end();
system("pause");
while(1){
system("cls");
system("color F0");
cout<<"按下空格重新开始. . . \n";
char c;
c=getch();
if(c==' '){
main();
return 0;
}
}
return 0;
}else{
if(f[x][y]==0){
f[x][y]=1;
cnt2++;
if(zhou[x][y]==0)fan(x,y);
}
}
}
}
system("cls");
system("color F6");
cout<<"你赢了!\n";
end();
system("pause");
while(1){
system("cls");
system("color F0");
cout<<"按下空格重新开始. . . \n";
char c;
c=getch();
if(c==' '){
main();
return 0;
}
}
return 0;
}
全部评论 14
顶(个_个)
2026-06-16 来自 浙江
3@wyh @[安全总监]德穆兰来看看我做的扫雷游戏
2026-06-16 来自 浙江
3”看不到“
2026-06-23 来自 浙江
0
我康康
2026-06-17 来自 天津
25
2026-06-17 来自 浙江
2有点bug,在修
2026-06-17 来自 浙江
2已修完bug
2026-06-17 来自 浙江
1置顶一下
2026-06-23 来自 浙江
0置顶完之后,把我的评论删掉
2026-06-23 来自 浙江
0
来,我点赞了,刚好到10!!!
2026-06-19 来自 广东
1d
2026-06-21 来自 浙江
0顶
2026-06-19 来自 浙江
0d
2026-06-19 来自 浙江
0d
2026-06-19 来自 浙江
0d
2026-06-19 来自 浙江
0d
2026-06-19 来自 浙江
0d
2026-06-19 来自 浙江
0顶
2026-06-18 来自 浙江
0顶
2026-06-18 来自 浙江
1顶
2026-06-18 来自 浙江
1顶
2026-06-18 来自 浙江
1





































有帮助,赞一个