Ejemplo n.º 1
0
        private void startButton_Click(object sender, EventArgs e)
        {
            Form f = this.FindForm();

            f.Controls.Remove(this);

            MainScreen ms = new MainScreen();

            f.Controls.Add(ms);
            ms.Focus();
        }
Ejemplo n.º 2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            // Create an instance of the MainScreen

            MainScreen ms = new MainScreen();



            // Add the User Control to the Form

            this.Controls.Add(ms);
        }
Ejemplo n.º 3
0
        private void gameLoop_Tick_1(object sender, EventArgs e)
        {
            foreach (Obstacles b in left)
            {
                b.Move(-5);
            }
            foreach (Obstacles b in right)
            {
                b.Move(-5);
            }

            foreach (Obstacles b in middle)
            {
                b.Move(5);
            }
            //remove box if it has gone of screen
            if (left[0].y < 0)
            {
                left.RemoveAt(0);
            }
            if (right[0].y < 0)
            {
                right.RemoveAt(0);
            }
            if (middle[0].y > this.Height)
            {
                middle.RemoveAt(0);
            }
            //add new box if it is time
            if (left[left.Count - 1].y > 21)
            {
                MakeObstacle();
            }
            if (right[right.Count - 1].y > 21)
            {
                MakeObstacle();
            }
            if (middle[middle.Count - 1].y > 21)
            {
                MakeObstacle();
            }

            if (aKeyDown == true)
            {
                hero.Move(heroSpeed, false);
            }
            if (dKeyDown == true)
            {
                hero.Move(heroSpeed, true);
            }
            if (wKeyDown == true && hero.y >= 0)
            {
                hero.Move2(heroSpeed, false);
            }
            if (sKeyDown == true && hero.y + 50 <= this.Height)
            {
                hero.Move2(heroSpeed, true);
            }

            if (counter > 200)
            {
                waitLabel.Visible = false;
            }

            Rectangle heroRec = new Rectangle(hero.x, hero.y, hero.size, hero.size);

            if (left.Count >= 4)
            {
                for (int i = 0; i < left.Count(); i++)
                {
                    Rectangle obstacleRec       = new Rectangle(left[i].x, left[i].y, left[i].size, left[i].size);
                    Rectangle rightobstacleRec  = new Rectangle(right[i].x, right[i].y, right[i].size, right[i].size);
                    Rectangle middleobstacleRec = new Rectangle(middle[i].x, middle[i].y, middle[i].size, middle[i].size);
                    Rectangle objectiveRec      = new Rectangle(835, 250, objectiveSize, objectiveSize);

                    if (obstacleRec.IntersectsWith(heroRec) || rightobstacleRec.IntersectsWith(heroRec) || middleobstacleRec.IntersectsWith(heroRec))
                    {
                        gameLoop.Enabled = false;

                        lossLabel.Text = "YOU LOSE";
                        lossSound.Play();
                        lossCount = lossCount + 1;

                        Refresh();
                        Thread.Sleep(1000);

                        Form f = this.FindForm();
                        f.Controls.Remove(this);

                        MainScreen ss = new MainScreen();
                        f.Controls.Add(ss);
                        ss.Focus();
                    }
                    else if (objectiveRec.IntersectsWith(heroRec))
                    {
                        gameLoop.Stop();
                        victorylabel.Text = "YOU WIN";
                        victorySound.Play();

                        Refresh();
                        Thread.Sleep(3000);

                        Form f = this.FindForm();
                        f.Controls.Remove(this);

                        MainScreen ss = new MainScreen();
                        f.Controls.Add(ss);
                        ss.Focus();
                        return;
                    }
                }
            }

            Refresh();
        }