C# Mines(布雷) 代码

lana1101

lana1101

2016-02-19 13:47

下面图老师小编跟大家分享一个简单易学的C# Mines(布雷) 代码教程,get新技能是需要行动的,喜欢的朋友赶紧收藏起来学习下吧!

  本文给出一个 C# Mines(布雷)的 代码,新手研究一下吧。

(本文来源于图老师网站,更多请访问https://m.tulaoshi.com/bianchengyuyan/)

以下是引用片段:
  using System.Collections;
  using System.IO;
  using System;
  namespace com.Mines
  {
  class SearchingMines
  {
  public ArrayList list = new ArrayList();
  public int[,] mines = new int[10, 10];
  static void Main(string[] args)
  {
  SearchingMines sm = new SearchingMines();
  sm.initMines();
  sm.HidenMines();
  sm.FillInOtherNumber();
  sm.display();
  // sm.SaveTxt();
  }
  public void initMines()
  {
  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;
  list.Add(this.mines[i, j]);
  }
  }
  }
  public void HidenMines()
  {
  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[row, column] = 9;
  this.list.RemoveAt(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)//左边和上边
  {
  if (this.mines[top, left] == 9)//判断左上方是否为9
  {
  mines[i,j] += 1;
  }
  }
  if(top=0 && right10)//右边和上边
  {
  if (this.mines[top, right] == 9)//判断该点的右上方是否
  {
  mines[i,j] += 1;
  }
  }
  if(top=0)//最上边
  {
  if (this.mines[top, j] == 9)//上边的那个是否为9
  {
  mines[i,j] += 1;
  }
  }
  if(left=0)//最左边
  {
  if (this.mines[i, left] == 9)//看左边那个是否为9
  {
  mines[i,j] += 1;
  }
  }
  if(right10)//最右边
  {
  if (this.mines[i, right] == 9)//看右边是否为9
  {
  mines[i,j] += 1;
  }

以下是引用片段:
  }
  if(bottom10 && left =0)//底部和左边
  {
  if (this.mines[bottom, left] == 9)//左下方是否为9
  {
  mines[i,j] += 1;
  }
  }
  if(bottom10 && right10)//右下方
  {
  if (this.mines[bottom, right] == 9)右下方
  {
  mines[i,j] += 1;
  }
  }
  if(bottom10)//底部
  {
  if (this.mines[bottom, j] == 9)//底部是否为9
  {
  mines[i,j] += 1;
  }
  }
  // if (left  0)//左边
  // {
  // if (this.mines[i, right] == 9)//右侧是否为9
  // { count += 1; }
  // if (bottom  10 && bottom  0)//如果底边的范围是除过头节点和尾节点
  // {
  // if (this.mines[bottom, j] == 9)//底部是否为9
  // { count += 1; }
  // if (this.mines[bottom, right] == 9)//右下是否为9
  // { count += 1; }
  // }
  // if (top  0 && top  10)//上边除过头结点和尾节点
  // {
  // if (this.mines[top, j] == 9)//头上那个点是否为9
  // { count += 1; }
  // if (this.mines[top, right] == 9)//右上是否为9
  // { count += 1; }
  // }
  // }
  // if (j == this.mines.GetLength(0))
  // {
  // if (i == 0)
  // {
  // if (this.mines[i, j - 1] == 9)
  // { count += 1; }
  // if (this.mines[i - 1, j - 1] == 9)
  // { count += 1; }
  // if (this.mines[i - 1, j] == 9)
  // { count += 1; }
  //
  // }
  // if(i0&&i 
  // {
  // if(this.mines[i+1,j-1]==9)
  // {count+=1;}
  // if (this.mines[i + 1, j] == 9)
  // { count += 1; }
  // if (this.mines[i, j - 1] == 9)
  // { count += 1; }
  // if (this.mines[i - 1, j] == 9)
  // { count += 1; }
  // if (this.mines[i - 1, j - 1] == 9)
  // { count += 1; }
  // }
  // if (i == this.mines.GetLength(1))
  // {
  // if (this.mines[i - 1, j - 1]==9)
  // { count += 1; }
  // if (this.mines[i - 1, j] == 9)
  // { count += 1; }
  // if (this.mines[i, j - 1] == 9)
  // { count += 1; }
  // }
  // }
  // this.mines[i, j] = count;
  }
  }
  }
  }

  本文给出一个 C# Mines(布雷)的 代码,新手研究一下吧。

(本文来源于图老师网站,更多请访问https://m.tulaoshi.com/bianchengyuyan/)(本文来源于图老师网站,更多请访问https://m.tulaoshi.com/bianchengyuyan/)

以下是引用片段:
  using System.Collections;
  using System.IO;
  using System;
  namespace com.Mines
  {
  class SearchingMines
  {
  public ArrayList list = new ArrayList();
  public int[,] mines = new int[10, 10];
  static void Main(string[] args)
  {
  SearchingMines sm = new SearchingMines();
  sm.initMines();
  sm.HidenMines();
  sm.FillInOtherNumber();
  sm.display();
  // sm.SaveTxt();
  }
  public void initMines()
  {
  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;
  list.Add(this.mines[i, j]);
  }
  }
  }
  public void HidenMines()
  {
  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[row, column] = 9;
  this.list.RemoveAt(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)//左边和上边
  {
  if (this.mines[top, left] == 9)//判断左上方是否为9
  {
  mines[i,j] += 1;
  }
  }
  if(top=0 && right10)//右边和上边
  {
  if (this.mines[top, right] == 9)//判断该点的右上方是否
  {
  mines[i,j] += 1;
  }
  }
  if(top=0)//最上边
  {
  if (this.mines[top, j] == 9)//上边的那个是否为9
  {
  mines[i,j] += 1;
  }
  }
  if(left=0)//最左边
  {
  if (this.mines[i, left] == 9)//看左边那个是否为9
  {
  mines[i,j] += 1;
  }
  }
  if(right10)//最右边
  {
  if (this.mines[i, right] == 9)//看右边是否为9
  {
  mines[i,j] += 1;
  }

以下是引用片段:
  catch (Exception ex)
  {
  Console.WriteLine(ex.Message);
  }
  }
  public void display()
  {
  for (int i = 0; i  this.mines.GetLength(0); i++)
  {
  for (int j = 0; j  this.mines.GetLength(1); j++)
  {
  Console.Write(this.mines[i, j] + " ");
  }
  Console.Write("n");
  }
  }
  public void SaveTxt()
  {
  StreamWriter sw = new StreamWriter(@"c:abc.txt");
  for (int i = 0; i  this.mines.GetLength(0); i++)
  {
  for (int j = 0; j  this.mines.GetLength(1); j++)
  {
  sw.Write(this.mines[i, j] + " ");
  }
  sw.WriteLine();
  }
  sw.Flush();
  sw.Close();
  }
  }
  }

展开更多 50%)
分享

猜你喜欢

C# Mines(布雷) 代码

编程语言 网络编程
C# Mines(布雷) 代码

索引服务调用代码(C#)

电脑网络
索引服务调用代码(C#)

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

用C#操纵IIS(代码)

编程语言 网络编程
用C#操纵IIS(代码)

C#独立域名查询代码

编程语言 网络编程
C#独立域名查询代码

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

C# WORD操作实现代码

编程语言 网络编程
C# WORD操作实现代码

C# 游戏外挂实现核心代码

编程语言 网络编程
C# 游戏外挂实现核心代码

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

加快Win8系统上网速度的方法

加快Win8系统上网速度的方法

将html转成ubb代码的正则

将html转成ubb代码的正则
下拉加载更多内容 ↓