예제 #1
0
        //Bind Mouse Clicks
        private void Grid_Button_MouseDown(object sender, MouseEventArgs e)
        {
            Button ClickedButton  = (Button)sender;
            Point  ButtonLocation = (Point)ClickedButton.Tag;
            int    x        = ButtonLocation.X;
            int    y        = ButtonLocation.Y;
            Cell   ThisCell = MineSweeperBoard.Grid[x, y];

            StartTimer();

            //Left Mouse Button Click
            if (e.Button == MouseButtons.Left)
            {
                if (ThisCell.Visited == false && ThisCell.Flagged == false)
                {
                    MineCheck(MineSweeperBoard.MinePresent(x, y));
                    MineSweeperBoard.VisitBlocksWithNoLiveNeighbors(x, y);
                    ThisCell.Visited = true;
                }
            }

            //Right Mouse Button Click
            if (e.Button == MouseButtons.Right)
            {
                if (ThisCell.Flagged == false && ThisCell.Visited == false)
                {
                    ThisCell.Flagged = true;
                    MinesLeft--;
                    lbl_mines.Text = MinesLeft.ToString();
                }
                else if (ThisCell.Flagged)
                {
                    ThisCell.Flagged = false;
                    MinesLeft++;
                    lbl_mines.Text = MinesLeft.ToString();
                }
            }

            //Double Mouse Button Click
            if (((Control.MouseButtons & MouseButtons.Right) == MouseButtons.Right) &&
                ((Control.MouseButtons & MouseButtons.Left) == MouseButtons.Left))
            {
                if (ThisCell.Visited == true)
                {
                    MineCheck(MineSweeperBoard.ClearSimilarLiveNeighbors(x, y));
                }
            }
            RefreshBoard(MineSweeperBoard);
            CheckWin(MineSweeperBoard);
        }
예제 #2
0
 private void RefreshMineInfoTextBox()
 {
     if (MinesLeft > 99)
     {
         MinesInfo.Text = "99";
     }
     else if (MinesLeft < 0)
     {
         MinesInfo.Text = "00";
     }
     else
     {
         MinesInfo.Text = MinesLeft.ToString("00");
     }
 }
예제 #3
0
        public Form2(string Difficulty)
        {
            GameDifficulty   = Difficulty;
            MineSweeperBoard = new GameBoard(Difficulty);
            ButtonArray      = new Button[MineSweeperBoard.Size, MineSweeperBoard.Size];
            BUTTONSIZE       = 21;
            GameTimer        = new Stopwatch();
            MinesLeft        = MineSweeperBoard.NumMines;

            this.Size = new Size(300, 300);

            InitializeComponent();
            lbl_mines.Text = MinesLeft.ToString();
            CreateButtonArray();
            MineSweeperBoard.SetMinesAndLabels();
        }