working year practice thing

This commit is contained in:
BroodjeAap 2020-11-21 16:52:03 +01:00
parent 7ffd19c7f1
commit 9d2b636d7d
4 changed files with 96 additions and 0 deletions

View file

@ -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<PracticePage> {
this.practiceThing = PracticeThingMonth();
break;
}
case (PracticeType.year): {
this.practiceThing = PracticeThingYear();
break;
}
case (PracticeType.century): {
this.practiceThing = PracticeThingCentury();
break;

View file

@ -122,6 +122,7 @@ class _PracticeSetupState extends State<PracticeSetupPage> {
]
),
getStatTableRow(snapshot, PracticeType.month),
getStatTableRow(snapshot, PracticeType.year),
getStatTableRow(snapshot, PracticeType.century),
getStatTableRow(snapshot, PracticeType.leap),
getStatTableRow(snapshot, PracticeType.mod),

View file

@ -1,5 +1,6 @@
enum PracticeType {
month,
year,
century,
leap,
mod,

View file

@ -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<bool> 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
)
);
}
}