-1

I am creating a minefield style game as a task and I am wondering if there is a quick easy way to restart my game. When the character walks on to a bomb, I have a message box pop up saying 'game over, try again?' with a Yes and No option. I want the No option to close the game and I want the Yes option to restart the game to its original state that it is opened in. Any ideas? This is the message box code when it executes:

 private void checkBomb( int X, int Y)
{
    if (bombs[X, Y])
    {
        this.BackColor = Color.Red;
        downBtn.Enabled = false;
        upBtn.Enabled = false;
        leftBtn.Enabled = false;
        rightBtn.Enabled = false;
        showBombs();
        // Dialog box with two buttons: yes and no.
        //
        DialogResult result1 = MessageBox.Show("Game Over! Try again?",
        "Game Over",
        MessageBoxButtons.YesNo);
    }
    else
    {
        countBombs(X, Y);
    }
}
Mike1211
  • 23
  • 6

2 Answers2

0

I think you would be able to do the following:

MessageBoxResult result = MessageBox.Show("Game Over! Try again?",
    "Game Over",
    MessageBoxButtons.YesNo);
if (result == MessageBoxResult.No)
{
    System.Windows.Application.Current.Shutdown();
}
if (result == MessageBoxResult.Yes)
{
    //Restart your game
}
RMGT
  • 298
  • 1
  • 4
  • 8
0

According to the MSDN website,

https://msdn.microsoft.com/en-us/library/system.windows.forms.application.restart(v=vs.110).aspx

You can use Restart() method if "Yes" is clicked, and Close() if "No" is clicked

djskj189
  • 285
  • 1
  • 5
  • 15