C
C#11mo ago
winterz

automatic restart game

i want my game to auto restart when im game over
No description
7 Replies
CoRoys
CoRoys11mo ago
$code
MODiX
MODiX11mo ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat For longer snippets, use: https://paste.mod.gg/
CoRoys
CoRoys11mo ago
$codegif
winterz
winterzOP11mo ago
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 flappy_bird_windows_form
{
public partial class Form1 : Form
{

int pipeSpeed = 8;
int gravity = 10;
int score = 0;



public Form1()
{
InitializeComponent();
}

private void pictureBox4_Click(object sender, EventArgs e)
{

}



private void gameTimerEvent(object sender, EventArgs e)
{
flappyBird.Top += gravity;
pipeBottom.Left -= pipeSpeed;
pipeTop.Left -= pipeSpeed;
scoreText.Text = "score: " + score;

if(pipeBottom.Left < -100)
{
pipeBottom.Left = 500;
score++;
}

if(pipeTop.Left < -130 )
{
pipeTop.Left = 650;
score++;
}
if (flappyBird.Bounds.IntersectsWith(pipeBottom.Bounds) ||
flappyBird.Bounds.IntersectsWith(pipeTop.Bounds) ||
flappyBird.Bounds.IntersectsWith(ground.Bounds) || flappyBird.Top < -25

)
{
endGame();
}

}

private void gamekeyisdown(object sender, KeyEventArgs e)
{
if(e.KeyCode == Keys.Space)
{
gravity = -10; }
}

private void gamekeyisup(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Space)
{
gravity = 10;
}

}
private void endGame()
{
gameTimer.Stop();
scoreText.Text += "game over!!!";


}



}
}
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 flappy_bird_windows_form
{
public partial class Form1 : Form
{

int pipeSpeed = 8;
int gravity = 10;
int score = 0;



public Form1()
{
InitializeComponent();
}

private void pictureBox4_Click(object sender, EventArgs e)
{

}



private void gameTimerEvent(object sender, EventArgs e)
{
flappyBird.Top += gravity;
pipeBottom.Left -= pipeSpeed;
pipeTop.Left -= pipeSpeed;
scoreText.Text = "score: " + score;

if(pipeBottom.Left < -100)
{
pipeBottom.Left = 500;
score++;
}

if(pipeTop.Left < -130 )
{
pipeTop.Left = 650;
score++;
}
if (flappyBird.Bounds.IntersectsWith(pipeBottom.Bounds) ||
flappyBird.Bounds.IntersectsWith(pipeTop.Bounds) ||
flappyBird.Bounds.IntersectsWith(ground.Bounds) || flappyBird.Top < -25

)
{
endGame();
}

}

private void gamekeyisdown(object sender, KeyEventArgs e)
{
if(e.KeyCode == Keys.Space)
{
gravity = -10; }
}

private void gamekeyisup(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Space)
{
gravity = 10;
}

}
private void endGame()
{
gameTimer.Stop();
scoreText.Text += "game over!!!";


}



}
}
CoRoys
CoRoys11mo ago
First, know which method handles the game over event:
private void EndGame()
{
gameTimer.Stop();
scoreText.Text += "game over!!!";

Thread.Sleep(2000); // wait for 2 seconds before resetting the game
// reset all game object values to default
}
private void EndGame()
{
gameTimer.Stop();
scoreText.Text += "game over!!!";

Thread.Sleep(2000); // wait for 2 seconds before resetting the game
// reset all game object values to default
}
Then, you need to set components like flappyBird, scoreText, etc... back to their defaults individually
daniel2
daniel211mo ago
U can try close and re-open the form
Want results from more Discord servers?
Add your server