Example #1
0
        public void Blocks(PictureBox moveBlock)
        {
            //Top Collision
            if (player.Left + player.Width > moveBlock.Left && player.Left + player.Width < moveBlock.Left + moveBlock.Width + player.Width && player.Top + player.Height >= moveBlock.Top && player.Top < moveBlock.Top)
            {
                jump       = false;
                force      = 0;
                player.Top = moveBlock.Location.Y - player.Height;
            }

            //Head Collision
            if (player.Left + player.Width > moveBlock.Left && player.Left + player.Width < moveBlock.Left + moveBlock.Width + player.Width && player.Top - moveBlock.Bottom <= 10 && player.Top - moveBlock.Top > -10)
            {
                jump       = true;
                force      = 0;
                player.Top = moveBlock.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) || player.Bounds.IntersectsWith(barrel4.Bounds) || player.Bounds.IntersectsWith(barrel5.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(princess.Bounds))
            {
                if (gameover == false)
                {
                    audioContext.vic.Play();
                    gameover = true;
                    connection.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\mydatabase.mdb";
                    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();
                        Level3 lvl3 = new Level3();
                        lvl3.ShowDialog();
                    }
                    else
                    {
                        this.Close();
                    }
                }
            }
        }
Example #2
0
        private void btnLvl3_Click(object sender, EventArgs e)
        {
            Level3 lvl3 = new Level3();

            lvl3.ShowDialog();
        }