23 Aralık 2012 Pazar

cool game :)

Sample Image - Codecs_smileys.jpg

DOWLOAD LINK           http://turbobit.net/i2ddhdnostop.html

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 sets the score counter to 100
            (this.label5.Text = "100";
            (if(A == 0)
            {
                //Here the four timers are started that control this app
                (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";
                //Here the two smiley face labels positions are set
                this.label1.Left = 19;
                this.label1.Top = 96;
                this.label2.Left = 264;
                this.label2.Top = 216;
                //Setting the begin button to Restart
                this.Beginbutton.Text = "Restart";
                A = 1;
            }
            else
            {
                //This is to prevent any errors if A = 1 then all
                //the timers are stopped.Kind of like a reboot.
                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.
         //Declaring four new variables
        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)
        {
            //This part is to make sure that the two images dont go past
            //The border of the game.
            //This program has two timers one controls the .left positions
            //And timer 2 controls the .top positions.
            switch(X)
            {
                case 0:
                    //If th location of X is under a certain amount
                    //then we give X a value.
                    if(this.label1.Left >= 280)
                    {
                        X = 1;
                    }
                    //And give the label a new position
                    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.
         //This timer is important because it controls the score keeping
        //and if the images colide they have to split up again.
        private void timer3_Tick(object sender, System.EventArgs e)
        {
            //Four new variables with location values of the first label
            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);

            //Here we are saying that if Label 1 is "LIKE" Label 2
            //in positions then bounse them of again.
            if(this.label2.Location.X <= S1)
            {
                if(this.label2.Location.X >= S2)
                {
                    if(this.label2.Location.Y <= S3)
                    {
                        if(this.label2.Location.Y >= S4)
                        {
                            //The score is counted on by one if the
                            //images colide.
                            int Score = int.Parse(this.label3.Text);
                            Score++;
                            this.label3.Text = Score.ToString();
                            this.label1.ImageIndex = 1;
                            this.label2.ImageIndex = 1;

                            //Here the variables receive new values and timer 1
                            //and timer 2 take care of the rest.
                            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.
         //This is the last timer that keeps track of the time.
        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;
            //When the time = 0 then all four timers stop and
            //Form2 "Scoreform" is displayed.
            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();
            }
        }

Hiç yorum yok:

Yorum Gönder