程序视频展示链接
http://v.youku.com/v_show/id_XNDA2ODQwODYwNA==.html?spm=a2h3j.8428770.3416059.1
程序描述及代码展示
1、扫雷游戏设计的内容主要包含在两个大类上,即程序代码中的Game类和Square类。Game类表示一局扫雷游戏,其中包含游戏数据,游戏等级,雷区数,布雷方法等等。Square类表示游戏中的一个小方格,小方格中可能埋有地雷。Game类来实现一个游戏实例,Square类则代表一个游戏实例中的元素。用二维数组来保存游戏界面的信息,定义一个二维数组public static Square[,] gameData,游戏界面的宽度和高度即二维数组的第一维和第二维的长度。
2、扫雷游戏设计要求共有四个方面:
① 能够实现游戏中雷区和非雷区的分布,且能够在第一次点击时不踩中雷。
② 能够实现计时功能,即一局游戏结束时,能给出用户进行这局游戏所花费的时间。
③ 能实现标记计数功能,即每次鼠标右击方格时,在方格中画一个小旗标记时,主界面中相应的雷数也要减1,而再次点击质疑时,主界面中雷数又要相应的加1。
④ 当游戏正在进行时,如果用户做任何终止本次游戏的行为,则程序应该能够弹出提示框,询问用户是否继续进行正在进行的游戏,根据用户的选择,执行相应的操作。
2、扫雷程序设计流程:
#主窗口程序
using System;
using System.Windows.Forms;
using System.Media;
namespace SweepingMine
{
public partial class FormMain : Form
{
public Game game1;
public static int SquareColor;
public static FormMain fm1 = null;
public static DateTime beginTime;
public GameLevel formmerLevel = GameLevel.Beginner;
public GameLevel nowLevel = GameLevel.Beginner;
SetSize size = new SetSize();
public FormMain()
{
InitializeComponent();
fm1 = this;
}
/// <summary>
/// 游戏开局
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void 开局NF2ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (userControl12.gameLevel == GameLevel.Customize)
{
timer1.Enabled = false;
this.textBox1.Text = "0";
textBox2.Text = Properties.Settings.Default.MinesCount.ToString();
userControl12.NewGameC(userControl12.logicalSize, userControl12.MineCount);
}
else
{
timer1.Enabled = false;
this.textBox1.Text = "0";
userControl12.NewGameL(userControl12.gameLevel);
switch (userControl12.gameLevel)
{
case GameLevel.Beginner:
textBox2.Text = "10";
break;
case GameLevel.Intermediate:
textBox2.Text = "40";
break;
case GameLevel.Expert:
textBox2.Text = "99";
break;
}
}
}
/// <summary>
/// 游戏等级初级
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void 初级BToolStripMenuItem_Click(object sender, EventArgs e)
{
nowLevel = GameLevel.Beginner;
if (timer1.Enabled != false)
{
FormTips ft = new FormTips();
ft.Show();
}
else
{
userControl12.gameLevel = formmerLevel = GameLevel.Beginner;
size.GetGameLevel(userControl12.gameLevel);
}
}
/// <summary>
/// 游戏等级中级
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void 中级IToolStripMenuItem_Click(object sender, EventArgs e)
{
nowLevel = GameLevel.Intermediate;
if (timer1.Enabled != false)
{
FormTips ft = new FormTips();
ft.Show();
}
else
{
userControl12.gameLevel = formmerLevel = GameLevel.Intermediate;
size.GetGameLevel(userControl12.gameLevel);
}
}
/// <summary>
/// 游戏等级高级
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void 高级EToolStripMenuItem_Click(object sender, EventArgs e)
{
nowLevel = GameLevel.Expert;
if (timer1.Enabled != false)
{
FormTips ft = new FormTips();
ft.Show();
}
else
{
userControl12.gameLevel = formmerLevel = GameLevel.Expert;
size.GetGameLevel(userControl12.gameLevel);
}
}
/// <summary>
/// 自定义游戏设置
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void 自定义CToolStripMenuItem_Click(object sender, EventArgs e)
{
nowLevel = GameLevel.Customize;
if (timer1.Enabled != false)
{
FormCustomize f = new FormCustomize();
if (f.ShowDialog() == DialogResult.OK)
{
FormTips ft = new FormTips();
ft.Show();
}
}
else
{
userControl12.gameLevel = formmerLevel = GameLevel.Customize;