private void play_btn_Click(object sender, EventArgs e) { // Create new Form1, hide Form3, show Form1 Form1 f1 = new MinesweeperGUI.Form1(); this.Hide(); f1.Show(); }
/* * Method to restart the game */ private void restart_btn_Click(object sender, EventArgs e) { // Stop watch watch.Stop(); // Create new Form1, hide Form2, show Form1 Form1 f1 = new MinesweeperGUI.Form1(); this.Hide(); f1.Show(); }
/* * Method for the user pressing the mouse (right or left) on the panel */ private void buttonPanel_MouseDown(object sender, MouseEventArgs e) { // Get the row and column number of the button clicked Button buttonClicked = (Button)sender; Point location = (Point)buttonClicked.Tag; int x = location.X; int y = location.Y; // Check if it was left click if (e.Button == MouseButtons.Left) { // Initialize currentCell as button pressed on board Cell currentCell = board.grid[x, y]; // If the user selected a bomb if (currentCell.bomb == true) { // Game is over, call method to reveal board gameOverShowBoard(); // Stop the timer watch.Stop(); // Messagebox of game over DialogResult result = MessageBox.Show("You hit a bomb! Game over." + Environment.NewLine + Environment.NewLine + "Do you want to play again?", "Game Over", MessageBoxButtons.YesNo); // If they want to play again if (result == DialogResult.Yes) { // Create new Form1, hide Form2, show Form1 Form1 f1 = new MinesweeperGUI.Form1(); this.Hide(); f1.Show(); } // Else, they dont want to play again else { // Close the form this.Close(); } } else { // Flood fill surrounding buttons board.floodFill(x, y); // Show all visited buttons showVisited(); } } // Else, it was a right click else if (e.Button == MouseButtons.Right) { // Set button to flag image buttonGrid[x, y].BackgroundImage = Image.FromFile(@"C:\\Users\holla\source\repos\cst-227\MinesweeperGUI\flag.png"); buttonGrid[x, y].BackgroundImageLayout = ImageLayout.Stretch; } // Check to see if game is over if (board.isFinished() == true) { // Stop watch watch.Stop(); // Set all bomb spaces to flag setBombsToFlag(); // Input message box to get users name for leaderboard string name = Interaction.InputBox("Congratulations, you won!" + Environment.NewLine + "Time elapsed: " + timer_label.Text + Environment.NewLine + Environment.NewLine + "Enter your name to see if you made the leaderboard.", "You Won!", "NewPlayer"); // Write score to file readInAndWriteOutToFile(name); // Create new Form3, hide Form2, show Form3 Form3 f3 = new MinesweeperGUI.Form3(leaderboard, board.size); this.Hide(); f3.Show(); } }