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) { Widget _subGameDialog(int subGame) {
return Dialog( return Dialog(
child: Padding( child: Padding(
@ -58,13 +61,33 @@ class _SuperGameState extends State<SuperGame> {
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
Text( Padding(
padding: const EdgeInsets.only(bottom: 5),
child: Text(
"${Util.stateText(turn)} select cell", "${Util.stateText(turn)} select cell",
style: const TextStyle(fontWeight: FontWeight.bold), style: const TextStyle(fontWeight: FontWeight.bold),
), ),
),
TTCGame( TTCGame(
turn: turn, turn: turn,
cellOnTapCallback: (int i) { 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; nextPlay = i;
setState(() { setState(() {
data[subGame][i] = turn; data[subGame][i] = turn;
@ -74,7 +97,9 @@ class _SuperGameState extends State<SuperGame> {
}, },
data: data[subGame], data: data[subGame],
), ),
Row( Padding(
padding: const EdgeInsets.only(top: 5),
child: Row(
mainAxisAlignment: MainAxisAlignment.end, mainAxisAlignment: MainAxisAlignment.end,
children: [ children: [
ElevatedButton( ElevatedButton(
@ -84,6 +109,7 @@ class _SuperGameState extends State<SuperGame> {
child: const Text("Close")) child: const Text("Close"))
], ],
), ),
),
], ],
), ),
), ),