private void approveButton_Clicked(object sender, EventArgs e) { Button currentButton = ((Button)sender); int buttonRow = -1; int.TryParse(currentButton.Name.Substring(1, currentButton.Name.Length - 1), out buttonRow); for (int i = 0; i < k_numberOfGuessesPerChance; i++) { buttons[i + (k_numberOfGuessesPerChance + 1) * buttonRow].Enabled = false; currentRowGuessed[i] = false; if (buttonRow != (boardCurrentNumberOfChances - 1)) { buttons[i + (k_numberOfGuessesPerChance + 1) * (buttonRow + 1)].Enabled = true; } } for (int i = 0; i < k_numberOfGuessesPerChance; i++) { UserGuess.Add(buttons[i + ((k_numberOfGuessesPerChance + 1) * buttonRow)].BackColor.Name); } numberOfCurrentRowGuesses = 0; currentButton.Enabled = false; BCGame.checkTheGuess(m_chancesLeft, UserGuess, m_codeToGuess); m_chancesLeft--; for (int i = 0; i < BCGame.Bulls; i++) { guessAnswerButtons[i + k_numberOfGuessesPerChance * buttonRow].BackColor = Color.Black; } for (int i = BCGame.Bulls; i < k_numberOfGuessesPerChance; i++) { if (BCGame.Cows > 0) { guessAnswerButtons[i + k_numberOfGuessesPerChance * buttonRow].BackColor = Color.Yellow; BCGame.Cows--; } } flag = BCGame.isGameWon(BCGame.CurrentChance); if (flag) { DialogResult restartGame = MessageBox.Show("Congruts, You won the game!" + Environment.NewLine + "Do you want to play again?", "Game Won", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (restartGame == DialogResult.Yes) { this.m_isYesClicked[0] = true; CloseAllWindows(this.AllWindows); //restartTheGame.RunGame(); } else if (restartGame == DialogResult.No) { Environment.Exit(0); } } if ((m_chancesLeft == 0) && (!flag)) { codeToGuessString = BCGame.ConvertTheCodeToString(m_codeToGuess); ShowResult(); DialogResult restartGame = MessageBox.Show("Bad luck, Try again next time" + Environment.NewLine + "The code is:" + codeToGuessString + Environment.NewLine + "Do you want to play again?", "Game Lose", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (restartGame == DialogResult.Yes) { this.m_isYesClicked[0] = true; CloseAllWindows(this.AllWindows); //restartTheGame.RunGame(); } else if (restartGame == DialogResult.No) { Environment.Exit(0); } } BCGame.ClearResult(UserGuess); }