📄 controls.cs
字号:
((Pane)_arrayList[paneList])._button.FlatStyle = FlatStyle.Popup;
((Pane)_arrayList[paneList])._button.Enabled = false;
AddImage(paneList);
if (((Pane)_arrayList[paneList]).PaneNumber == 0)
{
if (((Pane)_arrayList[paneList + 1]).IsMine == false && ((Pane)_arrayList[paneList + 1]).State != "open")
{
DisplayAround(paneList + 1);
}
if (((Pane)_arrayList[paneList - 1]).IsMine == false && ((Pane)_arrayList[paneList - 1]).State != "open")
{
DisplayAround(paneList - 1);
}
if (((Pane)_arrayList[paneList + Convert.ToInt32(Math.Sqrt(_buttonNumber))]).IsMine == false && ((Pane)_arrayList[paneList + Convert.ToInt32(Math.Sqrt(_buttonNumber))]).State != "open")
{
DisplayAround(paneList + Convert.ToInt32(Math.Sqrt(_buttonNumber)));
}
if (((Pane)_arrayList[paneList - Convert.ToInt32(Math.Sqrt(_buttonNumber))]).IsMine == false && ((Pane)_arrayList[paneList - Convert.ToInt32(Math.Sqrt(_buttonNumber))]).State != "open")
{
DisplayAround(paneList - Convert.ToInt32(Math.Sqrt(_buttonNumber)));
}
if (((Pane)_arrayList[paneList + Convert.ToInt32(Math.Sqrt(_buttonNumber)) + 1]).IsMine == false && ((Pane)_arrayList[paneList + Convert.ToInt32(Math.Sqrt(_buttonNumber)) + 1]).State != "open")
{
DisplayAround(paneList + Convert.ToInt32(Math.Sqrt(_buttonNumber)) + 1);
}
if (((Pane)_arrayList[paneList + Convert.ToInt32(Math.Sqrt(_buttonNumber)) - 1]).IsMine == false && ((Pane)_arrayList[paneList + Convert.ToInt32(Math.Sqrt(_buttonNumber)) - 1]).State != "open")
{
DisplayAround(paneList + Convert.ToInt32(Math.Sqrt(_buttonNumber)) - 1);
}
if (((Pane)_arrayList[paneList - Convert.ToInt32(Math.Sqrt(_buttonNumber)) + 1]).IsMine == false && ((Pane)_arrayList[paneList - Convert.ToInt32(Math.Sqrt(_buttonNumber)) + 1]).State != "open")
{
DisplayAround(paneList - Convert.ToInt32(Math.Sqrt(_buttonNumber)) + 1);
}
if (((Pane)_arrayList[paneList - Convert.ToInt32(Math.Sqrt(_buttonNumber)) - 1]).IsMine == false && ((Pane)_arrayList[paneList - Convert.ToInt32(Math.Sqrt(_buttonNumber)) - 1]).State != "open")
{
DisplayAround(paneList - Convert.ToInt32(Math.Sqrt(_buttonNumber)) - 1);
}
}
return;
}
#endregion
}
/// <summary>
/// // 当点中一个雷时,显示全部方格的信息
/// </summary>
public void DisplayAll()
{
for (int i = 0; i < Length; i++)
{
((Pane)_arrayList[i]).State = "open";
if (((Pane)_arrayList[i]).IsMine == true)
{
//((Pane)_arrayList[i])._button.FlatStyle = FlatStyle.Popup;
((Pane)_arrayList[i])._button.Image = global::Mine.Properties.Resources.MarkedWrong;
}
switch (((Mine.Model.Pane)_arrayList[i]).PaneNumber)
{
case 1: ((Mine.Model.Pane)_arrayList[i])._button.Image = global::Mine.Properties.Resources.button1; ((Mine.Model.Pane)_arrayList[i])._button.Enabled = false; break;
case 2: ((Mine.Model.Pane)_arrayList[i])._button.Image = global::Mine.Properties.Resources.button2; ((Mine.Model.Pane)_arrayList[i])._button.Enabled = false; break;
case 3: ((Mine.Model.Pane)_arrayList[i])._button.Image = global::Mine.Properties.Resources.button3; ((Mine.Model.Pane)_arrayList[i])._button.Enabled = false; break;
case 4: ((Mine.Model.Pane)_arrayList[i])._button.Image = global::Mine.Properties.Resources.button4; ((Mine.Model.Pane)_arrayList[i])._button.Enabled = false; break;
case 5: ((Mine.Model.Pane)_arrayList[i])._button.Image = global::Mine.Properties.Resources.button5; ((Mine.Model.Pane)_arrayList[i])._button.Enabled = false; break;
case 6: ((Mine.Model.Pane)_arrayList[i])._button.Image = global::Mine.Properties.Resources.button6; ((Mine.Model.Pane)_arrayList[i])._button.Enabled = false; break;
case 7: ((Mine.Model.Pane)_arrayList[i])._button.Image = global::Mine.Properties.Resources.button7; ((Mine.Model.Pane)_arrayList[i])._button.Enabled = false; break;
case 8: ((Mine.Model.Pane)_arrayList[i])._button.Image = global::Mine.Properties.Resources.button8; ((Mine.Model.Pane)_arrayList[i])._button.Enabled = false; break;
case 0: ((Mine.Model.Pane)_arrayList[i])._button.FlatStyle = FlatStyle.Popup; ((Mine.Model.Pane)_arrayList[i])._button.Enabled = false; ((Mine.Model.Pane)_arrayList[i])._button.Enabled = false; break;
}
}
}
/// <summary>
/// 设定方格周围的雷的数量
/// </summary>
public void SetNumber()
{
for (int j=0;j<_buttonNumber;j++)
{
bool chioce = false;
#region 过滤本身是雷的方格
//过滤本身是雷的方格
if (((Pane)_arrayList[j]).IsMine==true)
{
continue;
}
#endregion
//若本身不是雷,则进行下一级运行
#region 判断四个特殊按钮
//判断第一个按钮
if (((Pane)_arrayList[j]).PaneList == 0)
{
//开始计算方格周围的雷的数量
foreach (int i in mineList)
{
if (((Pane)_arrayList[i]).PaneList == 1 || ((Pane)_arrayList[i]).PaneList == Math.Sqrt(_buttonNumber) || ((Pane)_arrayList[i]).PaneList == (Math.Sqrt(_buttonNumber) + 1))
{
((Pane)_arrayList[j]).PaneNumber++;
}
}
chioce = true;
continue;
}
//判断第一列的最后一个按钮
if (((Pane)_arrayList[j]).PaneList ==( Math.Sqrt(_buttonNumber) - 1))
{
//开始计算方格周围的雷的数量
foreach (int i in mineList)
{
if (((Pane)_arrayList[i]).PaneList == (Math.Sqrt(_buttonNumber) - 2) || ((Pane)_arrayList[i]).PaneList ==( 2 * Math.Sqrt(_buttonNumber) -1 )|| ((Pane)_arrayList[i]).PaneList == (2 * Math.Sqrt(_buttonNumber) - 2))
{
((Pane)_arrayList[j]).PaneNumber++;
}
}
chioce = true;
continue;
}
//判断第一行的最后一个按钮
if (((Pane)_arrayList[j]).PaneList == Math.Sqrt(_buttonNumber) * (Math.Sqrt(_buttonNumber) - 1) )
{
//开始计算方格周围的雷的数量
foreach (int i in mineList)
{
if (((Pane)_arrayList[i]).PaneList == Math.Sqrt(_buttonNumber) * (Math.Sqrt(_buttonNumber) - 2) || ((Pane)_arrayList[i]).PaneList == (Math.Sqrt(_buttonNumber) * (Math.Sqrt(_buttonNumber) - 2) + 1) || ((Pane)_arrayList[i]).PaneList == (Math.Sqrt(_buttonNumber) * (Math.Sqrt(_buttonNumber) - 1) + 1))
{
((Pane)_arrayList[j]).PaneNumber++;
}
}
chioce = true;
continue;
}
//判断最后一个按扭
if (((Pane)_arrayList[j]).PaneList == _buttonNumber - 1)
{
//开始计算方格周围的雷的数量
foreach (int i in mineList)
{
if (((Pane)_arrayList[i]).PaneList == (_buttonNumber - 2) || ((Pane)_arrayList[i]).PaneList == (Math.Sqrt(_buttonNumber) * (Math.Sqrt(_buttonNumber) - 1) - 1) || ((Pane)_arrayList[i]).PaneList == (Math.Sqrt(_buttonNumber) * (Math.Sqrt(_buttonNumber) - 1) - 2))
{
((Pane)_arrayList[j]).PaneNumber++;
}
}
chioce = true;
continue;
}
#endregion
#region 判断四条特殊的边
//判断左边的一列
if (((Pane)_arrayList[j]).PaneList / Convert.ToInt32( Math.Sqrt(_buttonNumber) ) == 0 && ((Pane)_arrayList[j]).PaneList != 0 && ((Pane)_arrayList[j]).PaneList !=( Math.Sqrt(_buttonNumber) - 1))
{
//开始计算方格周围的雷的数量
foreach (int i in mineList)
{
if (((Pane)_arrayList[i]).PaneList == ((Pane)_arrayList[j]).PaneList + 1 || ((Pane)_arrayList[i]).PaneList == ((Pane)_arrayList[j]).PaneList - 1 || ((Pane)_arrayList[i]).PaneList == ((Pane)_arrayList[j]).PaneList + Math.Sqrt(_buttonNumber) || ((Pane)_arrayList[i]).PaneList == ((Pane)_arrayList[j]).PaneList + Math.Sqrt(_buttonNumber) + 1 || ((Pane)_arrayList[i]).PaneList == ((Pane)_arrayList[j]).PaneList + Math.Sqrt(_buttonNumber) - 1)
{
((Pane)_arrayList[j]).PaneNumber++;
}
}
chioce = true;
continue;
}
//判断右边的一列
if (((Pane)_arrayList[j]).PaneList > Math.Sqrt(_buttonNumber) * (Math.Sqrt(_buttonNumber) - 1) && ((Pane)_arrayList[j]).PaneList!=( Math.Sqrt(_buttonNumber) - 1))
{
//开始计算方格周围的雷的数量
foreach (int i in mineList)
{
if (((Pane)_arrayList[i]).PaneList == ((Pane)_arrayList[j]).PaneList + 1 || ((Pane)_arrayList[i]).PaneList == ((Pane)_arrayList[j]).PaneList - 1 || ((Pane)_arrayList[i]).PaneList == (((Pane)_arrayList[j]).PaneList - Math.Sqrt(_buttonNumber)) || ((Pane)_arrayList[i]).PaneList == ((Pane)_arrayList[j]).PaneList - Math.Sqrt(_buttonNumber) + 1 || ((Pane)_arrayList[i]).PaneList == ((Pane)_arrayList[j]).PaneList - Math.Sqrt(_buttonNumber) - 1)
{
((Pane)_arrayList[j]).PaneNumber++;
}
}
chioce = true;
continue;
}
//判断上边的一行
for (int q = Convert.ToInt32(Math.Sqrt(_buttonNumber)) ; q < Math.Sqrt(_buttonNumber) * (Math.Sqrt(_buttonNumber) - 1); q += Convert.ToInt32(Math.Sqrt(_buttonNumber)))
{
if (((Pane)_arrayList[j]).PaneList == q)
{
//开始计算方格周围的雷的数量
foreach (int i in mineList)
{
if (((Pane)_arrayList[i]).PaneList == ((Pane)_arrayList[j]).PaneList + 1 || ((Pane)_arrayList[i]).PaneList == ((Pane)_arrayList[j]).PaneList + Math.Sqrt(_buttonNumber) || ((Pane)_arrayList[i]).PaneList == ((Pane)_arrayList[j]).PaneList - Math.Sqrt(_buttonNumber) || ((Pane)_arrayList[i]).PaneList == ((Pane)_arrayList[j]).PaneList - Math.Sqrt(_buttonNumber) + 1 || ((Pane)_arrayList[i]).PaneList == ((Pane)_arrayList[j]).PaneList + Math.Sqrt(_buttonNumber) + 1)
{
((Pane)_arrayList[j]).PaneNumber++;
}
}
chioce = true;
break;
}
}
//判断下边的一行
for (int q = Convert.ToInt32(2 * Math.Sqrt(_buttonNumber) - 1); q <=( Math.Sqrt(_buttonNumber) * (Math.Sqrt(_buttonNumber) - 1) - 1); q += Convert.ToInt32(Math.Sqrt(_buttonNumber)))
{
if (((Pane)_arrayList[j]).PaneList == q)
{
//开始计算方格周围的雷的数量
foreach (int i in mineList)
{
if (((Pane)_arrayList[i]).PaneList == ((Pane)_arrayList[j]).PaneList - 1 || ((Pane)_arrayList[i]).PaneList == ((Pane)_arrayList[j]).PaneList + Math.Sqrt(_buttonNumber) || ((Pane)_arrayList[i]).PaneList == ((Pane)_arrayList[j]).PaneList + Math.Sqrt(_buttonNumber) - 1 || ((Pane)_arrayList[i]).PaneList == ((Pane)_arrayList[j]).PaneList - Math.Sqrt(_buttonNumber) || ((Pane)_arrayList[i]).PaneList == ((Pane)_arrayList[j]).PaneList - Math.Sqrt(_buttonNumber) - 1)
{
((Pane)_arrayList[j]).PaneNumber++;
}
}
chioce = true;
break;
}
}
#endregion
#region 判断中间的方格
//中间的
//开始计算方格周围的雷的数量
if (!chioce)
{
foreach (int i in mineList)
{
if (((Pane)_arrayList[i]).PaneList == ((Pane)_arrayList[j]).PaneList - 1 || ((Pane)_arrayList[i]).PaneList == ((Pane)_arrayList[j]).PaneList + 1 || ((Pane)_arrayList[i]).PaneList == ((Pane)_arrayList[j]).PaneList + Math.Sqrt(_buttonNumber) || ((Pane)_arrayList[i]).PaneList == ((Pane)_arrayList[j]).PaneList + Math.Sqrt(_buttonNumber) - 1 || ((Pane)_arrayList[i]).PaneList == ((Pane)_arrayList[j]).PaneList + Math.Sqrt(_buttonNumber) + 1 || ((Pane)_arrayList[i]).PaneList == ((Pane)_arrayList[j]).PaneList - Math.Sqrt(_buttonNumber) || ((Pane)_arrayList[i]).PaneList == ((Pane)_arrayList[j]).PaneList - Math.Sqrt(_buttonNumber) - 1 || ((Pane)_arrayList[i]).PaneList == ((Pane)_arrayList[j]).PaneList - Math.Sqrt(_buttonNumber) + 1)
{
((Pane)_arrayList[j]).PaneNumber++;
}
}
}
#endregion
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -