Compare commits

..

2 Commits

Author SHA1 Message Date
Andrei Stoica 25483be0ae invalid choice dialog 2024-12-27 22:22:40 -05:00
Andrei Stoica dbd492969a valid choice 2024-12-27 21:32:06 -05:00
1 changed files with 38 additions and 12 deletions

View File

@ -51,6 +51,9 @@ class _SuperGameState extends State<SuperGame> {
}
}
bool _checkValidChoice(List<TTCState> game, int index) =>
game[index] == TTCState.empty;
Widget _subGameDialog(int subGame) {
return Dialog(
child: Padding(
@ -58,13 +61,33 @@ class _SuperGameState extends State<SuperGame> {
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
Padding(
padding: const EdgeInsets.only(bottom: 5),
child: Text(
"${Util.stateText(turn)} select cell",
style: const TextStyle(fontWeight: FontWeight.bold),
),
),
TTCGame(
turn: turn,
cellOnTapCallback: (int i) {
if (!_checkValidChoice(data[subGame], i)) {
showDialog(
context: context,
builder: (context) => AlertDialog(
content:
Text("${data[subGame][i].name.toUpperCase()}"
" already claimed "
"[${i % 3}, ${(i / 3).floor()}]"),
actions: [
ElevatedButton(
onPressed: () => Navigator.pop(context),
child: const Text("Close"))
],
));
return;
}
nextPlay = i;
setState(() {
data[subGame][i] = turn;
@ -74,7 +97,9 @@ class _SuperGameState extends State<SuperGame> {
},
data: data[subGame],
),
Row(
Padding(
padding: const EdgeInsets.only(top: 5),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
ElevatedButton(
@ -84,6 +109,7 @@ class _SuperGameState extends State<SuperGame> {
child: const Text("Close"))
],
),
),
],
),
),