Exemple #1
0
        private void button3_Click(object sender, EventArgs e)
        {
            Form1 form1 = new Form1(2);

            form1.ShowDialog();
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            label1.Text = "Score: " + score;
            if (goleft)
            {
                pacman.Left -= speed;
            }
            if (goright)
            {
                pacman.Left += speed;
            }
            if (goup)
            {
                pacman.Top -= speed;
            }
            if (godown)
            {
                pacman.Top += speed;
            }
            foreach (Control x in this.Controls)
            {
                if (x is PictureBox && x.Tag == "wall" || x.Tag == "ghost")
                {
                    if (((PictureBox)x).Bounds.IntersectsWith(pacman.Bounds))
                    {
                        Record newrecord = new Record(user, score);
                        label2.Text    = "Game Over";
                        label2.Visible = true;
                        timer1.Stop();
                        MessageBox.Show("User: "******". Score: " + score);
                        BaseDeDatos   b1      = new BaseDeDatos();
                        List <Record> records = b1.DesRecords();
                        records.Add(newrecord);
                        List <Record> recList = records.OrderByDescending(rec => rec.score).ToList();
                        string        g       = "-------Tabla historica-------\n";
                        int           lugar   = 1;
                        foreach (Record rec in recList)
                        {
                            g += lugar + ".- User: "******". Su score: " + rec.score + ".\n";
                            lugar++;
                        }
                        MessageBox.Show(g);
                        b1.SerRecords(records);
                        this.Hide();
                        Form1 inicio = new Form1();
                        inicio.ShowDialog();
                    }
                }
                if (x is PictureBox && x.Tag == "fruit")
                {
                    if (((PictureBox)x).Bounds.IntersectsWith(pacman.Bounds))
                    {
                        if (x.Name == "cherry")
                        {
                            x.Left = 357;
                            x.Top  = 7;
                            score += 10;
                        }
                        if (x.Name == "melon")
                        {
                            x.Left = 390;
                            x.Top  = 7;
                            score += 15;
                        }
                    }
                }
            }
            pinkGhost.Left += ghost1x;
            pinkGhost.Top  += ghost1y;
            redGhost.Left  += ghost2x;
            redGhost.Top   += ghost2y;
            if (pinkGhost.Left < 1 || pinkGhost.Left + pinkGhost.Width > ClientSize.Width - 2 || (pinkGhost.Bounds.IntersectsWith(pictureBox1.Bounds)) || (pinkGhost.Bounds.IntersectsWith(pictureBox2.Bounds)) || (pinkGhost.Bounds.IntersectsWith(pictureBox3.Bounds)) || (pinkGhost.Bounds.IntersectsWith(pictureBox4.Bounds)))
            {
                ghost1x = -ghost1x;
            }
            if (pinkGhost.Top < 1 || pinkGhost.Top + pinkGhost.Height > ClientSize.Height - 2 || (pinkGhost.Bounds.IntersectsWith(pictureBox1.Bounds)) || (pinkGhost.Bounds.IntersectsWith(pictureBox2.Bounds)) || (pinkGhost.Bounds.IntersectsWith(pictureBox3.Bounds)) || (pinkGhost.Bounds.IntersectsWith(pictureBox4.Bounds)))
            {
                ghost1y = -ghost1y;
            }

            if (redGhost.Left < 1 || redGhost.Left + redGhost.Width > ClientSize.Width - 2 || (redGhost.Bounds.IntersectsWith(pictureBox1.Bounds)) || (redGhost.Bounds.IntersectsWith(pictureBox2.Bounds)) || (redGhost.Bounds.IntersectsWith(pictureBox3.Bounds)) || (redGhost.Bounds.IntersectsWith(pictureBox4.Bounds)))
            {
                ghost2x = -ghost2x;
            }
            if (redGhost.Top < 1 || redGhost.Top + pinkGhost.Height > ClientSize.Height - 2 || (redGhost.Bounds.IntersectsWith(pictureBox1.Bounds)) || (redGhost.Bounds.IntersectsWith(pictureBox2.Bounds)) || (redGhost.Bounds.IntersectsWith(pictureBox3.Bounds)) || (redGhost.Bounds.IntersectsWith(pictureBox4.Bounds)))
            {
                ghost2y = -ghost2y;
            }
        }
        private void scoresButton_Click(object sender, EventArgs e)
        {
            Form1 form = new Form1(listaScore);

            form.ShowDialog();
        }