Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,29 @@ class _OddOneOutGameState extends State<OddOneOutGame> {
}

void _generateRound() {
List<int> nums = [];
Set<int> numsSet = {};
_oddIndex = _rand.nextInt(3);

for (int i = 0; i < 3; i++) {
if (i == _oddIndex) {
// Not multiple of 4
// Generate a non-multiple of 4 that isn't already in set
int n;
do {
n = _rand.nextInt(50) + 1;
} while (n % 4 == 0);
nums.add(n);
} while (n % 4 == 0 || numsSet.contains(n));
numsSet.add(n);
} else {
// Multiple of 4
int n = (_rand.nextInt(12) + 1) * 4;
nums.add(n);
// Generate a multiple of 4 that isn't already in set
int n;
do {
n = (_rand.nextInt(12) + 1) * 4;
} while (numsSet.contains(n));
numsSet.add(n);
}
}

setState(() {
_numbers = nums;
_numbers = numsSet.toList();
});
}

Expand All @@ -79,7 +82,10 @@ class _OddOneOutGameState extends State<OddOneOutGame> {
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(_rule, style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold)),
Text(
_rule,
style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold),
),
SizedBox(height: 20),
for (int i = 0; i < _numbers.length; i++)
Padding(
Expand All @@ -97,4 +103,4 @@ class _OddOneOutGameState extends State<OddOneOutGame> {
),
);
}
}
}