protected (Question[], WrongAnswers[]) GenerateQuestionTables() { Question[] q = new Question[50]; WrongAnswers[] wa = new WrongAnswers[50]; for (int i = 0; i < 50; i++) { int r = new Random().Next(1, 6); WrongAnswers tempWa = new WrongAnswers { Id = i + 1, Question1 = "Question" + (i + 1), Answer1 = "Answer" + (i + 1) + "_1", Answer2 = "Answer" + (i + 1) + "_2", Answer3 = "Answer" + (i + 1) + "_3" }; wa[i] = tempWa; q[i] = new Question { Id = i + 1, Question1 = "Question" + (i + 1), WrongAns = tempWa, CorrectAnswer = "Correct Answer" + (i + 1), Difficulty = r, IsDeleted = false }; } return(q, wa); }
//Das eigentliche Exam private void Exam() { //Array für bereits verwendete karten usedCards = new bool[5][]; usedCards[0] = new bool[Collections[0].Count]; usedCards[1] = new bool[Collections[1].Count]; usedCards[2] = new bool[Collections[2].Count]; usedCards[3] = new bool[Collections[3].Count]; usedCards[4] = new bool[Collections[4].Count]; int initialCardAmount = CardAmount; //Diese For-Schleife wird aml die vom nutzer eingestellte Anzahl an Karten ausgeführt for (int i = 0; i < CardAmount; i++) { if (i == 0) { //Zu bebegin des Exams Halbe Sekunde Pause, damit der Nutzer sich kurz auf die Frage einstellen kann Thread.Sleep(500); } ProgressString = "Frage " + (i + 1) + " von " + CardAmount; QuestionProgress = 0; stopTask = false; //Dieser Thread stoppt die Zeit progressThread = new Thread(new ThreadStart(() => startTime(this.time))); GetNextCard(); //Neue Karte wird geholt progressThread.Start(); Question = currentCard.Front.Text; progressThread.Join(); //Warten bis die Zeit abgelaufen ist (oder bis die Frage korrekt beantwortet wurde) ExamProgress = 100f / CardAmount * (i + 1); if (!stopTask) { //Wurde die Frage nicht richtig beantwortet, wird Sie der WrongAnswerCollection hinzugefügt dispatcher.Invoke(() => WrongAnswers.Add(currentCard)); } else { BoxColor = "Green"; stopTask = false; } Thread.Sleep(500); //Pause Nach einer Frage Answer = ""; BoxColor = "White"; } CanStop = false; VisabilityExamUi = "Hidden"; QuestionProgress = 0; ExamProgress = 0; EnableSettings = true; CanStart = true; ExamStarted = false; ProgressString = ""; Question = ""; Statistics(initialCardAmount); }
// Die Methode startet die Prüfung, wird nach klick auf "start" ausgeführt private void StartExam() { VisabilityStatUi = "Hidden"; WrongAnswers.Clear(); SelectedWrongQuestion = ""; SelectedWrongAnswer = ""; ExamStarted = true; VisabilityExamUi = "Visable"; EnableSettings = false; CanStart = false; CanStop = true; //Hier wird der Thread gestartet, auf dem das Exam läuft examThread = new Thread(new ThreadStart(() => Exam())); examThread.Start(); }
public async Task <bool> UpdateQuestion(Models.Question question) { var currentQuestion = await _quizManagerContext.Questions.Include(x => x.CorrectAnswer) .Include(y => y.WrongAnswers) .ThenInclude(z => z.Answers) .FirstOrDefaultAsync(q => q.Id == question.Id); if (currentQuestion != null) { currentQuestion.QuestionString = question.QuestionText; currentQuestion.CorrectAnswer = new Answer { AnswerText = question.CorrectAnswer }; var newWrongAnswers = new WrongAnswers { Answers = new List <Answer>() }; foreach (var answer in question.WrongAnswers) { var newWrongAnswer = new Answer { AnswerText = answer }; newWrongAnswers.Answers.Add(newWrongAnswer); } currentQuestion.WrongAnswers = newWrongAnswers; try { await _quizManagerContext.SaveChangesAsync(); return(true); } catch (Exception) { return(false); } } return(false); }