rendering update
This commit is contained in:
parent
5c334577bf
commit
e9362706a1
|
|
@ -23,8 +23,8 @@ class _ClassicGameState extends State<ClassicGame> {
|
||||||
TTCState.empty,
|
TTCState.empty,
|
||||||
TTCState.empty,
|
TTCState.empty,
|
||||||
];
|
];
|
||||||
bool ended = false;
|
TTCState get winner => Util.checkWin(data);
|
||||||
TTCState? winner;
|
bool get ended => winner != TTCState.empty;
|
||||||
|
|
||||||
String get turnText => switch (turn) {
|
String get turnText => switch (turn) {
|
||||||
TTCState.empty => "",
|
TTCState.empty => "",
|
||||||
|
|
@ -32,13 +32,7 @@ class _ClassicGameState extends State<ClassicGame> {
|
||||||
TTCState.o => "O",
|
TTCState.o => "O",
|
||||||
};
|
};
|
||||||
|
|
||||||
void _nextTurn() {
|
void _nextTurn() => turn = Util.nextTurn(turn);
|
||||||
turn = switch (turn) {
|
|
||||||
TTCState.x => TTCState.o,
|
|
||||||
TTCState.o => TTCState.x,
|
|
||||||
_ => TTCState.x
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _invalidChoiceAlert(TTCState existingValue) {
|
Widget _invalidChoiceAlert(TTCState existingValue) {
|
||||||
return Dialog(
|
return Dialog(
|
||||||
|
|
@ -52,7 +46,7 @@ class _ClassicGameState extends State<ClassicGame> {
|
||||||
"INVALID CHOICE",
|
"INVALID CHOICE",
|
||||||
style: TextStyle(fontWeight: FontWeight.bold),
|
style: TextStyle(fontWeight: FontWeight.bold),
|
||||||
),
|
),
|
||||||
Text("${existingValue.name.toUpperCase()} already claimed that"),
|
Text("${Util.stateText(existingValue)} already claimed that"),
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () => Navigator.pop(context),
|
onPressed: () => Navigator.pop(context),
|
||||||
child: const Text("Ok")),
|
child: const Text("Ok")),
|
||||||
|
|
@ -80,10 +74,6 @@ class _ClassicGameState extends State<ClassicGame> {
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
data[index] = turn;
|
data[index] = turn;
|
||||||
winner = Util.checkWin(data);
|
|
||||||
if (winner != null && winner != TTCState.empty) {
|
|
||||||
ended = true;
|
|
||||||
}
|
|
||||||
_nextTurn();
|
_nextTurn();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -103,7 +93,7 @@ class _ClassicGameState extends State<ClassicGame> {
|
||||||
"GAME OVER",
|
"GAME OVER",
|
||||||
style: TextStyle(fontWeight: FontWeight.bold),
|
style: TextStyle(fontWeight: FontWeight.bold),
|
||||||
),
|
),
|
||||||
Text("${winner?.name.toUpperCase()} has already won"),
|
Text("${Util.stateText(winner)} has already won"),
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () => Navigator.pop(context),
|
onPressed: () => Navigator.pop(context),
|
||||||
child: const Text("Ok")),
|
child: const Text("Ok")),
|
||||||
|
|
@ -122,7 +112,7 @@ class _ClassicGameState extends State<ClassicGame> {
|
||||||
const Spacer(flex: 5),
|
const Spacer(flex: 5),
|
||||||
Center(
|
Center(
|
||||||
child: Text(
|
child: Text(
|
||||||
!ended ? "$turnText's turn" : "${winner?.name.toUpperCase()} wins",
|
!ended ? "$turnText's turn" : "${Util.stateText(winner)} wins",
|
||||||
style: const TextStyle(fontSize: 30, fontWeight: FontWeight.bold),
|
style: const TextStyle(fontSize: 30, fontWeight: FontWeight.bold),
|
||||||
)),
|
)),
|
||||||
const Spacer(flex: 1),
|
const Spacer(flex: 1),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue