Esempio n. 1
0
 void 生成方格()
 {
     for (int i = 0; i < 方格列数; i++)
     {
         for (int j = 0; j < 方格行数; j++)
         {
             方格 tld = new 方格();
             tld.Location   = new Point((方格.宽 + 方格间隔) * i, (方格.高 + 方格间隔) * j);
             tld.MouseDown += 点击事件;
             tld.横坐标        = i;
             tld.纵坐标        = j;
             方格坐标集合[i, j]   = tld;
             this.Controls.Add(tld);
         }
     }
 }
Esempio n. 2
0
 void 爆炸方法(方格 bomb)
 {
     if (bomb.是不是地雷 == true)
     {
         foreach (方格 control in this.Controls)
         {
             if (control.是不是地雷 == true)
             {
                 control.外观 = 方格状态.爆炸;
             }
         }
         游戏能不能继续 = false;
         bomb.BackgroundImage = Image.FromFile("Images\\主动爆炸.jpg");
         打开数量 = -1;  //最后一个打开是雷时,不判断赢
         MessageBox.Show("GameOver!!!游戏结束");
     }
 }
Esempio n. 3
0
        void 点击事件(object sender, MouseEventArgs e)
        {
            方格 fg = (方格)sender;

            switch (e.Button)
            {
            case MouseButtons.Left:
                if (游戏能不能继续 == true)
                {
                    if (fg.外观 == 方格状态.未知 || fg.外观 == 方格状态.疑问)
                    {
                        fg.外观 = 方格状态.打开;
                        爆炸方法(fg);
                        判断赢();
                    }
                }
                break;

            case MouseButtons.Right:
                if (游戏能不能继续 == true)
                {
                    if (标记数量 > 0)
                    {
                        if (fg.外观 == 方格状态.未知 || fg.外观 == 方格状态.疑问)
                        {
                            fg.外观 = 方格状态.标记;
                            标记数量--;
                        }
                        else if (fg.外观 == 方格状态.标记)
                        {
                            fg.外观 = 方格状态.疑问;
                            标记数量++;
                        }
                    }
                    else
                    {
                        if (fg.外观 == 方格状态.标记)
                        {
                            fg.外观 = 方格状态.疑问;
                            标记数量++;
                        }
                    }
                }
                break;
            }
        }
Esempio n. 4
0
 /// <summary>
 /// 周围没有雷时,扩散
 /// </summary>
 /// <param name="横坐标"></param>
 /// <param name="纵坐标"></param>
 void 扩散方法(int 横坐标, int 纵坐标)
 {
     if (周围雷数量 == 0)
     {
         foreach (Object control in this.Parent.Controls)
         {
             方格 _方格 = (方格)control;
             if (_方格.外观 == 方格状态.未知 || _方格.外观 == 方格状态.疑问)
             {
                 try
                 {
                     if (_方格.横坐标 + 1 == this.横坐标 && _方格.纵坐标 + 1 == this.纵坐标)
                     {
                         _方格.外观 = 方格状态.打开;
                     }
                 }
                 catch { }
                 try
                 {
                     if (_方格.横坐标 == this.横坐标 && _方格.纵坐标 + 1 == this.纵坐标)
                     {
                         _方格.外观 = 方格状态.打开;
                     }
                 }
                 catch { }
                 try
                 {
                     if (_方格.横坐标 - 1 == this.横坐标 && _方格.纵坐标 + 1 == this.纵坐标)
                     {
                         _方格.外观 = 方格状态.打开;
                     }
                 }
                 catch { }
                 try
                 {
                     if (_方格.横坐标 + 1 == this.横坐标 && _方格.纵坐标 == this.纵坐标)
                     {
                         _方格.外观 = 方格状态.打开;
                     }
                 }
                 catch { }
                 try
                 {
                     if (_方格.横坐标 - 1 == this.横坐标 && _方格.纵坐标 == this.纵坐标)
                     {
                         _方格.外观 = 方格状态.打开;
                     }
                 }
                 catch { }
                 try
                 {
                     if (_方格.横坐标 + 1 == this.横坐标 && _方格.纵坐标 - 1 == this.纵坐标)
                     {
                         _方格.外观 = 方格状态.打开;
                     }
                 }
                 catch { }
                 try
                 {
                     if (_方格.横坐标 == this.横坐标 && _方格.纵坐标 - 1 == this.纵坐标)
                     {
                         _方格.外观 = 方格状态.打开;
                     }
                 }
                 catch { }
                 try
                 {
                     if (_方格.横坐标 - 1 == this.横坐标 && _方格.纵坐标 - 1 == this.纵坐标)
                     {
                         _方格.外观 = 方格状态.打开;
                     }
                 }
                 catch { }
             }
         }
     }
 }