//Opens the buttons that don't have value/0/. Called when an empty button is clicked private void OpenEmptyButtons(MineButton button) { if (NumberList[button.Index] == 0) { for (int i = 0; (i <= button.Index + mineSweeperSizes_[dificulty_][3] + 1) && (i < mineSweeperSizes_[dificulty_][1]); i++) { if (!ButtonList[i].Enabled) { continue; } //left neighbour if ((button.Location - new Size(button.Width, 0)) == ButtonList[i].Location) { NextClick(ButtonList[i]); } //right neighbour if ((button.Location + new Size(button.Width, 0)) == ButtonList[i].Location) { NextClick(ButtonList[i]); } //top neighbour if ((button.Location - new Size(0, button.Height)) == ButtonList[i].Location) { NextClick(ButtonList[i]); } //bottom neighbour if ((button.Location + new Size(0, button.Height)) == ButtonList[i].Location) { NextClick(ButtonList[i]); } //Diagonals //////up right if ((button.Location + new Size(button.Width, -button.Height)) == ButtonList[i].Location) { NextClick(ButtonList[i]); } ///// down right if ((button.Location - new Size(button.Width, button.Height)) == ButtonList[i].Location) { NextClick(ButtonList[i]); } ///// up left if ((button.Location + new Size(button.Width, button.Height)) == ButtonList[i].Location) { NextClick(ButtonList[i]); } ///// down left if ((button.Location + new Size(-button.Width, button.Height)) == ButtonList[i].Location) { NextClick(ButtonList[i]); } } } }
void NextClick(MineButton nextButton) { nextButton.Enabled = false; nextButton.BackColor = Color.FromArgb(100, 248, 23, 109); if (NumberList[nextButton.Index] == 0) { nextButton.Text = null; OpenEmptyButtons(nextButton); } else { nextButton.Text = NumberList[nextButton.Index].ToString(); } }
private void Button_Clicked(object sender, EventArgs e) { MineButton button = sender as MineButton; if (NumberList[button.Index] == 0) { OpenEmptyButtons(button); button.Text = null; } else { button.Text = NumberList[button.Index].ToString(); } }
public void Refresh() { rnd = new Random(); bombImage.Dispose(); flagImage.Dispose(); markImage.Dispose(); indicesRange_ = new List <int>(Enumerable.Range(0, mineSweeperSizes_[dificulty_][1])); notMineIndices_ = null; ButtonList = null; ButtonList = new MineButton[mineSweeperSizes_[dificulty_][1]]; GenButtons(); AddButtons(); notMineIndices_ = GenNotMineIndices(indicesRange_); UpdateNotMineButtons(); GenNumbers3(); EventClick(); }
private void Button_MouseClick(object sender, MouseEventArgs e) { MineButton button = sender as MineButton; if (FirstClick == 0) { timer.Start(); } FirstClick++; switch (e.Button) { case MouseButtons.Left: if (button.HasMine == false) { if (button.HasFlag) { this.Counter--; } label1.Text = "Mines: " + (mineSweeperSizes_[dificulty_][0] - Counter); label1.Update(); button.BackgroundImage = null; if (NumberList[button.Index] == 0) { OpenEmptyButtons(button); button.Text = null; } else { button.Text = NumberList[button.Index].ToString(); } } else { button.SetImage2(bombImage); MineForm.EndGame(0); } button.Enabled = false; button.BackColor = Color.FromArgb(100, 248, 23, 109); break; case MouseButtons.Right: //Set an image as background - 0 for flagImage and 1 for questionmarkImage if (timesClicked[button.Index] % 3 == 0) { button.HasFlag = true; button.SetImage2(flagImage); Counter++; } else if (timesClicked[button.Index] % 3 == 1) { button.HasFlag = false; button.HasMark = true; button.SetImage2(markImage); Counter--; } else if (timesClicked[button.Index] % 3 == 2) { button.HasMark = false; button.SetImage2(null); } label1.Text = "Mines: " + (mineSweeperSizes_[dificulty_][0] - Counter); label1.Update(); timesClicked[button.Index]++; if (mineSweeperSizes_[dificulty_][0] == Counter) { if (CheckFlags()) { MineForm.EndGame(2); } else { MineForm.EndGame(0); } } break; } }