Introduction
Halo every one. Here is an interisting little game for you guys, it works with four timers in the background at all times. So we can say that this app is purely timer driven. I wont forget my friend Flesh_Eater who helped me a lot, i am still i newbie and i am trying to learn to do better.I hope you guys enjoy it.
Code sample 1
The following piece of code is activated when the Begin Button is pressed. The four timers are given interval values and the labels are given there positions.
int A = 0;
private void Beginbutton_Click(object sender, System.EventArgs e)
{
(this.label5.Text = "100";
(if(A == 0)
{
(this.timer1.Interval = 1;
(this.timer1.Start();
(this.timer2.Interval = 1;
(this.timer2.Start();
(this.timer3.Interval = 1;
(this.timer3.Start();
(this.timer4.Interval = 1000;
(this.timer4.Start();
(this.label3.Text = "0";
this.label1.Left = 19;
this.label1.Top = 96;
this.label2.Left = 264;
this.label2.Top = 216;
this.Beginbutton.Text = "Restart";
A = 1;
}
else
{
this.timer1.Stop();
this.timer2.Stop();
this.timer3.Stop();
this.timer4.Stop();
this.Beginbutton.Text = "Begin";
A = 0;
}
}
Code sample 2
In the following piece of code i am explaining how one of the two timers that control the images so that they dont go out of the borders to you.
static int X = 0;
static int Y = 0;
static int X1 = 0;
static int Y1 = 0;
private void timer1_Tick(object sender, System.EventArgs e)
{
switch(X)
{
case 0:
if(this.label1.Left >= 280)
{
X = 1;
}
this.label1.Left += 3;
break;
case 1:
if(this.label1.Left <= 0)
{
X = 0;
}
this.label1.Left -= 2;
break;
default:
break;
}
Code sample 3
Here is the discription of the third timer.
private void timer3_Tick(object sender, System.EventArgs e)
{
int S1 = (this.label1.Location.X +17);
int S2 = (this.label1.Location.X -17);
int S3 = (this.label1.Location.Y +17);
int S4 = (this.label1.Location.Y -17);
if(this.label2.Location.X <= S1)
{
if(this.label2.Location.X >= S2)
{
if(this.label2.Location.Y <= S3)
{
if(this.label2.Location.Y >= S4)
{
int Score = int.Parse(this.label3.Text);
Score++;
this.label3.Text = Score.ToString();
this.label1.ImageIndex = 1;
this.label2.ImageIndex = 1;
if (Y == 0)
{
Y = 1;
}
else
{
Y = 0;
}
if (Y1 == 0)
{
Y1 = 1;
}
else
{
Y1 = 0;
}
if (X == 0)
{
X = 1;
}
else
{
X = 0;
}
if (X1 == 0)
{
X1 = 1;
}
else
{
X1 = 0;
}
}
}
}
Final Code Sample
This is the final timer in the app, it controls functions like calculating the time adn stopping the rest of the timers.
private void timer4_Tick(object sender, System.EventArgs e)
{
int Time = int.Parse(this.label5.Text);
Time--;
this.label5.Text = Time.ToString();
this.label1.ImageIndex = 0;
this.label2.ImageIndex = 0;
if (Time == 0)
{
this.timer4.Stop();
this.timer3.Stop();
this.timer2.Stop();
this.timer1.Stop();
EndScore = int.Parse(this.label3.Text);
Form2 F2 = new Form2();
F2.Show();
}
}
Problems
My major problems with this app was that my two images kept going over the borders, the result was they did not bounce. This was solved with my friends (Fles_Eater) help in Code Sample 1.This baby was deeloped during the boring hours of school so it is not perfect i know that. I hope everyone enjoys this app and hopefully you will see many more.