Game Over

The game over screen is shown to the user when their player character's life total reaches zero.

The screen itself

The image was created by prompting DALL.E-3 with ideas of a "game over screen featuring Mr. Peanut as a character."

The trigger

The trigger to display the game over screen happens within FrmBattle.cs Form. The Form FrmGameOver is newly initialized and shown when the player's health is at or below zero.

if (player.Health <= 0)
            {
                FrmGameOver frmGameOver = new FrmGameOver();
                frmGameOver.Show();

                instance = null;
                Close();
            }

How it works

Try Again and Quit Buttons

These buttons are presented to the player in a new window after their health depletes in battle. The functionality of the buttons are below.

// quit button
private void button2_Click(object sender, EventArgs e) {
    Application.Exit();
}

// retry button
private void button1_Click(object sender, EventArgs e) {
    Application.Restart();
}

These buttons simply use a built-in class within the project that handles the properties and static methods of a Windows Forms application, such as starting and stopping an application, Windows message processing, and fetching application properties.

Application.Exit() informs all message pumps that they must terminate, and then closes all application windows after the messages have been processed.

Application.Restart() shuts down the application and starts a new instance immediately.

Last updated