Example #1
0
        // called when a mineButton is clicked
        private void RemoveMineButton(object sender, MouseEventArgs e)
        {
            // If Game over return
            if (GameData.isGameOver)
            {
                return;
            }
            // Read the X and Y values
            Label btn = sender as Label;
            int   x   = ((Tuple <int, int>)btn.Tag).Item1;
            int   y   = ((Tuple <int, int>)btn.Tag).Item2;

            // when removing a tile
            if (e.Button == MouseButtons.Left && !GameData.GetCellFlagged(x, y))
            {
                if (GameData.CheckFirstMove(x, y))
                {
                    setMineLabelValues();
                }

                GameForm.Controls.Remove(sender as Label);
                GameData.SetCellHidded(x, y, false);
                if (GameData.GetCellValue(x, y) == 0)
                {
                    ClearSurroundingButtons(x, y);
                }
                GameData.TestGameOver();
            }

            // when flagging
            if (e.Button == MouseButtons.Right)
            {
                if (!GameData.GetCellFlagged(x, y) && !GameData.GetCellQuestion(x, y) && (GameForm.Controls.Find("ScoreTextBox", true)[0].Text != "000"))
                {
                    GameData.SetCellFlagged(x, y, true);
                    GameData.SetCellQuestion(x, y, false);
                    (sender as Label).Text = "F";
                    int numFlagged = GameData.GetTotalFlaggedTiles();
                    GameForm.Controls.Find("ScoreTextBox", true)[0].Text = ((int)GameData.NumberOfMines - numFlagged).ToString("D" + 3);
                }
                else if (!GameData.GetCellQuestion(x, y))
                {
                    GameData.SetCellFlagged(x, y, false);
                    GameData.SetCellQuestion(x, y, true);
                    (sender as Label).Text = "?";
                    int numFlagged = GameData.GetTotalFlaggedTiles();
                    GameForm.Controls.Find("ScoreTextBox", true)[0].Text = ((int)GameData.NumberOfMines - numFlagged).ToString("D" + 3);
                }
                else if (!GameData.GetCellFlagged(x, y) && GameData.GetCellQuestion(x, y))
                {
                    GameData.SetCellFlagged(x, y, false);
                    GameData.SetCellQuestion(x, y, false);
                    (sender as Label).Text = "";
                }
            }
        }