I am making a game in C# and the game will not end once the Life has hit 0. The game however does show the ending MessageBox alerting the User that they have no live remaining which by pressing OK the game should close and the Gameover Dialog Form should show. However the game just restarts again from scratch while the Gameover form shows. Can anyone help me as this project has all the elements of a small indie side scroll game which I will be using this Game as an introduction to the components within my next project. This is the code which I have used, if you can help me it would be greatly appreciated. Bear in mind this is my first question posted and having searched extensively for the solution which I have not been able to find.
using System; //--->
using System.Collections.Generic; //--->
using System.ComponentModel; //--->
using System.Data; //--->
using System.Drawing; //--->
using System.Linq; //--->
using System.Text; //--->
using System.Threading.Tasks; //--->
using System.Windows.Forms; //------>
namespace BouningBall
{
public partial class EasyGame : Form
{
public int speed_Left = 5;
public int speed_Top = 3;
public int Lifes = 3;
int Points = 0;
public EasyGame()
{
InitializeComponent();
EasyTimer.Enabled = true;
EasyLife.Text = Lifes.ToString();
this.FormBorderStyle = FormBorderStyle.Sizable;
this.TopMost = true;
this.Bounds = Screen.PrimaryScreen.Bounds;
Cursor.Hide();
Bar.Top = Playground.Bottom - (Playground.Bottom / 10);
}
private void EasyTimer_Tick(object sender, EventArgs e)
{
Bar.Left = Cursor.Position.X - (Bar.Width / 2);
Ball.Left += speed_Left;
Ball.Top += speed_Top;
if (EasyLife.Text == "0")
{
EasyTimer.Stop();
if (Lifes == 0)
EasyTimer.Stop();
this.Hide();
Cursor.Show();
string info = "lost ...";
string snippet = "all lifes have been used...";
MessageBoxButtons digits = MessageBoxButtons.OK;
DialogResult ending;
ending = MessageBox.Show(info, snippet, digits);
if (ending == System.Windows.Forms.DialogResult.OK)
{
EasyTimer.Stop();
EndLife Final = new EndLife();
Final.Show();
}
}
if (Ball.Bottom >= Bar.Top && Ball.Bottom <= Bar.Bottom && Ball.Left >= Bar.Left && Ball.Right <= Bar.Right)
{
speed_Top += 3;
speed_Left += 3;
speed_Top = -speed_Top;
Points += 1;
Easygamepoints.Text = Points.ToString();
}
if (Ball.Left <= Playground.Left)
{
speed_Left = -speed_Left;
}
if (Ball.Right >= Playground.Right)
{
speed_Left = -speed_Left;
}
if (Ball.Top <= Playground.Top)
{
speed_Top = -speed_Top;
}
if (Ball.Bottom >= Playground.Bottom)
{
EasyTimer.Stop();
Cursor.Show();
Lifes -= 1;
string message = "You have lost one of your lives...";
string caption = "You died, Life Lost...";
MessageBoxButtons buttons = MessageBoxButtons.OK;
DialogResult result;
result = MessageBox.Show(message, caption, buttons);
if (result == System.Windows.Forms.DialogResult.OK)
{
EasyTimer.Enabled = false;
Cursor.Hide();
EasyLife.Text = Lifes.ToString();
EasyTimer.Start();
speed_Left = 5;
speed_Top = 3;
Ball.Top = 69;
Ball.Left = 128;
}
}
}
}
}
Due to Confusion, this body has been edited to allow better understanding of the objective that needs to be met.`enter code here`