Made the question 'system' more generic
This commit is contained in:
parent
edf2556752
commit
5bde7ee9c2
3 changed files with 36 additions and 6 deletions
5
lib/pages/practice/PracticeGenerator.dart
Normal file
5
lib/pages/practice/PracticeGenerator.dart
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
abstract class PracticeGenerator {
|
||||||
|
bool check(int other);
|
||||||
|
void next();
|
||||||
|
String toString();
|
||||||
|
}
|
24
lib/pages/practice/month/MonthPracticeGenerator.dart
Normal file
24
lib/pages/practice/month/MonthPracticeGenerator.dart
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
import 'dart:math';
|
||||||
|
|
||||||
|
import 'package:ohthatsa/pages/practice/PracticeGenerator.dart';
|
||||||
|
import 'package:ohthatsa/util/Months.dart';
|
||||||
|
import 'package:ohthatsa/util/Extensions.dart';
|
||||||
|
|
||||||
|
class MonthPracticeGenerator extends PracticeGenerator {
|
||||||
|
final random = Random();
|
||||||
|
Month current;
|
||||||
|
MonthPracticeGenerator(){
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
bool check(int value){
|
||||||
|
return current.value == value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void next(){
|
||||||
|
current = Months.getFromInt(random.nextInt(Months.length));
|
||||||
|
}
|
||||||
|
|
||||||
|
String toString(){
|
||||||
|
return current.toString().capitalize();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,6 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:ohthatsa/pages/practice/PracticeGenerator.dart';
|
||||||
|
import 'package:ohthatsa/pages/practice/month/MonthPracticeGenerator.dart';
|
||||||
import 'file:///D:/dev/projects/ohthatsa/lib/pages/practice/PracticeSetup.dart';
|
import 'file:///D:/dev/projects/ohthatsa/lib/pages/practice/PracticeSetup.dart';
|
||||||
import 'package:ohthatsa/util/DayCalculator.dart';
|
import 'package:ohthatsa/util/DayCalculator.dart';
|
||||||
import 'package:ohthatsa/AppDrawer.dart';
|
import 'package:ohthatsa/AppDrawer.dart';
|
||||||
|
@ -19,8 +21,7 @@ class _MonthPracticeState extends State<MonthPracticePage> {
|
||||||
int _correct = 0;
|
int _correct = 0;
|
||||||
int _incorrect = 0;
|
int _incorrect = 0;
|
||||||
bool _showCorrect = true;
|
bool _showCorrect = true;
|
||||||
static final _random = Random();
|
static final practiceGenerator = MonthPracticeGenerator();
|
||||||
Month _month = Months.getFromInt(_random.nextInt(Months.length));
|
|
||||||
List<MonthPracticeAnswer> answers = List<MonthPracticeAnswer>();
|
List<MonthPracticeAnswer> answers = List<MonthPracticeAnswer>();
|
||||||
|
|
||||||
Widget getAnswerRow(){
|
Widget getAnswerRow(){
|
||||||
|
@ -114,7 +115,7 @@ class _MonthPracticeState extends State<MonthPracticePage> {
|
||||||
}
|
}
|
||||||
questions.add(
|
questions.add(
|
||||||
Text(
|
Text(
|
||||||
_month.string.capitalize(),
|
practiceGenerator.toString(),
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 30,
|
fontSize: 30,
|
||||||
)
|
)
|
||||||
|
@ -251,15 +252,15 @@ class _MonthPracticeState extends State<MonthPracticePage> {
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkMonth(int answer){
|
void checkMonth(int answer){
|
||||||
if(answer == _month.value){
|
if(practiceGenerator.check(answer)){
|
||||||
_correct += 1;
|
_correct += 1;
|
||||||
} else {
|
} else {
|
||||||
_incorrect += 1;
|
_incorrect += 1;
|
||||||
}
|
}
|
||||||
_count += 1;
|
_count += 1;
|
||||||
answers.add(MonthPracticeAnswer(_month, answer));
|
answers.add(MonthPracticeAnswer(practiceGenerator.current, answer));
|
||||||
setState(() => {
|
setState(() => {
|
||||||
_month = Months.getFromInt(_random.nextInt(Months.length))
|
practiceGenerator.next()
|
||||||
});
|
});
|
||||||
if((_startCount - _count) == 0) {
|
if((_startCount - _count) == 0) {
|
||||||
showDialog(
|
showDialog(
|
||||||
|
|
Loading…
Add table
Reference in a new issue