求一份c#编程的最简单的扫雷游戏代码,不要任何功能,如英雄版,中级,高级等,只要能扫,急需!!!!!! 20
展开全部
我有一份自己练习用的代码。。
控件画的比较难看而已。。
功能只有 LOAD 把雷和附近8个格的判断赋值好。。
左键判断是否踩雷。。
右键“小红旗”无法点击。
就这3个主要的功能。。
另 我也是刚学半年的新手 知识也不是很多。。
控件画的比较难看而已。。
功能只有 LOAD 把雷和附近8个格的判断赋值好。。
左键判断是否踩雷。。
右键“小红旗”无法点击。
就这3个主要的功能。。
另 我也是刚学半年的新手 知识也不是很多。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
留邮箱~我可以发项目文件给你
//Creat.dll 生成雷
using System;
namespace Creat
{
/// <summary>
/// 产生一个随机填充9的二维数组。
/// </summary>
sealed public class creat
{
private bool is_user_define = false;
/// <summary>
/// 是否为用户自定义的大小?
/// </summary>
public bool Is_user_define
{
set
{
is_user_define = value;
}
}
private int Arraywidth = 0;
/// <summary>
/// 如果为用户自定义的大小,则表示雷区宽。
/// </summary>
public int User_define_Arraywidth
{
set
{
Arraywidth =value;
}
}
private int Arrayheight = 0;
/// <summary>
/// 如果为用户自定义的大小,则表示雷区高。
/// </summary>
public int User_define_Arrayheight
{
set
{
Arrayheight =value;
}
}
private int leinum = 0;
/// <summary>
/// 如果为用户自定义的大小,则表示雷数。
/// </summary>
public int User_define_leinum
{
set
{
leinum =value;
}
get
{
return leinum;
}
}
private int lev = 1;
/// <summary>
/// 系统自定义难度v。
/// </summary>
public int User_define_lev
{
set
{
lev =value;
}
}
private int[,] output_Array;
/// <summary>
/// 输出结果Array。
/// </summary>
public int[,] Output_Array
{
get
{
return output_Array;
}
}
private int output_height;
/// <summary>
/// 输出Array的高,即数组[i,j]的i值。
/// </summary>
public int Output_height
{
get
{
return output_height;
}
}
private int output_width;
/// <summary>
/// 输出Array的宽,即数组[i,j]的j值。
/// </summary>
public int Output_width
{
get
{
return output_width;
}
}
private string output_string;
/// <summary>
/// 输出出错信息。
/// </summary>
public string Output_string
{
get
{
return output_string;
}
}
/// <summary>
/// 输入一系列值,执行这个方法后得到Output_Array。
/// </summary>
public void creatarray()
{
if(!this.is_user_define)
{
if(lev == 1)
{
Arrayheight = 9;
Arraywidth = 9;
leinum = 5;
}
else if(lev == 2)
{
Arrayheight = 16;
Arraywidth = 16;
leinum = 28;
}
else if(lev == 3)
{
Arrayheight = 20;
Arraywidth = 30;
leinum = 80;
}
else
{
output_string = "系统未定义此难度!";
return;
}
}
output_Array = new int[Arrayheight,Arraywidth];
output_height = Arrayheight;
output_width = Arraywidth;
if(leinum>=(int)Arrayheight*Arraywidth/2)
{
output_string = "雷数过多!";
return;
}
Random Rnd = new Random(); //随机产生雷。
int temp1=0,temp2=0,IntRnd=0;
for(int i=0;i<leinum;i++)
{
IntRnd = (int)(Rnd.NextDouble() * output_Array.Length);
//随机产生行和列。
temp1 = (int)(IntRnd/Arraywidth);
temp2 = IntRnd%Arraywidth;
//如果之前已经被付值为9,则次数减一
if((int)output_Array[temp1,temp2] == 9)
{
i--;
}
else
{
output_Array[temp1,temp2] = 9;
}
}
}
}
}
//process.dll 遍历数组
using System;
namespace Process1
{
/// <summary>
///对Creat产生出的数组作处理,使9的周围累加1。
/// </summary>
sealed public class process1
{
private int[,] process1_array;
/// <summary>
/// 输出经过do_process1处理后的Array。
/// </summary>
public int[,] Process1_Array
{
get
{
return process1_array;
}
}
/// <summary>
/// 调用此方法后才能得到正确的结果,即:Process1_Array。
/// </summary>
/// <param name="Input_Array">传入需要处理的数组</param>
/// <param name="Input_Hight">数组的高,即[i,j]的i</param>
/// <param name="Input_Width">数组的宽,即[i,j]的j</param>
public void do_process1(int[,] Input_Array, int Input_Hight, int Input_Width)
{
process1_array = new int[Input_Hight, Input_Width];
int i, j;
for (i = 0; i < Input_Hight; i++)
{
for (j = 0; j < Input_Width; j++)
{
process1_array[i,j]=Input_Array[i,j];
}
}
//遍历数组,每次遇到等于9的,则在周围不等于9的地方++。
for (i = 0; i < Input_Hight; i++)
{
for (j = 0; j < Input_Width; j++)
{
if (process1_array[i, j] == 9)
{
try
{
if(process1_array[i, j-1] != 9)
{
process1_array[i, j-1]++;
}
}
catch { }
try
{
if(process1_array[i, j+1] != 9)
{
process1_array[i, j+1]++;
}
}
catch { }
try
{
if(process1_array[i-1, j+1] != 9)
{
process1_array[i - 1, j+1]++;
}
}
catch { }
try
{
if(process1_array[i-1, j] != 9)
{
process1_array[i-1, j]++;
}
}
catch { }
try
{
if(process1_array[i-1, j-1] != 9)
{
process1_array[i-1, j-1]++;
}
}
catch { }
try
{
if(process1_array[i+1, j-1] != 9)
{
process1_array[i+1, j-1]++;
}
}
catch { }
try
{
if(process1_array[i+1, j] != 9)
{
process1_array[i+1, j]++;
}
}
catch { }
try
{
if(process1_array[i+1, j+1] != 9)
{
process1_array[i + 1, j+1]++;
}
}
catch { }
}
}
}
}
}
}
//process2.dll GOTO跳转法图的遍历
using System;
using System.Collections;
namespace Process2
{
/// <summary>
/// 图的遍历。
/// </summary>
sealed public class process2
{
private int[,] process2_array;
/// <summary>
/// 输出经过do_process2()处理后的Array。
/// </summary>
public int[,] Process2_Array
{
get
{
return process2_array;
}
}
public process2(int[,] Input_Array, int Input_Hight, int Input_Width)
{
process2_array = new int[Input_Hight, Input_Width];
for (int i = 0; i < Input_Hight; i++)
{
for (int j = 0; j < Input_Width; j++)
{
process2_array[i, j] = Input_Array[i, j];
}
}
}
Stack stack = new Stack();
/// <summary>
/// 图的遍历方法。
/// </summary>
/// <param name="Input_Array">输入待处理的数组</param>
/// <param name="Input_Hight">数组的高,即[i,j]的i</param>
/// <param name="Input_Width">数组的高,即[i,j]的j</param>
/// <param name="Start_X">遍历的起点,即[i,j]的i的值</param>
/// <param name="Start_Y">遍历的起点,即[i,j]的j的值</param>
public void do_process2(int Start_X, int Start_Y)
{
//this.Path(Start_X,Start_Y);
//图的深度遍历.
int ds = 0; //方向。
int X = Start_X,Y = Start_Y;
Stack stack = new Stack();
retry:
try
{
if (process2_array[X, Y] == 0)
{
ds = 1;
stack.Push(Y);
stack.Push(X);
process2_array[X, Y] = 15;
}
else
{
if (process2_array[X, Y] > 0 && process2_array[X, Y] < 9)
{
process2_array[X, Y] = 15;
}
switch(ds)
{
case 1:
X++;Y++;break;
case 2:
X++;break;
case 3:
X++;Y--;break;
case 4:
Y++;break;
case 5:
Y--;break;
case 6:
X--;Y++;break;
case 7:
X--;break;
case 8:
X--;Y--;break;
}
ds++;
}
}
catch
{
switch(ds)
{
case 1:
X++;Y++;break;
case 2:
X++;break;
case 3:
X++;Y--;break;
case 4:
Y++;break;
case 5:
Y--;break;
case 6:
X--;Y++;break;
case 7:
X--;break;
case 8:
X--;Y--;break;
}
ds++;
}
switch(ds)
{
case 1:
X--;Y--;goto retry;
case 2:
X--;goto retry;
case 3:
X--;Y++;goto retry;
case 4:
Y--;goto retry;
case 5:
Y++;goto retry;
case 6:
X++;Y--;goto retry;
case 7:
X++;goto retry;
case 8:
X++;Y++;goto retry;
case 9:
ds = 1;
while(stack.Count != 0)
{
X = (int)stack.Pop()-1;
Y = (int)stack.Pop()-1;
goto retry;
}
break;
}
}
}
}
//main.exe 主程序
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace main
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
……设计器代码过多...已省略……
private Creat.creat creat = new Creat.creat();
private Process1.process1 process1 = new Process1.process1();
private Process2.process2 process2;
private int[,] temparray; //作为process1.Process1_Array[i, j]的备份数组。
/// <summary>
/// 用户重新开始。
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItem2_Click(object sender, System.EventArgs e)
{
Initializtion();
}
/// <summary>
/// 用户退出游戏。
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItem4_Click(object sender, System.EventArgs e)
{
this.Dispose();
}
/// <summary>
/// 用户自定义难度:初出茅庐
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItem6_Click(object sender, System.EventArgs e)
{
this.userdefine.define.user_define = false;
userdefine.define.user_define_lev = 1;
Initializtion();
}
/// <summary>
/// 用户自定义难度:行侠仗义
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItem7_Click(object sender, System.EventArgs e)
{
this.userdefine.define.user_define = false;
userdefine.define.user_define_lev = 2;
Initializtion();
}
/// <summary>
/// 用户自定义难度:一统江湖
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItem8_Click(object sender, System.EventArgs e)
{
this.userdefine.define.user_define = false;
userdefine.define.user_define_lev = 3;
Initializtion();
}
USER_DEFINE userdefine = new USER_DEFINE(); //自定义窗体.
/// <summary>
/// 用户自定义难度:指定大小
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItem10_Click(object sender, System.EventArgs e)
{
userdefine.ShowDialog();
}
/// <summary>
/// 用户选择风格1
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItem12_Click(object sender, System.EventArgs e)
{
The_style.Picture_Box_Back_color = Color.Brown;
The_style.Show_Result_Before_Brush = Brushes.YellowGreen;
The_style.Shou_RightClick = Brushes.White;
The_style.The_Mouse_Holdon_Brush = Brushes.Yellow;
The_style.The_Mouse_Clicked_Cover_and_Result_Image_size = this.the_back_pictureBox.Height/creat.Output_height-1;
The_style.The_Mouse_Holdon_Image_size_add = 1;
the_back_pictureBox.Refresh();
}
/// <summary>
/// 用户选择风格2
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItem13_Click(object sender, System.EventArgs e)
{
The_style.Picture_Box_Back_color = Color.Black;
The_style.Show_Result_Before_Brush = Brushes.MediumSlateBlue;
The_style.Shou_RightClick = Brushes.Violet;
The_style.The_Mouse_Holdon_Brush = Brushes.DeepPink;
The_style.The_Mouse_Clicked_Cover_and_Result_Image_size = this.the_back_pictureBox.Height / creat.Output_height - 1;
The_style.The_Mouse_Holdon_Image_size_add = 0;
the_back_pictureBox.Refresh();
}
/// <summary>
/// 用户选择风格3
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItem14_Click(object sender, System.EventArgs e)
{
The_style.Picture_Box_Back_color = Color.Green;
The_style.Show_Result_Before_Brush = Brushes.DarkOrange;
The_style.Shou_RightClick = Brushes.Navy;
The_style.The_Mouse_Holdon_Brush = Brushes.Beige;
The_style.The_Mouse_Clicked_Cover_and_Result_Image_size = this.the_back_pictureBox.Height / creat.Output_height - 1;
The_style.The_Mouse_Holdon_Image_size_add = 1;
the_back_pictureBox.Refresh();
}
/// <summary>
/// 用户选择风格4
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItem15_Click(object sender, System.EventArgs e)
{
The_style.Picture_Box_Back_color = Color.SeaGreen;
The_style.Show_Result_Before_Brush = Brushes.Tan;
The_style.Shou_RightClick = Brushes.DarkSeaGreen;
The_style.The_Mouse_Holdon_Brush = Brushes.Gold;
The_style.The_Mouse_Clicked_Cover_and_Result_Image_size = this.the_back_pictureBox.Height / creat.Output_height - 1;
The_style.The_Mouse_Holdon_Image_size_add = 2;
the_back_pictureBox.Refresh();
}
/// <summary>
/// 关于信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItem17_Click(object sender, System.EventArgs e)
{
MessageBox.Show("");
}
/// <summary>
/// 帮助信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItem18_Click(object sender, System.EventArgs e)
{
MessageBox.Show("和Windows自带的扫雷功能一样地");
}
private int time = 0; //计时器时间,单位:秒。
/// <summary>
/// 计时器控件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void timer1_Tick(object sender, System.EventArgs e)
{
time++;
if (time < 9999)
{
label1.Text = time.ToString().PadLeft(4, '0');
}
}
/// <summary>
/// Form1_Load,初始化内部控件的位置。
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form1_Load(object sender, EventArgs e)
{
//调整位置.
this.groupBox1.Location = new Point(this.Width / 2 - this.groupBox1.Width, 8);
this.groupBox2.Location = new Point(this.Width / 2, 8);
this.the_back_pictureBox.Location = new Point((this.Width - this.the_back_pictureBox.Width) / 2, 64);
//子窗体关闭时,主窗体需要执行Initializtion();
this.userdefine.Closed += new EventHandler(userdefine_Closed);
}
/// <summary>
/// 当自定义窗体关闭时,如果用户确定了自定义数据,则执行Initializtion()。
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void userdefine_Closed(object sender, System.EventArgs e)
{
if (this.userdefine.define.user_define)
{
Initializtion();
}
}
/// <summary>
/// 当窗体大小改变时,重新调整内部控件的位置和大小。
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form1_SizeChanged(object sender, EventArgs e)
{
this.groupBox1.Location = new Point(this.Width / 2 - this.groupBox1.Width, 8);
this.groupBox2.Location = new Point(this.Width / 2, 8);
double h, w;
h = (this.Height - 112) / creat.Output_height;
w = (this.Width-5.8) / creat.Output_width;
if (w <= h)
{
this.the_back_pictureBox.Size = new Size(this.Width, Convert.ToInt32(w * creat.Output_height));
The_style.The_Mouse_Clicked_Cover_and_Result_Image_size = Convert.ToInt32(w - 1);
}
else
{
The_style.The_Mouse_Clicked_Cover_and_Result_Image_size = Convert.ToInt32(h-1);
this.the_back_pictureBox.Size = new Size(Convert.ToInt32(h * creat.Output_width), this.Height - 112);
}
this.the_back_pictureBox.Location = new Point((this.Width - this.the_back_pictureBox.Width) / 2, 64);
the_back_pictureBox.Refresh();
}
private void the_back_pictureBox_Resize(object sender, EventArgs e)
{
the_back_pictureBox.Refresh();
}
/// <summary>
/// 初始化函数。
/// </summary>
private void Initializtion()
{
//生成随机雷。
creat.Is_user_define = this.userdefine.define.user_define;
creat.User_define_Arrayheight = this.userdefine.define.user_define_Height;
creat.User_define_Arraywidth = this.userdefine.define.user_define_Width;
creat.User_define_leinum = this.userdefine.define.user_define_leinum;
creat.User_define_lev = this.userdefine.define.user_define_lev;
creat.creatarray();
//处理雷边界。
process1.do_process1(creat.Output_Array, creat.Output_height, creat.Output_width);
process2 = new Process2.process2(process1.Process1_Array ,creat.Output_height, creat.Output_width);
//复制一个备用数组,以便以后还原。
temparray = new int[creat.Output_height, creat.Output_width];
for (int i = 0; i < creat.Output_height; i++)
{
for (int j = 0; j < creat.Output_width; j++)
{
temparray[i, j] = process1.Process1_Array[i, j];
}
}
//生成两个个记录鼠标点击的纪录数组。
The_Block_Clicked.the_block_left_clicked = new int[creat.Output_height, creat.Output_width]; //0表示未左击鼠标。
The_Block_Clicked.the_block_right_clicked = new int[creat.Output_height, creat.Output_width]; //0表示未右击鼠标或者还原的初始状态,1表示?号,2表示雷号。
this.timer1.Interval = 1000;
time = 0; //计时器时间,单位:秒。
this.timer1.Stop();
label1.Text = "0000";
label2.Text = creat.User_define_leinum.ToString().PadLeft(4, '0');
Is_first_click = true; //是否为第一次点击?确保用户第一次不会点到雷。
Is_finally = false; //当前游戏是否结束。
Is_rightdown = false;Is_leftdown = false;IsBothDown =false; //左键是否按下?右键是否按下?左右键是否同时按下。
right_click_count_as1 = 0;//纪录蒙板the_block_right_clicked被置为1的次数,方便以后判断输赢结果用。
left_click_count = 0;//纪录蒙板the_block_right_clicked被置为1的次数,方便以后判断输赢结果用。
//调整pictureBox的大小。
double h, w;
h = (this.Height - 112) / creat.Output_height;
w = (this.Width - 5.8) / creat.Output_width;
if (w <= h)
{
this.the_back_pictureBox.Size = new Size(this.Width, Convert.ToInt32(w * creat.Output_height));
The_style.The_Mouse_Clicked_Cover_and_Result_Image_size = Convert.ToInt32(w - 1);
}
else
{
The_style.The_Mouse_Clicked_Cover_and_Result_Image_size = Convert.ToInt32(h - 1);
this.the_back_pictureBox.Size = new Size(Convert.ToInt32(h * creat.Output_width), this.Height - 112);
}
this.the_back_pictureBox.Location = new Point((this.Width - this.the_back_pictureBox.Width) / 2, 64);
the_back_pictureBox.Refresh();
}
/// <summary>
/// 风格类。
/// </summary>
private class the_style
{
public Color Picture_Box_Back_color = Color.Brown; //背景色
public Brush The_Mouse_Holdon_Brush = Brushes.Yellow; //鼠标移动到哪个区块时需要高亮显示的颜色。
public int The_Mouse_Holdon_Image_size_add = 1; //高亮区域比原来区域增加了多少。
public Brush Show_Result_Before_Brush = Brushes.YellowGreen; //就是原区块的颜色。
public Brush Shou_RightClick = Brushes.White; //"?"和“!”的颜色。
public int The_Mouse_Clicked_Cover_and_Result_Image_size = 21; //就是原区块的大小。
public Image The_Mouse_Holdon_Image; //高亮显示块的Image。
public Image The_Mouse_Clicked_Cover_Image; //就是原区块的Image。
public the_style()
{
The_Mouse_Holdon_Image = new Bitmap((int)(The_Mouse_Clicked_Cover_and_Result_Image_size * 1.1 + The_Mouse_Holdon_Image_size_add), (int)(The_Mouse_Clicked_Cover_and_Result_Image_size * 1.1 + The_Mouse_Holdon_Image_size_add));
The_Mouse_Clicked_Cover_Image = new Bitmap(The_Mouse_Clicked_Cover_and_Result_Image_size, The_Mouse_Clicked_Cover_and_Result_Image_size);
}
}
private the_style The_style = new the_style();
//Creat.dll 生成雷
using System;
namespace Creat
{
/// <summary>
/// 产生一个随机填充9的二维数组。
/// </summary>
sealed public class creat
{
private bool is_user_define = false;
/// <summary>
/// 是否为用户自定义的大小?
/// </summary>
public bool Is_user_define
{
set
{
is_user_define = value;
}
}
private int Arraywidth = 0;
/// <summary>
/// 如果为用户自定义的大小,则表示雷区宽。
/// </summary>
public int User_define_Arraywidth
{
set
{
Arraywidth =value;
}
}
private int Arrayheight = 0;
/// <summary>
/// 如果为用户自定义的大小,则表示雷区高。
/// </summary>
public int User_define_Arrayheight
{
set
{
Arrayheight =value;
}
}
private int leinum = 0;
/// <summary>
/// 如果为用户自定义的大小,则表示雷数。
/// </summary>
public int User_define_leinum
{
set
{
leinum =value;
}
get
{
return leinum;
}
}
private int lev = 1;
/// <summary>
/// 系统自定义难度v。
/// </summary>
public int User_define_lev
{
set
{
lev =value;
}
}
private int[,] output_Array;
/// <summary>
/// 输出结果Array。
/// </summary>
public int[,] Output_Array
{
get
{
return output_Array;
}
}
private int output_height;
/// <summary>
/// 输出Array的高,即数组[i,j]的i值。
/// </summary>
public int Output_height
{
get
{
return output_height;
}
}
private int output_width;
/// <summary>
/// 输出Array的宽,即数组[i,j]的j值。
/// </summary>
public int Output_width
{
get
{
return output_width;
}
}
private string output_string;
/// <summary>
/// 输出出错信息。
/// </summary>
public string Output_string
{
get
{
return output_string;
}
}
/// <summary>
/// 输入一系列值,执行这个方法后得到Output_Array。
/// </summary>
public void creatarray()
{
if(!this.is_user_define)
{
if(lev == 1)
{
Arrayheight = 9;
Arraywidth = 9;
leinum = 5;
}
else if(lev == 2)
{
Arrayheight = 16;
Arraywidth = 16;
leinum = 28;
}
else if(lev == 3)
{
Arrayheight = 20;
Arraywidth = 30;
leinum = 80;
}
else
{
output_string = "系统未定义此难度!";
return;
}
}
output_Array = new int[Arrayheight,Arraywidth];
output_height = Arrayheight;
output_width = Arraywidth;
if(leinum>=(int)Arrayheight*Arraywidth/2)
{
output_string = "雷数过多!";
return;
}
Random Rnd = new Random(); //随机产生雷。
int temp1=0,temp2=0,IntRnd=0;
for(int i=0;i<leinum;i++)
{
IntRnd = (int)(Rnd.NextDouble() * output_Array.Length);
//随机产生行和列。
temp1 = (int)(IntRnd/Arraywidth);
temp2 = IntRnd%Arraywidth;
//如果之前已经被付值为9,则次数减一
if((int)output_Array[temp1,temp2] == 9)
{
i--;
}
else
{
output_Array[temp1,temp2] = 9;
}
}
}
}
}
//process.dll 遍历数组
using System;
namespace Process1
{
/// <summary>
///对Creat产生出的数组作处理,使9的周围累加1。
/// </summary>
sealed public class process1
{
private int[,] process1_array;
/// <summary>
/// 输出经过do_process1处理后的Array。
/// </summary>
public int[,] Process1_Array
{
get
{
return process1_array;
}
}
/// <summary>
/// 调用此方法后才能得到正确的结果,即:Process1_Array。
/// </summary>
/// <param name="Input_Array">传入需要处理的数组</param>
/// <param name="Input_Hight">数组的高,即[i,j]的i</param>
/// <param name="Input_Width">数组的宽,即[i,j]的j</param>
public void do_process1(int[,] Input_Array, int Input_Hight, int Input_Width)
{
process1_array = new int[Input_Hight, Input_Width];
int i, j;
for (i = 0; i < Input_Hight; i++)
{
for (j = 0; j < Input_Width; j++)
{
process1_array[i,j]=Input_Array[i,j];
}
}
//遍历数组,每次遇到等于9的,则在周围不等于9的地方++。
for (i = 0; i < Input_Hight; i++)
{
for (j = 0; j < Input_Width; j++)
{
if (process1_array[i, j] == 9)
{
try
{
if(process1_array[i, j-1] != 9)
{
process1_array[i, j-1]++;
}
}
catch { }
try
{
if(process1_array[i, j+1] != 9)
{
process1_array[i, j+1]++;
}
}
catch { }
try
{
if(process1_array[i-1, j+1] != 9)
{
process1_array[i - 1, j+1]++;
}
}
catch { }
try
{
if(process1_array[i-1, j] != 9)
{
process1_array[i-1, j]++;
}
}
catch { }
try
{
if(process1_array[i-1, j-1] != 9)
{
process1_array[i-1, j-1]++;
}
}
catch { }
try
{
if(process1_array[i+1, j-1] != 9)
{
process1_array[i+1, j-1]++;
}
}
catch { }
try
{
if(process1_array[i+1, j] != 9)
{
process1_array[i+1, j]++;
}
}
catch { }
try
{
if(process1_array[i+1, j+1] != 9)
{
process1_array[i + 1, j+1]++;
}
}
catch { }
}
}
}
}
}
}
//process2.dll GOTO跳转法图的遍历
using System;
using System.Collections;
namespace Process2
{
/// <summary>
/// 图的遍历。
/// </summary>
sealed public class process2
{
private int[,] process2_array;
/// <summary>
/// 输出经过do_process2()处理后的Array。
/// </summary>
public int[,] Process2_Array
{
get
{
return process2_array;
}
}
public process2(int[,] Input_Array, int Input_Hight, int Input_Width)
{
process2_array = new int[Input_Hight, Input_Width];
for (int i = 0; i < Input_Hight; i++)
{
for (int j = 0; j < Input_Width; j++)
{
process2_array[i, j] = Input_Array[i, j];
}
}
}
Stack stack = new Stack();
/// <summary>
/// 图的遍历方法。
/// </summary>
/// <param name="Input_Array">输入待处理的数组</param>
/// <param name="Input_Hight">数组的高,即[i,j]的i</param>
/// <param name="Input_Width">数组的高,即[i,j]的j</param>
/// <param name="Start_X">遍历的起点,即[i,j]的i的值</param>
/// <param name="Start_Y">遍历的起点,即[i,j]的j的值</param>
public void do_process2(int Start_X, int Start_Y)
{
//this.Path(Start_X,Start_Y);
//图的深度遍历.
int ds = 0; //方向。
int X = Start_X,Y = Start_Y;
Stack stack = new Stack();
retry:
try
{
if (process2_array[X, Y] == 0)
{
ds = 1;
stack.Push(Y);
stack.Push(X);
process2_array[X, Y] = 15;
}
else
{
if (process2_array[X, Y] > 0 && process2_array[X, Y] < 9)
{
process2_array[X, Y] = 15;
}
switch(ds)
{
case 1:
X++;Y++;break;
case 2:
X++;break;
case 3:
X++;Y--;break;
case 4:
Y++;break;
case 5:
Y--;break;
case 6:
X--;Y++;break;
case 7:
X--;break;
case 8:
X--;Y--;break;
}
ds++;
}
}
catch
{
switch(ds)
{
case 1:
X++;Y++;break;
case 2:
X++;break;
case 3:
X++;Y--;break;
case 4:
Y++;break;
case 5:
Y--;break;
case 6:
X--;Y++;break;
case 7:
X--;break;
case 8:
X--;Y--;break;
}
ds++;
}
switch(ds)
{
case 1:
X--;Y--;goto retry;
case 2:
X--;goto retry;
case 3:
X--;Y++;goto retry;
case 4:
Y--;goto retry;
case 5:
Y++;goto retry;
case 6:
X++;Y--;goto retry;
case 7:
X++;goto retry;
case 8:
X++;Y++;goto retry;
case 9:
ds = 1;
while(stack.Count != 0)
{
X = (int)stack.Pop()-1;
Y = (int)stack.Pop()-1;
goto retry;
}
break;
}
}
}
}
//main.exe 主程序
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace main
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
……设计器代码过多...已省略……
private Creat.creat creat = new Creat.creat();
private Process1.process1 process1 = new Process1.process1();
private Process2.process2 process2;
private int[,] temparray; //作为process1.Process1_Array[i, j]的备份数组。
/// <summary>
/// 用户重新开始。
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItem2_Click(object sender, System.EventArgs e)
{
Initializtion();
}
/// <summary>
/// 用户退出游戏。
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItem4_Click(object sender, System.EventArgs e)
{
this.Dispose();
}
/// <summary>
/// 用户自定义难度:初出茅庐
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItem6_Click(object sender, System.EventArgs e)
{
this.userdefine.define.user_define = false;
userdefine.define.user_define_lev = 1;
Initializtion();
}
/// <summary>
/// 用户自定义难度:行侠仗义
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItem7_Click(object sender, System.EventArgs e)
{
this.userdefine.define.user_define = false;
userdefine.define.user_define_lev = 2;
Initializtion();
}
/// <summary>
/// 用户自定义难度:一统江湖
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItem8_Click(object sender, System.EventArgs e)
{
this.userdefine.define.user_define = false;
userdefine.define.user_define_lev = 3;
Initializtion();
}
USER_DEFINE userdefine = new USER_DEFINE(); //自定义窗体.
/// <summary>
/// 用户自定义难度:指定大小
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItem10_Click(object sender, System.EventArgs e)
{
userdefine.ShowDialog();
}
/// <summary>
/// 用户选择风格1
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItem12_Click(object sender, System.EventArgs e)
{
The_style.Picture_Box_Back_color = Color.Brown;
The_style.Show_Result_Before_Brush = Brushes.YellowGreen;
The_style.Shou_RightClick = Brushes.White;
The_style.The_Mouse_Holdon_Brush = Brushes.Yellow;
The_style.The_Mouse_Clicked_Cover_and_Result_Image_size = this.the_back_pictureBox.Height/creat.Output_height-1;
The_style.The_Mouse_Holdon_Image_size_add = 1;
the_back_pictureBox.Refresh();
}
/// <summary>
/// 用户选择风格2
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItem13_Click(object sender, System.EventArgs e)
{
The_style.Picture_Box_Back_color = Color.Black;
The_style.Show_Result_Before_Brush = Brushes.MediumSlateBlue;
The_style.Shou_RightClick = Brushes.Violet;
The_style.The_Mouse_Holdon_Brush = Brushes.DeepPink;
The_style.The_Mouse_Clicked_Cover_and_Result_Image_size = this.the_back_pictureBox.Height / creat.Output_height - 1;
The_style.The_Mouse_Holdon_Image_size_add = 0;
the_back_pictureBox.Refresh();
}
/// <summary>
/// 用户选择风格3
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItem14_Click(object sender, System.EventArgs e)
{
The_style.Picture_Box_Back_color = Color.Green;
The_style.Show_Result_Before_Brush = Brushes.DarkOrange;
The_style.Shou_RightClick = Brushes.Navy;
The_style.The_Mouse_Holdon_Brush = Brushes.Beige;
The_style.The_Mouse_Clicked_Cover_and_Result_Image_size = this.the_back_pictureBox.Height / creat.Output_height - 1;
The_style.The_Mouse_Holdon_Image_size_add = 1;
the_back_pictureBox.Refresh();
}
/// <summary>
/// 用户选择风格4
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItem15_Click(object sender, System.EventArgs e)
{
The_style.Picture_Box_Back_color = Color.SeaGreen;
The_style.Show_Result_Before_Brush = Brushes.Tan;
The_style.Shou_RightClick = Brushes.DarkSeaGreen;
The_style.The_Mouse_Holdon_Brush = Brushes.Gold;
The_style.The_Mouse_Clicked_Cover_and_Result_Image_size = this.the_back_pictureBox.Height / creat.Output_height - 1;
The_style.The_Mouse_Holdon_Image_size_add = 2;
the_back_pictureBox.Refresh();
}
/// <summary>
/// 关于信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItem17_Click(object sender, System.EventArgs e)
{
MessageBox.Show("");
}
/// <summary>
/// 帮助信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItem18_Click(object sender, System.EventArgs e)
{
MessageBox.Show("和Windows自带的扫雷功能一样地");
}
private int time = 0; //计时器时间,单位:秒。
/// <summary>
/// 计时器控件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void timer1_Tick(object sender, System.EventArgs e)
{
time++;
if (time < 9999)
{
label1.Text = time.ToString().PadLeft(4, '0');
}
}
/// <summary>
/// Form1_Load,初始化内部控件的位置。
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form1_Load(object sender, EventArgs e)
{
//调整位置.
this.groupBox1.Location = new Point(this.Width / 2 - this.groupBox1.Width, 8);
this.groupBox2.Location = new Point(this.Width / 2, 8);
this.the_back_pictureBox.Location = new Point((this.Width - this.the_back_pictureBox.Width) / 2, 64);
//子窗体关闭时,主窗体需要执行Initializtion();
this.userdefine.Closed += new EventHandler(userdefine_Closed);
}
/// <summary>
/// 当自定义窗体关闭时,如果用户确定了自定义数据,则执行Initializtion()。
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void userdefine_Closed(object sender, System.EventArgs e)
{
if (this.userdefine.define.user_define)
{
Initializtion();
}
}
/// <summary>
/// 当窗体大小改变时,重新调整内部控件的位置和大小。
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form1_SizeChanged(object sender, EventArgs e)
{
this.groupBox1.Location = new Point(this.Width / 2 - this.groupBox1.Width, 8);
this.groupBox2.Location = new Point(this.Width / 2, 8);
double h, w;
h = (this.Height - 112) / creat.Output_height;
w = (this.Width-5.8) / creat.Output_width;
if (w <= h)
{
this.the_back_pictureBox.Size = new Size(this.Width, Convert.ToInt32(w * creat.Output_height));
The_style.The_Mouse_Clicked_Cover_and_Result_Image_size = Convert.ToInt32(w - 1);
}
else
{
The_style.The_Mouse_Clicked_Cover_and_Result_Image_size = Convert.ToInt32(h-1);
this.the_back_pictureBox.Size = new Size(Convert.ToInt32(h * creat.Output_width), this.Height - 112);
}
this.the_back_pictureBox.Location = new Point((this.Width - this.the_back_pictureBox.Width) / 2, 64);
the_back_pictureBox.Refresh();
}
private void the_back_pictureBox_Resize(object sender, EventArgs e)
{
the_back_pictureBox.Refresh();
}
/// <summary>
/// 初始化函数。
/// </summary>
private void Initializtion()
{
//生成随机雷。
creat.Is_user_define = this.userdefine.define.user_define;
creat.User_define_Arrayheight = this.userdefine.define.user_define_Height;
creat.User_define_Arraywidth = this.userdefine.define.user_define_Width;
creat.User_define_leinum = this.userdefine.define.user_define_leinum;
creat.User_define_lev = this.userdefine.define.user_define_lev;
creat.creatarray();
//处理雷边界。
process1.do_process1(creat.Output_Array, creat.Output_height, creat.Output_width);
process2 = new Process2.process2(process1.Process1_Array ,creat.Output_height, creat.Output_width);
//复制一个备用数组,以便以后还原。
temparray = new int[creat.Output_height, creat.Output_width];
for (int i = 0; i < creat.Output_height; i++)
{
for (int j = 0; j < creat.Output_width; j++)
{
temparray[i, j] = process1.Process1_Array[i, j];
}
}
//生成两个个记录鼠标点击的纪录数组。
The_Block_Clicked.the_block_left_clicked = new int[creat.Output_height, creat.Output_width]; //0表示未左击鼠标。
The_Block_Clicked.the_block_right_clicked = new int[creat.Output_height, creat.Output_width]; //0表示未右击鼠标或者还原的初始状态,1表示?号,2表示雷号。
this.timer1.Interval = 1000;
time = 0; //计时器时间,单位:秒。
this.timer1.Stop();
label1.Text = "0000";
label2.Text = creat.User_define_leinum.ToString().PadLeft(4, '0');
Is_first_click = true; //是否为第一次点击?确保用户第一次不会点到雷。
Is_finally = false; //当前游戏是否结束。
Is_rightdown = false;Is_leftdown = false;IsBothDown =false; //左键是否按下?右键是否按下?左右键是否同时按下。
right_click_count_as1 = 0;//纪录蒙板the_block_right_clicked被置为1的次数,方便以后判断输赢结果用。
left_click_count = 0;//纪录蒙板the_block_right_clicked被置为1的次数,方便以后判断输赢结果用。
//调整pictureBox的大小。
double h, w;
h = (this.Height - 112) / creat.Output_height;
w = (this.Width - 5.8) / creat.Output_width;
if (w <= h)
{
this.the_back_pictureBox.Size = new Size(this.Width, Convert.ToInt32(w * creat.Output_height));
The_style.The_Mouse_Clicked_Cover_and_Result_Image_size = Convert.ToInt32(w - 1);
}
else
{
The_style.The_Mouse_Clicked_Cover_and_Result_Image_size = Convert.ToInt32(h - 1);
this.the_back_pictureBox.Size = new Size(Convert.ToInt32(h * creat.Output_width), this.Height - 112);
}
this.the_back_pictureBox.Location = new Point((this.Width - this.the_back_pictureBox.Width) / 2, 64);
the_back_pictureBox.Refresh();
}
/// <summary>
/// 风格类。
/// </summary>
private class the_style
{
public Color Picture_Box_Back_color = Color.Brown; //背景色
public Brush The_Mouse_Holdon_Brush = Brushes.Yellow; //鼠标移动到哪个区块时需要高亮显示的颜色。
public int The_Mouse_Holdon_Image_size_add = 1; //高亮区域比原来区域增加了多少。
public Brush Show_Result_Before_Brush = Brushes.YellowGreen; //就是原区块的颜色。
public Brush Shou_RightClick = Brushes.White; //"?"和“!”的颜色。
public int The_Mouse_Clicked_Cover_and_Result_Image_size = 21; //就是原区块的大小。
public Image The_Mouse_Holdon_Image; //高亮显示块的Image。
public Image The_Mouse_Clicked_Cover_Image; //就是原区块的Image。
public the_style()
{
The_Mouse_Holdon_Image = new Bitmap((int)(The_Mouse_Clicked_Cover_and_Result_Image_size * 1.1 + The_Mouse_Holdon_Image_size_add), (int)(The_Mouse_Clicked_Cover_and_Result_Image_size * 1.1 + The_Mouse_Holdon_Image_size_add));
The_Mouse_Clicked_Cover_Image = new Bitmap(The_Mouse_Clicked_Cover_and_Result_Image_size, The_Mouse_Clicked_Cover_and_Result_Image_size);
}
}
private the_style The_style = new the_style();
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询