protected void MineSquareButton_Click(object sender, EventArgs e) { MouseEventArgs me = (MouseEventArgs)e; Button button = sender as Button; MineSquare mine = button.Tag as MineSquare; int pos = mine.GetIndex(); if (me.Button == MouseButtons.Right) { MineSquareButtonRight_click(button, pos); return; } if (mineLand.HasGameEnded()) { return; } if (mine.GetState() == SquareState.MineExploded || mine.GetState() == SquareState.EmptyExposed || mine.GetState() == SquareState.Flagged) { return; } if (mineLand.ProbeForMine(pos, true)) { SetButtonStyleByState(button, 0, SquareState.MineExploded); SetAndCenterGameInfo("You Lost!", Color.Red); timeElapsed.Stop(); RevealEntireBoard(pos); return; } mine.ChangeState(SquareState.EmptyExposed); var mineCount = InspectAndCountNearbyMines(pos, false); SetButtonStyleByState(button, mineCount, SquareState.EmptyExposed); if (mineCount == 0) { InspectAndCountNearbyMines(pos, true); } if (mineLand.CheckIfAllCleared()) { SetAndCenterGameInfo("All Cleared!", Color.Blue); timeElapsed.Stop(); } }
private void RevealEntireBoard(int skipPos) { foreach (Control button in MineFlowPanel.Controls) { MineSquare mineSquare = (MineSquare)button.Tag; var btnPos = mineSquare.GetIndex(); if (btnPos == skipPos) { continue; } var curBtnState = mineSquare.GetState(); switch (curBtnState) { case SquareState.Flagged: if (mineSquare.HasMine()) { SetButtonStyleByState(button, 0, SquareState.Flagged); mineSquare.ChangeState(SquareState.Flagged); } else { SetButtonStyleByState(button, 0, SquareState.WrongGuess); mineSquare.ChangeState(SquareState.WrongGuess); } break; case SquareState.Untouched: if (mineSquare.HasMine()) { SetButtonStyleByState(button, 0, SquareState.MineExposed); mineSquare.ChangeState(SquareState.MineExposed); } else { if (debugMode) { var mineCount = InspectAndCountNearbyMines(btnPos, false); if (mineCount > 0) { SetButtonStyleByState(button, mineCount); } else { SetButtonStyleByState(button, 0, SquareState.EmptyExposed); } mineLand.GetMineSquare(btnPos).ChangeState(SquareState.EmptyExposed); } } break; case SquareState.Questioned: if (mineSquare.HasMine()) { SetButtonStyleByState(button, 0, SquareState.MineExposed); mineSquare.ChangeState(SquareState.MineExposed); } else { if (debugMode) { SetButtonStyleByState(button, 0, SquareState.EmptyExposed); } } break; } } }