public QuizPractise(Quiz quiz, QuizPractiseMode quizPractiseMode) { InitializeComponent(); Quiz = quiz; PractiseMode = quizPractiseMode; WindowState = Program.frmDashboard.WindowState; if (WindowState == FormWindowState.Normal) { Size = Program.frmDashboard.Size; } Location = new Point(Program.frmDashboard.Location.X + (Program.frmDashboard.Size.Width / 2) - (this.Size.Width / 2), Program.frmDashboard.Location.Y + (Program.frmDashboard.Size.Height / 2) - (this.Size.Height / 2)); lbl_cardQuestionSideType.Text = Quiz.ProgressData.AnswerCardSide == CardSide.Front ? Quiz.CardBackType : Quiz.CardFrontType; lbl_cardAnswerSideType.Text = Quiz.ProgressData.AnswerCardSide == CardSide.Front ? Quiz.CardFrontType : Quiz.CardBackType; this.Text = $"{Path.GetFileNameWithoutExtension(Quiz.QuizIdentity.FindQuizPath())} - SteelQuiz"; if (MetaData.PRE_RELEASE) { this.Text += $" v{Application.ProductVersion} PRE-RELEASE"; } if (Quiz.ProgressData.FullTestInProgress) { lbl_intelligentLearning.Text = "Intelligent Learning: Disabled"; } else { lbl_intelligentLearning.Text = "Intelligent Learning: Enabled"; } SetTheme(GeneralTheme); if ((CurrentCard = CardPicker.GenerateCard(Quiz)) == null) { // Initiate new round if it hasn't previously been done - for instance if this quiz has never been practised before by the user. CardPicker.NewRound(Quiz); } SetCard(); }
private void InQuiz_KeyPress(object sender, KeyPressEventArgs e) { if (PractiseMode != QuizPractiseMode.Writing) { return; } if (e.KeyChar == '\u001b') { // ignore ESC return; } if (e.KeyChar == '\b') { // BACKSPACE if (!newCardPending && !newRoundPending && CurrentInput.Length > 0) { CurrentInput = CurrentInput.Remove(CurrentInput.Length - 1); } } else if (e.KeyChar == '\r') { // ENTER e.Handled = true; foreach (var c in lbl_cardSideToAsk.Controls.OfType <CorrectAnswer>()) { lbl_cardSideToAsk.Controls.Remove(c); c.Dispose(); } foreach (var c in lbl_cardSideToAsk.Controls.OfType <WrongAnswer>()) { lbl_cardSideToAsk.Controls.Remove(c); c.Dispose(); } foreach (var c in lbl_cardSideToAsk.Controls.OfType <RoundCompleted>()) { lbl_cardSideToAsk.Controls.Remove(c); c.Dispose(); } if (newRoundPending) { SetCard(); return; } if (newCardPending) { SetCard(); return; } // Check answer var chk = CurrentCard.WrittenAnswerCheck(Quiz, CurrentInput, CurrentCard.MultiAnswersAlreadyEntered(Quiz), !userCopyingAnswer); if (chk.IsCorrect()) { newCardPending = true; llb_overrideIwasRight.Visible = false; var correctAnswer = new CorrectAnswer(CurrentCard, Quiz, chk.Certainty); lbl_cardSideToAsk.Controls.Add(correctAnswer); correctAnswer.Show(); CurrentCard = CardPicker.GenerateCard(Quiz); // Generate new card now so that it will be shown on next instance if the user stops practising now lbl_cardSideToAnswer.Text = CurrentInput; } else { llb_overrideIwasRight.Visible = true; userCopyingAnswer = true; var wrongAnswer = new WrongAnswer(CurrentCard, Quiz); lbl_cardSideToAsk.Controls.Add(wrongAnswer); wrongAnswer.Show(); // Check if the user answered another card var answeredCards = new List <Card>(); foreach (var card in Quiz.Cards) { var testCheck = card.WrittenAnswerCheck(Quiz, CurrentInput, null, false, false); if (testCheck.IsCorrect()) { answeredCards.Add(card); } } if (answeredCards.Count > 0) { MessageBox.Show($"Your answer is wrong to the current card, but correct to other(s):\r\n\r\n" + string.Join("\r\n", answeredCards.Select(x => x.GetSideToAsk(Quiz))), "You answered other card(s)", MessageBoxButtons.OK, MessageBoxIcon.Information); } CurrentInput = ""; } } else if (!newCardPending && !newRoundPending) { if (cardSideAnswerPromptBeingShown) { lbl_cardSideToAnswer.Text = ""; cardSideAnswerPromptBeingShown = false; } CurrentInput += e.KeyChar; } }
/// <summary> /// Generates a card to be shown - or shows the last one from the previous session if it hadn't been answered. /// </summary> public void SetCard() { newRoundPending = false; newCardPending = false; userCopyingAnswer = false; foreach (var c in lbl_cardSideToAsk.Controls.OfType <CorrectAnswer>()) { lbl_cardSideToAsk.Controls.Remove(c); c.Dispose(); } foreach (var c in lbl_cardSideToAsk.Controls.OfType <WrongAnswer>()) { lbl_cardSideToAsk.Controls.Remove(c); c.Dispose(); } foreach (var c in lbl_cardSideToAsk.Controls.OfType <RoundCompleted>()) { lbl_cardSideToAsk.Controls.Remove(c); c.Dispose(); } foreach (var c in lbl_cardSideToAnswer.Controls.OfType <MultiAnswer>()) { lbl_cardSideToAnswer.Controls.Remove(c); c.Dispose(); } llb_overrideIwasRight.Visible = false; pnl_knewAnswer.Visible = false; CurrentInput = ""; CurrentCard = CardPicker.GenerateCard(Quiz); if (CurrentCard == null) { // Round completed var roundCompleted = new RoundCompleted(Quiz, PractiseMode, this); lbl_cardSideToAsk.Controls.Add(roundCompleted); roundCompleted.Show(); CardPicker.NewRound(Quiz); lbl_cardSideToAnswer.Text = ""; newRoundPending = true; return; } if (PractiseMode == QuizPractiseMode.Writing) { if (!IsCurrentCardMultiAnswer()) { lbl_cardSideToAnswer.Text = "Enter your answer ..."; } else { // Multi Answer Card var multiAns = new MultiAnswer(); lbl_cardSideToAnswer.Text = ""; foreach (var card in CurrentCard.MultiAnswersAlreadyEntered(Quiz)) { multiAns.CurrentLabel.Text = card.GetSideToAnswer(Quiz); multiAns.CurrentLabel.Clone(); } multiAns.CurrentLabel.Text = "Enter your answers ..."; lbl_cardSideToAnswer.Controls.Add(multiAns); } } else { lbl_cardSideToAnswer.Text = "Click here to reveal"; } cardSideAnswerPromptBeingShown = true; if (Quiz.ProgressData.GetLearningProgress() == 1.0) { if (!Quiz.ProgressData.MasterNoticeShowed) { MessageBox.Show("Congratulations! It seems you have learned the whole quiz! Practise until you feel confident - then start a full test, through the " + "quiz config menu, by clicking the gear button in the bottom right corner", "Quiz Mastered!", MessageBoxButtons.OK, MessageBoxIcon.Information); Quiz.ProgressData.MasterNoticeShowed = true; } } }