Exemplo n.º 1
0
        private void btnLvl2_Click(object sender, EventArgs e)
        {
            Level2 lvl2 = new Level2();

            lvl2.ShowDialog();
        }
Exemplo n.º 2
0
        public void Blocks(PictureBox block)
        {
            //Top Collision
            if (player.Left + player.Width > block.Left && player.Left + player.Width < block.Left + block.Width + player.Width && player.Top + player.Height >= block.Top && player.Top < block.Top)
            {
                jump       = false;
                force      = 0;
                player.Top = block.Location.Y - player.Height;
            }

            //Head Collision
            if (player.Left + player.Width > block.Left && player.Left + player.Width < block.Left + block.Width + player.Width && player.Top - block.Bottom <= 10 && player.Top - block.Top > -10)
            {
                jump       = false;
                force      = 0;
                player.Top = block.Location.Y + player.Height;
            }
            OleDbConnection connection = new OleDbConnection();

            connection.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\mydatabase.mdb";

            if (player.Bounds.IntersectsWith(barrel.Bounds) || player.Bounds.IntersectsWith(barrel1.Bounds) || player.Bounds.IntersectsWith(barrel2.Bounds) || player.Bounds.IntersectsWith(barrel3.Bounds))
            {
                if (gameover == false)
                {
                    audioContext.die.Play();
                    gameover          = true;
                    ChooseLevel.score = 0;
                    connection.Open();
                    OleDbCommand comm = new OleDbCommand();
                    comm.Connection  = connection;
                    comm.CommandText = "insert into data values('" + EnterName.playername + "','" + Math.Ceiling(ChooseLevel.score) + "')";
                    comm.ExecuteNonQuery();
                    connection.Close();
                    if (MessageBox.Show("Do you want to play again?", "Game Over", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        this.Close();
                    }
                    else
                    {
                        Application.Exit();
                    }
                }
            }
            if (player.Bounds.IntersectsWith(pictureBox6.Bounds))
            {
                if (gameover == false)
                {
                    audioContext.vic.Play();
                    gameover = true;
                    connection.Open();
                    OleDbCommand comm = new OleDbCommand();
                    comm.Connection  = connection;
                    comm.CommandText = "insert into data values('" + EnterName.playername + "','" + Math.Ceiling(ChooseLevel.score) + "')";
                    comm.ExecuteNonQuery();
                    connection.Close();
                    if (MessageBox.Show("Congratulations! Score: " + Math.Ceiling(ChooseLevel.score) + " Move to next level?", "Winner!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        this.Close();
                        Level2 lvl2 = new Level2();
                        lvl2.ShowDialog();
                    }
                    else
                    {
                        this.Close();
                    }
                }
            }
        }