C#Mines(布雷)代码,第1张

C#Mines(布雷)代码,第2张

本文给出了一个C# Mines的代码,初学者可以研究一下。

以下是一段引用片段:
使用System。收藏;
使用系统。木卫一;
使用系统;
命名空间com。mines
{
class searching mines
{
public ArrayList list = new ArrayList();
public int[,] mines = new int[10,10];
static void Main(string[]args)
{
searching mines sm = new searching mines();
sm . init mines();
sm。hiden mines();
sm。FillInOtherNumber();
sm . display();
// sm。save txt();
}
public void init mines()
{
for(int I = 0;I < this . mines . getlength(0);i++)
{
for(int j = 0;j < this . mines . getlength(1);j++)
{
this.mines[i,j]= 0;
列表。Add(this.mines[i,j]);
}
}
}
public void hiden mines()
{
Random r = new Random();
for(int I = 0;I < 9;i++)
{
int count = this . list . count;
int number = r . Next(count);
int row = number/10;
int column = number % 10;
this . mines[行,列]= 9;
this . list . remove at(this . mines[row,column]);
}
}
public void FillInOtherNumber()
{
try
{
for(int I = 0;I < this . mines . getlength(0);i++)
{
for(int j = 0;j < this . mines . getlength(1);j++)
{
int left = j-1;
int right = j+1;
int top = I-1;
int bottom = I+1;
if (this.mines[i,j]!= 9)
{
if(top > = 0 & & left > = 0)//left and top
{
if(this . mines[top,left]= = 9)//判断左上是否为9[
}
}
if(top > = 0 & & right {
if(this . mines[top,right]= = 9)//判断点的右上是否为
{

}
}
if(top > = 0)//top
{
if(this . mines[top,j]= = 9)//是最上面的一个9

}
}
if(left > = 0)//最左边的
{
if (this.mines [i,left]= = 9)//看看左边的是不是9

}
}
if(对{
if(这个。mines [i,right]= 9)//看看右边是不是9
{
mines [i,j]。
}

位律师回复
DABAN RP主题是一个优秀的主题,极致后台体验,无插件,集成会员系统
白度搜_经验知识百科全书 » C#Mines(布雷)代码

0条评论

发表评论

提供最优质的资源集合

立即查看 了解详情