using System;
using System
using System
namespace WindowsFormsApplication
{
public partial class Frm
{
#region 變量
public int qishu;
public static int ls=
public int lgs =
public int bl=
public int time ;
public int[
public int ceshi =
public int[
public int sum =
public int timerEnable =
#endregion
public Frm
{
InitializeComponent()
}
///
/// 標識雷的個數 和可插的旗數
///
public void Qishu()
{
if (qishu <= lgs)
{
gamesource
}
else
{
gamesource
}
}
///
/// 畫方格
///
/// <實例對象>
/// <要畫圖的位置>
/// <要畫圖的位置>
/// <畫圖使用的顏色>
public void Dline(Graphics dline
{
dline
dline
dline
dline
}
///
/// 看是否可以向周圍移動
///
/// <移動的基本X坐標>
/// <移動的基本Y坐標>
public void Panjie(int x
{
Pl(x
if (y
{
Pl(x
if (x
{
Pl(x
}
if (x +
{
Pl(x +
}
}
if (y +
{
Pl(x
if (x
{
Pl(x
}
if (x +
{
Pl(x +
}
}
if (x
{
Pl(x
}
if (x +
{
Pl(x +
}
}
///
/// 判斷是否要清清除
///
/// <要判斷的基本X坐標>
/// <要判斷的基本Y坐標>
public void Pl(int x
{
if (bulei[x
{
click[x
Panjie(x
}
if (bulei[x
{
click[x
}
}
///
/// 初始化數組
///
public void Blpl()
{
sum = ls * hs;
qishu =
int mx
//初始化數組
int mx
int sum
for (mx =
{
for (my =
{
bulei[mx
click[mx
}
}
while(sum
//決定雷的個數和雷德位置
{
sum
Random r = new Random((int)DateTime
mx = r
my = r
bulei[mx
for (mx
{
for (my
{
sum
}
}
}
//判斷周圍雷的個數
for (mx =
{
for (my =
{
if (bulei[mx
{
if (mx
{
if (bulei[mx
{
bulei[mx
}
if (my
{
bulei[mx
}
if ( my +
{
bulei[mx
}
}
if (mx +
{
if (bulei[mx +
{
bulei[mx
}
if (my
{
bulei[mx
}
if (my +
{
bulei[mx
}
}
if(my
{
bulei[mx
}
if (my +
{
bulei[mx
}
}
}
}
}
///
/// 右擊的重繪
///
/// >
public void Rdraw(Graphics dline)
{
string text;
int mx
int mx
for (mx =
{
for (my =
{
mx
my
if ( click[mx
{
//第一次右擊畫旗
dline
dline
dline
dline
dline
text =
dline
}
if ( click[mx
{
//第二次右擊畫問號
dline
dline
dline
dline
dline
text =
dline
}
if (click[mx
{
//第三次右擊 恢復原樣
click[mx
dline
dline
dline
dline
dline
}
}
}
}
///
/// 初始化屏幕 (包還所有的)
///
public void Startscr()
{
Graphics dline = labdraw
time =
Blpl()
timer
Color c = Color
labdraw
Drawscreen(dline)
timerEnable =
labtime
}
///
/// 畫界面
///
/// >
public void Drawscreen(Graphics dline)
{
sum =
int mx
int mx
string text;
for (mx =
{
for (my =
{
//畫圖地位置 mx
mx
my
if (click[mx
{
//下面用於畫立體形矩形
sum++;
Pen mypen = new Pen(Color
Dline(dline
dline
}
if ((click[mx
{
click[mx
//提示周圍的雷數
if (bulei[mx
{
text = bulei[mx
dline
}
//顯示雷
if ((bulei[mx
{
text =
dline
if (bulei[mx
{
//被單擊的雷上畫上叉號
dline
dline
}
}
}
}
//用於畫旗 和問號
Rdraw(dline)
}
}
///
/// 當為雷時的算法
///
/// >
/// >
public void Panlei(int x
{
if (bulei[x
{
if (bulei[x
{
timer
timerEnable =
bulei[x
int i
for (i =
{
for (j =
{
if (bulei[i
{
click[i
}
}
}
}
if (bulei[x
{
click[x
}
}
else
{
Panjie(x
}
}
///
/// 回到游戲開始的界面
///
///
///
private void btnreplay_Click(object sender
{
//初始化一切 包括布雷
Startscr()
}
///
/// 計算游戲所用的時間
///
///
///
private void timer
{
time++;
if (time <=
{
if (time <
{
labtime
}
else
{
labtime
}
}
else
{
if (time <
{
labtime
}
else
{
timer
MessageBox
time =
timerEnable =
}
}
}
///
/// 在啟動的游戲時初始化界面
///
///
///
private void labdraw_Paint(object sender
{
Graphics dline = e
if (bl ==
{
Blpl()
Drawscreen(dline)
}
else
{
Drawscreen(dline)
}
}
///
/// //單擊時觸發的事件
///
///
///
private void labdraw_MouseClick(object sender
{
bl =
int i=
if (timerEnable ==
{
timer
Graphics dline = labdraw
int mx =
int mx
int mx
//判斷鼠標所點位置
mx
my
for (i =
{
for (j =
{
mx =
my =
//找到單擊位置代表的數組
if (mx < mx
{
mx
my
break;
}
}
if (j <
{
break;
}
}
//判斷是左擊還是右擊
if (e
{
//第
if (click[mx
{
click[mx
}
else
{
//第
if (click[mx
{
if (qishu
{
click[mx
qishu++;
}
}
if (click[mx
{
click[mx
}
}
//右擊的繪圖事件
Rdraw(dline)
Qishu()
}
else
{
//左擊
if (click[mx
{
click[mx
Color c = Color
//清屏 用背景顏色
labdraw
Panlei (mx
Drawscreen(dline)
}
if (bulei[mx
{
MessageBox
timer
timerEnable =
}
}
if (sum == lgs)
{
MessageBox
timer
timerEnable =
}
}
}
private void Frm
{
Qishu()
// this
// this
}
}
}
From:http://tw.wingwit.com/Article/program/net/201311/11988.html