Example #1
0
 /// <summary>
 /// 重新这一局
 /// </summary>
 void againTheGame()
 {
     initializeVariable();
     foreach (Object control in this.Controls)
     {
         if (control is grid)
         {
             grid fg = (grid)control;
             fg.fasade = stateGrid.unknown;
         }
     }
     changeSurplusMineNum();
 }
Example #2
0
        /// <summary>
        /// 方格点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void gridClickInsident(object sender, MouseEventArgs e)
        {
            grid fg = (grid)sender;

            switch (e.Button)
            {
            case MouseButtons.Left:
                if (isGameContinue == true)
                {
                    if (fg.fasade == stateGrid.unknown || fg.fasade == stateGrid.query)
                    {
                        fg.fasade = stateGrid.open;
                        bombMethod(fg);
                        judgeWin();
                    }
                }
                break;

            case MouseButtons.Right:
                if (isGameContinue == true)
                {
                    if (markNum > 0)
                    {
                        if (fg.fasade == stateGrid.unknown || fg.fasade == stateGrid.query)
                        {
                            fg.fasade = stateGrid.mark;
                            markNum--;
                            changeSurplusMineNum();
                        }
                        else if (fg.fasade == stateGrid.mark)
                        {
                            fg.fasade = stateGrid.query;
                            markNum++;
                            changeSurplusMineNum();
                        }
                    }
                    else
                    {
                        if (fg.fasade == stateGrid.mark)
                        {
                            fg.fasade = stateGrid.query;
                            markNum++;
                            changeSurplusMineNum();
                        }
                    }
                }
                break;
            }
        }
Example #3
0
 void createGrid()
 {
     for (int i = 0; i < gridListNum; i++)
     {
         for (int j = 0; j < gridRowNum; j++)
         {
             grid createGrid = new grid();
             createGrid.Location        = new Point((grid.width + gridInterval) * i, (grid.height + gridInterval) * j);
             createGrid.MouseDown      += gridClickInsident;
             createGrid.x_Coordinate    = i;
             createGrid.y_Coordinate    = j;
             gridCoordinateGather[i, j] = createGrid;
             this.Controls.Add(createGrid);
         }
     }
 }
Example #4
0
 /// <summary>
 /// 重新下一局
 /// </summary>
 void againNextGame()
 {
     initializeVariable();
     foreach (Object control in this.Controls)
     {
         if (control is grid)
         {
             grid fg = (grid)control;
             fg.fasade       = stateGrid.unknown;
             fg.isMine       = false;
             fg.roundMineNum = 0;
         }
     }
     randomInstallMine();
     judgeRoundMineNum();
     changeSurplusMineNum();
 }
Example #5
0
 /// <summary>
 /// 爆炸方法
 /// </summary>
 /// <param name="bomb"></param>
 void bombMethod(grid bomb)
 {
     if (bomb.isMine == true)
     {
         try
         {
             foreach (grid control in this.Controls)
             {
                 if (control.isMine == true)
                 {
                     control.fasade = stateGrid.bomb;
                 }
             }
         }
         catch (Exception) {; }
         isGameContinue       = false;
         bomb.BackgroundImage = Image.FromFile("Images\\主动爆炸.jpg");
         openNum = -1;  //最后一个打开是雷时,不判断赢
         MessageBox.Show("GameOver!!!游戏结束");
     }
 }
Example #6
0
 /// <summary>
 /// 周围没有雷时,扩散
 /// </summary>
 void proliferateMethod()
 {
     if (roundMineNum == 0)
     {
         foreach (Object control in this.Parent.Controls)
         {
             if (control is grid)
             {
                 grid _grid = (grid)control;
                 if (_grid.fasade == stateGrid.unknown || _grid.fasade == stateGrid.query)
                 {
                     try
                     {
                         if (_grid.x_Coordinate + 1 == this.x_Coordinate && _grid.y_Coordinate + 1 == this.y_Coordinate)
                         {
                             _grid.fasade = stateGrid.open;
                         }
                     }
                     catch { }
                     try
                     {
                         if (_grid.x_Coordinate == this.x_Coordinate && _grid.y_Coordinate + 1 == this.y_Coordinate)
                         {
                             _grid.fasade = stateGrid.open;
                         }
                     }
                     catch { }
                     try
                     {
                         if (_grid.x_Coordinate - 1 == this.x_Coordinate && _grid.y_Coordinate + 1 == this.y_Coordinate)
                         {
                             _grid.fasade = stateGrid.open;
                         }
                     }
                     catch { }
                     try
                     {
                         if (_grid.x_Coordinate + 1 == this.x_Coordinate && _grid.y_Coordinate == this.y_Coordinate)
                         {
                             _grid.fasade = stateGrid.open;
                         }
                     }
                     catch { }
                     try
                     {
                         if (_grid.x_Coordinate - 1 == this.x_Coordinate && _grid.y_Coordinate == this.y_Coordinate)
                         {
                             _grid.fasade = stateGrid.open;
                         }
                     }
                     catch { }
                     try
                     {
                         if (_grid.x_Coordinate + 1 == this.x_Coordinate && _grid.y_Coordinate - 1 == this.y_Coordinate)
                         {
                             _grid.fasade = stateGrid.open;
                         }
                     }
                     catch { }
                     try
                     {
                         if (_grid.x_Coordinate == this.x_Coordinate && _grid.y_Coordinate - 1 == this.y_Coordinate)
                         {
                             _grid.fasade = stateGrid.open;
                         }
                     }
                     catch { }
                     try
                     {
                         if (_grid.x_Coordinate - 1 == this.x_Coordinate && _grid.y_Coordinate - 1 == this.y_Coordinate)
                         {
                             _grid.fasade = stateGrid.open;
                         }
                     }
                     catch { }
                 }
             }
         }
     }
 }