From 9d2b636d7d108b488f5464a8b5b64450ccc2ca84 Mon Sep 17 00:00:00 2001 From: BroodjeAap Date: Sat, 21 Nov 2020 16:52:03 +0100 Subject: [PATCH] working year practice thing --- lib/pages/practice/PracticePage.dart | 5 ++ lib/pages/practice/PracticeSetupPage.dart | 1 + lib/pages/practice/PracticeType.dart | 1 + .../practice/thing/PracticeThingYear.dart | 89 +++++++++++++++++++ 4 files changed, 96 insertions(+) create mode 100644 lib/pages/practice/thing/PracticeThingYear.dart diff --git a/lib/pages/practice/PracticePage.dart b/lib/pages/practice/PracticePage.dart index 9adbb8c..8bdd56f 100644 --- a/lib/pages/practice/PracticePage.dart +++ b/lib/pages/practice/PracticePage.dart @@ -9,6 +9,7 @@ import 'package:ohthatsa/pages/practice/thing/PracticeThingMod.dart'; import 'package:ohthatsa/pages/practice/thing/PracticeThingMonth.dart'; import 'package:ohthatsa/AppDrawer.dart'; import 'package:ohthatsa/pages/practice/PracticeType.dart'; +import 'package:ohthatsa/pages/practice/thing/PracticeThingYear.dart'; import 'package:ohthatsa/util/Extensions.dart'; import 'package:sqflite/sqflite.dart'; @@ -42,6 +43,10 @@ class _PracticeState extends State { this.practiceThing = PracticeThingMonth(); break; } + case (PracticeType.year): { + this.practiceThing = PracticeThingYear(); + break; + } case (PracticeType.century): { this.practiceThing = PracticeThingCentury(); break; diff --git a/lib/pages/practice/PracticeSetupPage.dart b/lib/pages/practice/PracticeSetupPage.dart index 9b13fa0..273de32 100644 --- a/lib/pages/practice/PracticeSetupPage.dart +++ b/lib/pages/practice/PracticeSetupPage.dart @@ -122,6 +122,7 @@ class _PracticeSetupState extends State { ] ), getStatTableRow(snapshot, PracticeType.month), + getStatTableRow(snapshot, PracticeType.year), getStatTableRow(snapshot, PracticeType.century), getStatTableRow(snapshot, PracticeType.leap), getStatTableRow(snapshot, PracticeType.mod), diff --git a/lib/pages/practice/PracticeType.dart b/lib/pages/practice/PracticeType.dart index c197909..c54dfc6 100644 --- a/lib/pages/practice/PracticeType.dart +++ b/lib/pages/practice/PracticeType.dart @@ -1,5 +1,6 @@ enum PracticeType { month, + year, century, leap, mod, diff --git a/lib/pages/practice/thing/PracticeThingYear.dart b/lib/pages/practice/thing/PracticeThingYear.dart new file mode 100644 index 0000000..89cce3e --- /dev/null +++ b/lib/pages/practice/thing/PracticeThingYear.dart @@ -0,0 +1,89 @@ +import 'package:flutter/material.dart'; +import 'package:ohthatsa/pages/practice/PracticeAnswer.dart'; +import 'package:ohthatsa/pages/practice/thing/PracticeThing.dart'; +import 'package:ohthatsa/util/DayCalculator.dart'; + +class PracticeThingYear extends PracticeThing { + int current; + + PracticeThingYear() { + next(); + } + + @override + bool isCorrect(int answer){ + final correctAnswer = DayCalculator.getYearValue(current); + 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 = 1700 + random.nextInt(500); + } + + List getBoolAnswers() { + return answers.map((answer) => + answer.correct + ).toList(); + } + + Text getAppBarTitleText() { + return Text("Practicing Years"); + } + + Text getCurrentQuestionText(){ + return Text( + current.toString(), + style: TextStyle( + fontSize: 30 + ) + ); + } + + Text getLastAnswerText(bool showCorrect){ + String text = "-"; + Color color = Colors.red; + if(answers.length >= 1){ + final answer = answers[answers.length - 1]; + final correctAnswer = DayCalculator.getYearValue(answer.question); + text = answer.question.toString() + (showCorrect ? ": $correctAnswer" : ""); + if(answer.correct){ + color = Colors.green; + } + } + return Text( + text, + style: TextStyle( + fontSize: 15, + color: color + ) + ); + } + + Text getSecondLastAnswerText(bool showCorrect){ + String text = "-"; + Color color = Colors.red; + if(answers.length >= 2){ + final answer = answers[answers.length - 2]; + final correctAnswer = DayCalculator.getYearValue(answer.question); + text = answer.question.toString() + (showCorrect ? ": $correctAnswer" : ""); + if(answer.correct){ + color = Colors.green; + } + } + return Text( + text, + style: TextStyle( + fontSize: 10, + color: color + ) + ); + } +} \ No newline at end of file