diff --git a/lib/pages/practice/PracticeAnswer.dart b/lib/pages/practice/PracticeAnswer.dart index 018a7a1..ad9b9e9 100644 --- a/lib/pages/practice/PracticeAnswer.dart +++ b/lib/pages/practice/PracticeAnswer.dart @@ -6,10 +6,11 @@ import 'package:ohthatsa/util/Months.dart'; class PracticeAnswer { final int question; final int answer; + final bool correct; DateTime dateTime; int sessionId = -1; - PracticeAnswer(this.question, this.answer){ + PracticeAnswer(this.question, this.answer, this.correct){ dateTime = DateTime.now(); } @@ -19,6 +20,7 @@ class PracticeAnswer { return { "question": question, "answer": answer, + "correct": correct, "time": timeFormat, "sessionId": sessionId }; diff --git a/lib/pages/practice/PracticeThing.dart b/lib/pages/practice/PracticeThing.dart index b6814de..df996df 100644 --- a/lib/pages/practice/PracticeThing.dart +++ b/lib/pages/practice/PracticeThing.dart @@ -8,6 +8,7 @@ abstract class PracticeThing { final random = Random(); final List answers = new List(); + bool isCorrect(int answer); bool answer(int answer); void next(); List getBoolAnswers(); diff --git a/lib/pages/practice/PracticeThingCentury.dart b/lib/pages/practice/PracticeThingCentury.dart index 37dc785..af0d095 100644 --- a/lib/pages/practice/PracticeThingCentury.dart +++ b/lib/pages/practice/PracticeThingCentury.dart @@ -14,12 +14,18 @@ class PracticeThingCentury extends PracticeThing { } @override - bool answer(int answer) { - answers.add(PracticeAnswer(current, answer)); + bool isCorrect(int answer){ final correctAnswer = DayCalculator.getCenturyValue(current); return answer == correctAnswer; } + @override + bool answer(int answer) { + bool isCorrect = this.isCorrect(answer); + answers.add(PracticeAnswer(current, answer, isCorrect)); + return isCorrect; + } + @override void next() { current = 1700 + random.nextInt(500); @@ -27,7 +33,7 @@ class PracticeThingCentury extends PracticeThing { List getBoolAnswers(){ return answers.map((answer) => - answer.answer == DayCalculator.getCenturyValue(answer.question) + answer.correct ).toList(); } @@ -51,7 +57,7 @@ class PracticeThingCentury extends PracticeThing { final answer = answers[answers.length - 1]; final correctAnswer = DayCalculator.getCenturyValue(answer.question); text = answer.question.toString() + (showCorrect ? ": $correctAnswer" : ""); - if(answer.answer == correctAnswer){ + if(answer.correct){ color = Colors.green; } } @@ -70,7 +76,7 @@ class PracticeThingCentury extends PracticeThing { final answer = answers[answers.length - 2]; final correctAnswer = DayCalculator.getCenturyValue(answer.question); text = answer.question.toString() + (showCorrect ? ": $correctAnswer" : ""); - if(answer.answer == correctAnswer){ + if(answer.correct){ color = Colors.green; } } diff --git a/lib/pages/practice/PracticeThingLeap.dart b/lib/pages/practice/PracticeThingLeap.dart index f160b84..30ae380 100644 --- a/lib/pages/practice/PracticeThingLeap.dart +++ b/lib/pages/practice/PracticeThingLeap.dart @@ -13,12 +13,18 @@ class PracticeThingLeap extends PracticeThing { } @override - bool answer(int answer) { - answers.add(PracticeAnswer(current, answer)); + bool isCorrect(int answer){ final correctAnswer = DayCalculator.isLeapYear(current); return (answer != 0) == correctAnswer; } + @override + bool answer(int answer) { + final isCorrect = this.isCorrect(answer); + answers.add(PracticeAnswer(current, answer, isCorrect)); + return isCorrect; + } + @override void next() { current = random.nextInt(10000); @@ -26,7 +32,7 @@ class PracticeThingLeap extends PracticeThing { List getBoolAnswers(){ return answers.map((answer) => - (answer.answer != 0) == DayCalculator.isLeapYear(answer.question) + answer.correct ).toList(); } @@ -50,7 +56,7 @@ class PracticeThingLeap extends PracticeThing { final answer = answers[answers.length - 1]; final correctAnswer = DayCalculator.isLeapYear(answer.question); text = answer.question.toString() + (showCorrect ? ": $correctAnswer" : ""); - if((answer.answer != 0) == correctAnswer){ + if(answer.correct){ color = Colors.green; } } @@ -69,7 +75,7 @@ class PracticeThingLeap extends PracticeThing { final answer = answers[answers.length - 2]; final correctAnswer = DayCalculator.isLeapYear(answer.question); text = answer.question.toString() + (showCorrect ? ": $correctAnswer" : ""); - if((answer.answer != 0) == correctAnswer){ + if(answer.correct){ color = Colors.green; } } diff --git a/lib/pages/practice/PracticeThingMod.dart b/lib/pages/practice/PracticeThingMod.dart index 61f7402..06468f5 100644 --- a/lib/pages/practice/PracticeThingMod.dart +++ b/lib/pages/practice/PracticeThingMod.dart @@ -11,12 +11,18 @@ class PracticeThingMod extends PracticeThing { } @override - bool answer(int answer) { - answers.add(PracticeAnswer(current, answer)); + bool isCorrect(int answer){ final correctAnswer = current % 7; return answer == correctAnswer; } + @override + bool answer(int answer) { + final isCorrect = this.isCorrect(answer); + answers.add(PracticeAnswer(current, answer, isCorrect)); + return isCorrect; + } + @override void next() { current = random.nextInt(141); @@ -30,7 +36,7 @@ class PracticeThingMod extends PracticeThing { @override List getBoolAnswers() { return answers.map((answer) => - answer.question % 7 == answer.answer + answer.correct ).toList(); } @@ -50,7 +56,7 @@ class PracticeThingMod extends PracticeThing { final answer = answers[answers.length - 1]; final correctAnswer = answer.question % 7; text = answer.question.toString() + (showCorrect ? ": $correctAnswer" : ""); - if(answer.answer == correctAnswer){ + if(answer.correct){ color = Colors.green; } } @@ -69,7 +75,7 @@ class PracticeThingMod extends PracticeThing { final answer = answers[answers.length - 2]; final correctAnswer = answer.question % 7; text = answer.question.toString() + (showCorrect ? ": $correctAnswer" : ""); - if(answer.answer == correctAnswer){ + if(answer.correct){ color = Colors.green; } } diff --git a/lib/pages/practice/PracticeThingMonth.dart b/lib/pages/practice/PracticeThingMonth.dart index 7317df8..372c7eb 100644 --- a/lib/pages/practice/PracticeThingMonth.dart +++ b/lib/pages/practice/PracticeThingMonth.dart @@ -13,10 +13,18 @@ class PracticeThingMonth extends PracticeThing { PracticeThingMonth(){ next(); } + + @override + bool isCorrect(int answer){ + return current.value == answer; + } + + @override bool answer(int answer) { - answers.add(PracticeAnswer(current.i, answer)); - return current.value == answer; + final isCorrect = this.isCorrect(answer); + answers.add(PracticeAnswer(current.i, answer, isCorrect)); + return isCorrect; } @override @@ -25,7 +33,9 @@ class PracticeThingMonth extends PracticeThing { } List getBoolAnswers(){ - return answers.map((answer) => Months.getFromInt(answer.question).value == answer.answer).toList(); + return answers.map( + (answer) => answer.correct + ).toList(); } Text getAppBarTitleText(){ @@ -48,7 +58,7 @@ class PracticeThingMonth extends PracticeThing { final answer = answers[answers.length - 1]; final month = Months.getFromInt(answer.question); text = month.toString() + (showCorrect ? ": ${month.value}" : ""); - if(month.value == answer.answer){ + if(answer.correct){ color = Colors.green; } } @@ -67,7 +77,7 @@ class PracticeThingMonth extends PracticeThing { final answer = answers[answers.length - 2]; final month = Months.getFromInt(answer.question); text = month.toString() + (showCorrect ? ": ${month.value}" : ""); - if(month.value == answer.answer){ + if(answer.correct){ color = Colors.green; } }