private void buttonJugar_Click(object sender, EventArgs e) { string nombreusuario = textBoxNombreUsuario.Text; Usuario nuevousuario = new Usuario(nombreusuario); nuevoregistro.AgregarUsuario(nuevousuario); textBoxUsuario.AppendText(nombreusuario); panel2.BringToFront(); pictureBox33.Image = Image.FromFile("C:pacman-right.png"); }
private void timer1_Tick(object sender, EventArgs e) { labelScore.Text = "Score: " + score.ToString(); if (goleft == true) { pictureBoxPacman.Left -= speed; } if (goright == true) { pictureBoxPacman.Left += speed; } if (goup == true) { pictureBoxPacman.Top -= speed; } if (godown == true) { pictureBoxPacman.Top += speed; } //Random r = new Random(); //int x2 = r.Next(0, 502); //int y = r.Next(0, 474); //int x1 = r.Next(0, 502); //int y2 = r.Next(0, 474); //pictureBoxPink.Left = x2; //pictureBoxPink.Top = y; //pictureBoxRed.Left = x1; //pictureBoxRed.Top = y2; pictureBoxPink.Top -= ghost1y; pictureBoxRed.Top -= ghost2y; pictureBoxPink.Left -= ghost1x; pictureBoxRed.Left -= ghost2x; foreach (Control x in this.Controls) { if (x is PictureBox && x.Tag.ToString() == "ghost") { if (((PictureBox)x).Bounds.IntersectsWith(pictureBoxPacman.Bounds) || score == 30) { pictureBoxPacman.Left = 0; pictureBoxPacman.Top = 25; labelGameO.Visible = true; string nombre = textBoxNombreUsuario.Text; Usuario user = new Usuario(nombre, score); nuevoregistro.AgregarUsuario(user); timer1.Stop(); } } if (x is PictureBox && x.Tag.ToString() == "fruit") { //checking if the player hits the points picturebox then we can add to the score if (((PictureBox)x).Bounds.IntersectsWith(pictureBoxPacman.Bounds)) { this.Controls.Remove(x); score += 15; } } } if (pictureBoxPink.Left < 1 || pictureBoxPink.Left + pictureBoxPink.Width > ClientSize.Width - 2) { ghost1x = -ghost1x; } if (pictureBoxPink.Top < 1 || pictureBoxPink.Top + pictureBoxPink.Height > ClientSize.Height - 2) { ghost1y = -ghost1y; } if (pictureBoxRed.Left < 1 || pictureBoxRed.Left + pictureBoxRed.Width > ClientSize.Width - 2) { ghost2x = -ghost2x; } if (pictureBoxRed.Top < 1 || pictureBoxRed.Top + pictureBoxRed.Height > ClientSize.Height - 2) { ghost2y = -ghost2y; } }