Ball and Break Game in C#
This blog and the attached code is about a Game of Ball and Break written using C# and GDI+.
Hello!
This is a simple game about ball and break written in C#. The goal of this game is clear all the breaks. You can use up to 3 hits to clear breaks.
The game is designed in 3 levels.
Note : Berore run game please install .NET Framework 3.5 or higher.
Sample This Code :
//create array of picturebox
PictureBox pic = new PictureBox();
pic.Location = new System.Drawing.Point(x, y);
pic.Name = pics.Count.ToString();
pic.BackColor = Color.Transparent;
pic.Image = global::game.Resource1.wall_red;
pic.SizeMode = PictureBoxSizeMode.StretchImage;
pic.Size = new System.Drawing.Size(width, height);
pic.TabIndex = 0;
//adding picturebox
int x, y;
pics = new ArrayList(10);
for (y = 0; y < 1; y++)
{
for (x = 0; x < 10; x++)
{
this.Addpics(62 * x, 30 * y, 60, 30);
}
}
//ÑÏÔ Èå ÑÇÓÊ ÈÇ ˜äÏí or // Go To Left
if (pictureBox1.Left + pictureBox1.Width >= pictureBox5.Left &&
pictureBox1.Left + pictureBox1.Width <= pictureBox5.Left + pictureBox5.Width
&& pictureBox1.Top + pictureBox1.Height >= pictureBox5.Top &&
pictureBox1.Top + pictureBox1.Height <= pictureBox5.Top + pictureBox5.Height + pictureBox1.Height)
{
ball = Resource1.BALLme;
Playpadd();
pictureBox5.BackColor = Color.Red;
pictureBox5.Image = null;
pictureBox2.Image = global::game.Resource1.paddle2; pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage; pictureBox2.BackColor =
Color.Red;
pictureBox3.Image = global::game.Resource1.paddle2; pictureBox3.SizeMode = PictureBoxSizeMode.StretchImage; pictureBox3.BackColor =
Color.Red;
pictureBox4.Image = global::game.Resource1.paddle2; pictureBox4.SizeMode = PictureBoxSizeMode.StretchImage; pictureBox4.BackColor =
Color.Red;
iss = false;
top = false;
left = true;
//result += 100;
}
if (iss == false) { if (left) pictureBox1.Left += speed; else pictureBox1.Left -= speed; }//Èå ˜äÏí
if (iss == true) { if (left) pictureBox1.Left += 12; else pictureBox1.Left -= 12; }//Èå ÓÑÚÊ
if (iss == false) { if (top) pictureBox1.Top += speed; else pictureBox1.Top -= speed; }
if (iss == true) { if (top) pictureBox1.Top += speed; else pictureBox1.Top -= speed; }
if (pictureBox1.Top <= 0) top = true;
if (pictureBox1.Left >= this.Width - 30) left = false;
if (pictureBox1.Left <= 0) left = true;
if (pictureBox1.Left >= this.Width - 30)
{
Playaround();
}
if (pictureBox1.Left <= 1)
{
Playaround();
}
if (pictureBox1.Top <= 0)
{
Playaround();
}
this.Text = "Welcome : " + global.nm + " -" + " Score : " + result.ToString();
//For Each Picturebox
for (i = 0; i <= 59; i++)
{
picc[i] = (PictureBox)pics[i];
picc[i].Visible = false;
}
//Each Rectangle Of Picturebox
rc1[i] = new Rectangle(picc[i].Left, picc[i].Top, picc[i].Width, picc[i].Height);v
DOWNLOAD THIS GAME FROM MY WEBSITE:
http://www.zunkan.ir/uploadarticles/brickgame.zip
OR
http://www.zunkan.ir/Showsubject.aspx?id=17
ENJOY IT.