private void timerGame_Tick(object sender, EventArgs e) { dateToday = DateTime.Now.ToString("MM/dd/yyyy"); lblScore.Text = "Score: " + Top10Only.AddingCommasInScore(Convert.ToString(score)); lblMissed.Text = "Missed: " + missedEggs; // Chicken will go to left side. if (isGoLeft == true && pbChicken.Left > 0) { pbChicken.Left -= 30; pbChicken.Image = Properties.Resources.chicken_normal2; } // Chicken will go to right side. if (isGoRight == true && pbChicken.Left + pbChicken.Width < this.ClientSize.Width) { pbChicken.Left += 30; pbChicken.Image = Properties.Resources.chicken_normal; } // Using the foreach loop to control every eggs. foreach (Control x in this.Controls) { // Check if there are picturebox that have a tag name of "eggs". if (x is PictureBox && (string)x.Tag == "eggs") { // Add the speed of falling egg. x.Top += speed; // If Egg was dropped in the floor. if (x.Top + x.Height > this.ClientSize.Height) { pictureBox.Image = Properties.Resources.splash; pictureBox.Location = x.Location; pictureBox.Height = 60; pictureBox.Width = 60; pictureBox.BackColor = Color.Transparent; this.Controls.Add(pictureBox); x.Top = randomNumberForYaxis.Next(80, 300) * -1; x.Left = randomNumberForXaxis.Next(5, this.ClientSize.Width - x.Width); missedEggs += 1; pbChicken.Image = Properties.Resources.chicken_hurt; CheckIfAudioMutedOrNot("missed_egg.wav"); } // If Chicken collided of egg. if (pbChicken.Bounds.IntersectsWith(x.Bounds)) { x.Top = randomNumberForYaxis.Next(80, 300) * -1; x.Left = randomNumberForXaxis.Next(5, this.ClientSize.Width - x.Width); score += 1; CheckIfAudioMutedOrNot("saved_egg.wav"); } } } // If the score is greater than 10. if (score > 10) { speed = 12; // then increase the speed. } if (missedEggs >= 10) // If missedEggs is greater than or equal to 10. { GameOver(); // Execute this user defined function called GameOver() } }
private void GameOver() { timerGame.Stop(); lblScore.Text = "Score: " + Top10Only.AddingCommasInScore(Convert.ToString(score)); lblMissed.Text = "Missed: " + missedEggs; Top10Only.CheckResultInTop10Only(dateToday, score); inGameAudio.StopPlaying(); if (Form_Introduction.isAudioOn == true) { gameOverAudio.Play(false); } DialogResult result = MessageBox.Show("Score: " + score + Environment.NewLine + "Missed: " + missedEggs + Environment.NewLine + Environment.NewLine + "Do you want to play again?", "GAME OVER", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (result == DialogResult.Yes) { gameOverAudio.StopPlaying(); StartGame(); } else if (result == DialogResult.No) { gameOverAudio.StopPlaying(); this.Hide(); Form_Introduction nextForm = new Form_Introduction(); nextForm.ShowDialog(); } }
public static void CheckResultInTop10Only(string param_Date, int param_Score) { if (Top10Only.CheckingIfScoreIsAcceptable(param_Score)) { Top10OnlyEntry entry = new Top10OnlyEntry(); entry.Date = param_Date; entry.Score = param_Score; Top10Only.EnterTop10Only(entry); } }
private void Form_HighScores_Load(object sender, EventArgs e) { CheckIfAudioMutedOrNot(); Top10Only.Show(this.lblRankHeaderAndContent, this.lblDateHeaderAndContent, this.lblScoreHeaderAndContent); }