From 0176a2f333b50f818aaef70589a78edf6d1031af Mon Sep 17 00:00:00 2001 From: BroodjeAap Date: Tue, 3 Nov 2020 20:41:31 +0100 Subject: [PATCH] Added leap year practice TODO change buttons for this? --- lib/pages/practice/PracticePage.dart | 5 ++ lib/pages/practice/PracticeSetupPage.dart | 8 ++- lib/pages/practice/PracticeThingLeap.dart | 84 +++++++++++++++++++++++ lib/pages/practice/PracticeType.dart | 2 +- 4 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 lib/pages/practice/PracticeThingLeap.dart diff --git a/lib/pages/practice/PracticePage.dart b/lib/pages/practice/PracticePage.dart index ca9706b..0c46b40 100644 --- a/lib/pages/practice/PracticePage.dart +++ b/lib/pages/practice/PracticePage.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:ohthatsa/pages/practice/PracticeSetup.dart'; import 'package:ohthatsa/pages/practice/PracticeThing.dart'; import 'package:ohthatsa/pages/practice/PracticeThingCentury.dart'; +import 'package:ohthatsa/pages/practice/PracticeThingLeap.dart'; import 'package:ohthatsa/pages/practice/PracticeThingMonth.dart'; import 'package:ohthatsa/AppDrawer.dart'; import 'package:ohthatsa/pages/practice/PracticeType.dart'; @@ -39,6 +40,10 @@ class _PracticeState extends State { this.practiceThing = PracticeThingCentury(); break; } + case (PracticeType.leap): { + this.practiceThing = PracticeThingLeap(); + break; + } default: { // } diff --git a/lib/pages/practice/PracticeSetupPage.dart b/lib/pages/practice/PracticeSetupPage.dart index a132d07..994699c 100644 --- a/lib/pages/practice/PracticeSetupPage.dart +++ b/lib/pages/practice/PracticeSetupPage.dart @@ -112,7 +112,13 @@ class _PracticeSetupState extends State { child: Text("Leap"), color: Colors.blue, textColor: Colors.white, - onPressed: () {}, + onPressed: () { + Navigator.pushNamed( + context, + '/practice/practice', + arguments: PracticeSetup(_count, _showCorrect, PracticeType.leap) + ); + }, ), Text("80%", textAlign: TextAlign.center, style: TextStyle(fontSize: 25)), Text("70%", textAlign: TextAlign.center, style: TextStyle(fontSize: 25)), diff --git a/lib/pages/practice/PracticeThingLeap.dart b/lib/pages/practice/PracticeThingLeap.dart new file mode 100644 index 0000000..3444516 --- /dev/null +++ b/lib/pages/practice/PracticeThingLeap.dart @@ -0,0 +1,84 @@ +import 'package:flutter/material.dart'; +import 'package:flutter/src/widgets/text.dart'; +import 'package:ohthatsa/pages/practice/PracticeAnswer.dart'; +import 'package:ohthatsa/pages/practice/PracticeThing.dart'; +import 'package:ohthatsa/pages/practice/PracticeType.dart'; +import 'package:ohthatsa/util/DayCalculator.dart'; + +class PracticeThingLeap extends PracticeThing { + int current; + + PracticeThingLeap(){ + next(); + } + + @override + bool answer(int answer) { + answers.add(PracticeAnswer(current, answer, PracticeType.month)); + final correctAnswer = DayCalculator.isLeapYear(current); + return (answer != 0) == correctAnswer; + } + + @override + void next() { + current = random.nextInt(10000); + } + + List getBoolAnswers(){ + return answers.map((answer) => + (answer.answer != 0) == DayCalculator.isLeapYear(answer.question) + ).toList(); + } + + Text getAppBarTitleText(){ + return Text("Practicing Leap 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.isLeapYear(answer.question); + text = answer.question.toString() + (showCorrect ? ": $correctAnswer" : ""); + if((answer.answer != 0) == correctAnswer){ + 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.isLeapYear(answer.question); + text = answer.question.toString() + (showCorrect ? ": $correctAnswer" : ""); + if((answer.answer != 0) == correctAnswer){ + color = Colors.green; + } + } + return Text( + text, + style: TextStyle( + fontSize: 10, + color: color + ) + ); + } +} \ No newline at end of file diff --git a/lib/pages/practice/PracticeType.dart b/lib/pages/practice/PracticeType.dart index 8834081..f115e05 100644 --- a/lib/pages/practice/PracticeType.dart +++ b/lib/pages/practice/PracticeType.dart @@ -1,6 +1,6 @@ enum PracticeType { month, century, - year, + leap, all } \ No newline at end of file