Added century practice

This commit is contained in:
BroodjeAap 2020-11-03 20:27:17 +01:00
parent b6e4ab0ae8
commit 29a9441e1d
4 changed files with 103 additions and 7 deletions

View file

@ -1,6 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:ohthatsa/pages/practice/PracticeSetup.dart'; import 'package:ohthatsa/pages/practice/PracticeSetup.dart';
import 'package:ohthatsa/pages/practice/PracticeThing.dart'; import 'package:ohthatsa/pages/practice/PracticeThing.dart';
import 'package:ohthatsa/pages/practice/PracticeThingCentury.dart';
import 'package:ohthatsa/pages/practice/PracticeThingMonth.dart'; import 'package:ohthatsa/pages/practice/PracticeThingMonth.dart';
import 'package:ohthatsa/AppDrawer.dart'; import 'package:ohthatsa/AppDrawer.dart';
import 'package:ohthatsa/pages/practice/PracticeType.dart'; import 'package:ohthatsa/pages/practice/PracticeType.dart';
@ -34,6 +35,10 @@ class _PracticeState extends State<PracticePage> {
this.practiceThing = PracticeThingMonth(); this.practiceThing = PracticeThingMonth();
break; break;
} }
case (PracticeType.century): {
this.practiceThing = PracticeThingCentury();
break;
}
default: { default: {
// //
} }

View file

@ -90,10 +90,16 @@ class _PracticeSetupState extends State<PracticeSetupPage> {
TableRow( TableRow(
children: <Widget>[ children: <Widget>[
FlatButton( FlatButton(
child: Text("Year"), child: Text("Century"),
color: Colors.blue, color: Colors.blue,
textColor: Colors.white, textColor: Colors.white,
onPressed: () {}, onPressed: () {
Navigator.pushNamed(
context,
'/practice/practice',
arguments: PracticeSetup(_count, _showCorrect, PracticeType.century)
);
},
), ),
Text("80%", textAlign: TextAlign.center, style: TextStyle(fontSize: 25)), Text("80%", textAlign: TextAlign.center, style: TextStyle(fontSize: 25)),
Text("70%", textAlign: TextAlign.center, style: TextStyle(fontSize: 25)), Text("70%", textAlign: TextAlign.center, style: TextStyle(fontSize: 25)),

View file

@ -0,0 +1,85 @@
import 'dart:ui';
import 'package:flutter/material.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 PracticeThingCentury extends PracticeThing {
int current;
PracticeThingCentury(){
next();
}
@override
bool answer(int answer) {
answers.add(PracticeAnswer(current, answer, PracticeType.month));
final correctAnswer = DayCalculator.getCenturyValue(current);
return answer == correctAnswer;
}
@override
void next() {
current = 1700 + random.nextInt(500);
}
List<bool> getBoolAnswers(){
return answers.map((answer) =>
answer.answer == DayCalculator.getCenturyValue(answer.question)
).toList();
}
Text getAppBarTitleText(){
return Text("Practicing Centuries");
}
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.getCenturyValue(answer.question);
text = answer.question.toString() + (showCorrect ? ": $correctAnswer" : "");
if(answer.answer == 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.getCenturyValue(answer.question);
text = answer.question.toString() + (showCorrect ? ": $correctAnswer" : "");
if(answer.answer == correctAnswer){
color = Colors.green;
}
}
return Text(
text,
style: TextStyle(
fontSize: 10,
color: color
)
);
}
}

View file

@ -72,11 +72,11 @@ class PracticeThingMonth extends PracticeThing {
} }
} }
return Text( return Text(
text, text,
style: TextStyle( style: TextStyle(
fontSize: 10, fontSize: 10,
color: color color: color
) )
); );
} }
} }