欢迎来到天天文库
浏览记录
ID:34004903
大小:77.50 KB
页数:10页
时间:2019-03-03
《c#控制台实现扫雷程序》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、秦申学qinshenxue@163.comC#在控制台实现扫雷程序最终运行结果如图所示使用说明玩法同系统自带扫雷游戏规则按Enter键”踩有无雷”按M键标记有雷区域usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespacetest{classProgram{staticvoidMain(string[]args){intn=int.Parse(Console.ReadLine());//用户输入扫雷二维数组大小int[,]mine=newint[n,n];
2、//定义一个扫雷二维数组int[,]record=newint[n,n];//定义一个记录用户当前判定情况的二维数组int[,]amount=newint[n,n];//记录以当前方块为中心的周围八个方块中雷的数量intmc=0;for(inti=0;i3、/3;//从0到2中产生随机数0,1其中0代表无雷,而1代表有雷}}//遍历出雷的数量for(inti2=0;i24、5、j-1<06、7、i+1>n-18、9、j+1>n-1){if(i-1<0&&j-1<0)//左上角{if(mine[i10、+1,j]==1)mine_count++;if(mine[i,j+1]==1)mine_count++;if(mine[i+1,j+1]==1)mine_count++;amount[i,j]=mine_count;mine_count=0;}秦申学qinshenxue@163.comif(j-1>=0&&j+1<=n-1&&i-1<0)//上边{if(mine[i,j-1]==1)mine_count++;if(mine[i+1,j-1]==1)mine_count++;if(mine[i+1,j]==1)mine_count++;if(mine[i+1,j+1]=11、=1)mine_count++;if(mine[i,j+1]==1)mine_count++;amount[i,j]=mine_count;mine_count=0;}if(i-1<0&&j+1>n-1)//右上角{if(mine[i,j-1]==1)mine_count++;if(mine[i+1,j-1]==1)mine_count++;if(mine[i+1,j]==1)mine_count++;amount[i,j]=mine_count;mine_count=0;}if(j+1>n-1&&i-1>=0&&i+1<=n-1)//右边{if(mine[i-1,j]12、==1)mine_count++;if(mine[i-1,j-1]==1)mine_count++;if(mine[i,j-1]==1)mine_count++;if(mine[i+1,j-1]==1)mine_count++;if(mine[i+1,j]==1)mine_count++;amount[i,j]=mine_count;mine_count=0;}if(i+1>n-1&&j+1>n-1)//右下角{if(mine[i-1,j-1]==1)秦申学qinshenxue@163.commine_count++;if(mine[i-1,j]==1)mine_cou13、nt++;if(mine[i,j-1]==1)mine_count++;amount[i,j]=mine_count;mine_count=0;}if(i+1>n-1&&j-1>=0&&j+1<=n-1)//下边{if(mine[i-1,j-1]==1)mine_count++;if(mine[i,j-1]==1)mine_count++;if(mine[i-1,j]==1)mine_count++;if(mine[i-1,j+1]==1)mine_count++;if(mine[i,j+1]==1)mine_count++;amount
3、/3;//从0到2中产生随机数0,1其中0代表无雷,而1代表有雷}}//遍历出雷的数量for(inti2=0;i24、5、j-1<06、7、i+1>n-18、9、j+1>n-1){if(i-1<0&&j-1<0)//左上角{if(mine[i10、+1,j]==1)mine_count++;if(mine[i,j+1]==1)mine_count++;if(mine[i+1,j+1]==1)mine_count++;amount[i,j]=mine_count;mine_count=0;}秦申学qinshenxue@163.comif(j-1>=0&&j+1<=n-1&&i-1<0)//上边{if(mine[i,j-1]==1)mine_count++;if(mine[i+1,j-1]==1)mine_count++;if(mine[i+1,j]==1)mine_count++;if(mine[i+1,j+1]=11、=1)mine_count++;if(mine[i,j+1]==1)mine_count++;amount[i,j]=mine_count;mine_count=0;}if(i-1<0&&j+1>n-1)//右上角{if(mine[i,j-1]==1)mine_count++;if(mine[i+1,j-1]==1)mine_count++;if(mine[i+1,j]==1)mine_count++;amount[i,j]=mine_count;mine_count=0;}if(j+1>n-1&&i-1>=0&&i+1<=n-1)//右边{if(mine[i-1,j]12、==1)mine_count++;if(mine[i-1,j-1]==1)mine_count++;if(mine[i,j-1]==1)mine_count++;if(mine[i+1,j-1]==1)mine_count++;if(mine[i+1,j]==1)mine_count++;amount[i,j]=mine_count;mine_count=0;}if(i+1>n-1&&j+1>n-1)//右下角{if(mine[i-1,j-1]==1)秦申学qinshenxue@163.commine_count++;if(mine[i-1,j]==1)mine_cou13、nt++;if(mine[i,j-1]==1)mine_count++;amount[i,j]=mine_count;mine_count=0;}if(i+1>n-1&&j-1>=0&&j+1<=n-1)//下边{if(mine[i-1,j-1]==1)mine_count++;if(mine[i,j-1]==1)mine_count++;if(mine[i-1,j]==1)mine_count++;if(mine[i-1,j+1]==1)mine_count++;if(mine[i,j+1]==1)mine_count++;amount
4、
5、j-1<0
6、
7、i+1>n-1
8、
9、j+1>n-1){if(i-1<0&&j-1<0)//左上角{if(mine[i
10、+1,j]==1)mine_count++;if(mine[i,j+1]==1)mine_count++;if(mine[i+1,j+1]==1)mine_count++;amount[i,j]=mine_count;mine_count=0;}秦申学qinshenxue@163.comif(j-1>=0&&j+1<=n-1&&i-1<0)//上边{if(mine[i,j-1]==1)mine_count++;if(mine[i+1,j-1]==1)mine_count++;if(mine[i+1,j]==1)mine_count++;if(mine[i+1,j+1]=
11、=1)mine_count++;if(mine[i,j+1]==1)mine_count++;amount[i,j]=mine_count;mine_count=0;}if(i-1<0&&j+1>n-1)//右上角{if(mine[i,j-1]==1)mine_count++;if(mine[i+1,j-1]==1)mine_count++;if(mine[i+1,j]==1)mine_count++;amount[i,j]=mine_count;mine_count=0;}if(j+1>n-1&&i-1>=0&&i+1<=n-1)//右边{if(mine[i-1,j]
12、==1)mine_count++;if(mine[i-1,j-1]==1)mine_count++;if(mine[i,j-1]==1)mine_count++;if(mine[i+1,j-1]==1)mine_count++;if(mine[i+1,j]==1)mine_count++;amount[i,j]=mine_count;mine_count=0;}if(i+1>n-1&&j+1>n-1)//右下角{if(mine[i-1,j-1]==1)秦申学qinshenxue@163.commine_count++;if(mine[i-1,j]==1)mine_cou
13、nt++;if(mine[i,j-1]==1)mine_count++;amount[i,j]=mine_count;mine_count=0;}if(i+1>n-1&&j-1>=0&&j+1<=n-1)//下边{if(mine[i-1,j-1]==1)mine_count++;if(mine[i,j-1]==1)mine_count++;if(mine[i-1,j]==1)mine_count++;if(mine[i-1,j+1]==1)mine_count++;if(mine[i,j+1]==1)mine_count++;amount
此文档下载收益归作者所有