private void button8_Click(object sender, EventArgs e) { bool boolTryAgain = false; do { string sTextFromUser = PopUpBox.GetUserInput("Enter Your Name Below:", "Congratulation"); if (sTextFromUser == "") { DialogResult dialogResult = MessageBox.Show("You did not enter anything. Try again?", "Error", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { boolTryAgain = true; //will reopen the dialog for user to input text again } else if (dialogResult == DialogResult.No) { //exit/cancel MessageBox.Show("operation cancelled"); boolTryAgain = false; }//end if } else { if (sTextFromUser == "cancel") { MessageBox.Show("operation cancelled"); } else { MessageBox.Show("Here is the text you entered: '" + sTextFromUser + "'"); //do something here with the user input } } } while (boolTryAgain == true); }
private void button_A1_Click(object sender, EventArgs e) { //check answer if (label_AnswerHolder.Text == "1") { richTextBox_Result.AppendText("QUESTION : CORRECT," + '\t' + "TIME TAKEN: "); numericUpDownCorrect.Value = numericUpDownCorrect.Value + 1; } else { richTextBox_Result.AppendText("QUESTION : INCORRECT," + '\t' + "TIME TAKEN: "); } double timeTaken = 1; timeTaken = Convert.ToDouble(sw.ElapsedMilliseconds.ToString()); timeTaken = Math.Round(timeTaken / 1000, 3); richTextBox_Result.AppendText(timeTaken.ToString("0.00") + " s" + '\r' + '\n'); numericUpDownMaxQuestion.Value = numericUpDownMaxQuestion.Value - 1; //Conclude or new question if (numericUpDownMaxQuestion.Value > 0) { int textWord = random.Next(1, 11); int textColor = random.Next(1, 11); int textX = random.Next(1, 11); while (previousColor == textColor || previousWord == textWord) { textColor = random.Next(1, 11); textWord = random.Next(1, 11); } while (textX == textColor) { textX = random.Next(1, 11); } previousColor = textColor; previousWord = textWord; int answerIndex = random.Next(1, 3); if (checkBox_codeSwitch.Checked) { codeSwitchQuestion(textWord, textColor, answerIndex, textX); } else { stroopTestQuestion(textWord, textColor, answerIndex, textX); } } else { tabControl1.SelectTab(2); numericUpDownMaxQuestion.Value = 20; sw.Stop(); sw.Reset(); richTextBox_Result.AppendText("=============================================================================" + '\r' + '\n'); if (checkBoxEasy.Checked) { labelMode.Text = "Difficulty: EASY"; } else if (checkBox_codeSwitch.Checked) { labelMode.Text = "Difficulty: CODE SWITCHING"; } else { labelMode.Text = "Difficulty: NORMAL"; } // Calculate Average Time richTextBoxCumulative.Text = timeTaken.ToString("0.00") + "/20"; DataTable dt = new DataTable(); var result = dt.Compute(richTextBoxCumulative.Text, ""); labelEva.Text = result.ToString(); double incorrectAns = Convert.ToDouble(numericUpDownMaxQuestion.Value - numericUpDownCorrect.Value); double correctAns = Convert.ToDouble(numericUpDownCorrect.Value); labelIncorrect.Text = incorrectAns.ToString(); if (incorrectAns >= 6 && timeTaken < 6) { incorrectAns = incorrectAns * 10; } else { incorrectAns = incorrectAns * 0.5; } if (incorrectAns <= 0) { incorrectAns = 0.3; } richTextBoxScoreCount.Text = numericUpDownCorrect.Value + "/" + incorrectAns + "/" + labelEva.Text; var resultScore = dt.Compute(richTextBoxScoreCount.Text, ""); labelScore.Text = resultScore.ToString(); labelAccuracy.Text = "Accuracy: " + correctAns / 20 * 100 + " %"; labelSpeed.Text = "Average Speed: " + labelEva.Text + " seconds"; double tempScore = Convert.ToDouble(labelScore.Text); labelResultScore.Text = "Score: " + tempScore.ToString("0.00"); if (tempScore < 1) { pictureBoxScore.Image = Image.FromFile("Pics\\E.png"); } else if (6 > tempScore && tempScore >= 1) { pictureBoxScore.Image = Image.FromFile("Pics\\D.png"); } else if (15 > tempScore && tempScore >= 6) { pictureBoxScore.Image = Image.FromFile("Pics\\C.png"); } else if (35 > tempScore && tempScore >= 15) { pictureBoxScore.Image = Image.FromFile("Pics\\B.png"); } else if (50 > tempScore && tempScore >= 35) { pictureBoxScore.Image = Image.FromFile("Pics\\A.png"); } else { pictureBoxScore.Image = Image.FromFile("Pics\\S.png"); } double previousHS = Convert.ToDouble(labelSCOREFILE.Text); double currentHS = tempScore; string sTextFromUser = "******"; if (currentHS > previousHS && !checkBoxEasy.Checked && !checkBox_codeSwitch.Checked) { bool boolTryAgain = false; do { sTextFromUser = PopUpBox.GetUserInput("Enter Your Name Below:", "Congratulation"); if (sTextFromUser == "") { sTextFromUser = "******"; } else { if (sTextFromUser == "cancel") { sTextFromUser = "******"; } } } while (boolTryAgain == true); StreamWriter sw = new StreamWriter("Score\\2Name.txt"); sw.WriteLine(sTextFromUser); sw.Close(); labelSCOREHOLDER.Text = sTextFromUser; labelHolder.Text = "RECORD HOLDER: " + sTextFromUser; StreamWriter sw2 = new StreamWriter("Score\\2Score.txt"); sw2.WriteLine(tempScore.ToString("0.00")); sw2.Close(); labelSCOREFILE.Text = tempScore.ToString("0.00"); labelHS.Text = "HIGH SCORE: " + tempScore.ToString("0.00"); } } }