Compare commits
No commits in common. "69a038c84fc9d2cc7a3d8819505b9766581ac402" and "fedfbb3dbc2b849884cbf23145bd4dae464a7345" have entirely different histories.
69a038c84f
...
fedfbb3dbc
|
|
@ -41,8 +41,3 @@ app.*.map.json
|
||||||
/android/app/debug
|
/android/app/debug
|
||||||
/android/app/profile
|
/android/app/profile
|
||||||
/android/app/release
|
/android/app/release
|
||||||
|
|
||||||
# Firebase
|
|
||||||
lib/firebase_options.dart
|
|
||||||
android/app/google-services.json
|
|
||||||
firebase.json
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,5 @@
|
||||||
plugins {
|
plugins {
|
||||||
id "com.android.application"
|
id "com.android.application"
|
||||||
// START: FlutterFire Configuration
|
|
||||||
id 'com.google.gms.google-services'
|
|
||||||
// END: FlutterFire Configuration
|
|
||||||
id "kotlin-android"
|
id "kotlin-android"
|
||||||
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
|
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
|
||||||
id "dev.flutter.flutter-gradle-plugin"
|
id "dev.flutter.flutter-gradle-plugin"
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,6 @@ pluginManagement {
|
||||||
plugins {
|
plugins {
|
||||||
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
|
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
|
||||||
id "com.android.application" version "8.1.0" apply false
|
id "com.android.application" version "8.1.0" apply false
|
||||||
// START: FlutterFire Configuration
|
|
||||||
id "com.google.gms.google-services" version "4.3.15" apply false
|
|
||||||
// END: FlutterFire Configuration
|
|
||||||
id "org.jetbrains.kotlin.android" version "1.8.22" apply false
|
id "org.jetbrains.kotlin.android" version "1.8.22" apply false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,8 @@ class _ClassicGameState extends State<ClassicGame> {
|
||||||
TTCState.empty,
|
TTCState.empty,
|
||||||
TTCState.empty,
|
TTCState.empty,
|
||||||
];
|
];
|
||||||
TTCState get winner => Util.checkWin(data);
|
bool ended = false;
|
||||||
bool get ended => winner != TTCState.empty;
|
TTCState? winner;
|
||||||
|
|
||||||
String get turnText => switch (turn) {
|
String get turnText => switch (turn) {
|
||||||
TTCState.empty => "",
|
TTCState.empty => "",
|
||||||
|
|
@ -32,7 +32,13 @@ class _ClassicGameState extends State<ClassicGame> {
|
||||||
TTCState.o => "O",
|
TTCState.o => "O",
|
||||||
};
|
};
|
||||||
|
|
||||||
void _nextTurn() => turn = Util.nextTurn(turn);
|
void _nextTurn() {
|
||||||
|
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(
|
||||||
|
|
@ -46,7 +52,7 @@ class _ClassicGameState extends State<ClassicGame> {
|
||||||
"INVALID CHOICE",
|
"INVALID CHOICE",
|
||||||
style: TextStyle(fontWeight: FontWeight.bold),
|
style: TextStyle(fontWeight: FontWeight.bold),
|
||||||
),
|
),
|
||||||
Text("${Util.stateText(existingValue)} already claimed that"),
|
Text("${existingValue.name.toUpperCase()} already claimed that"),
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () => Navigator.pop(context),
|
onPressed: () => Navigator.pop(context),
|
||||||
child: const Text("Ok")),
|
child: const Text("Ok")),
|
||||||
|
|
@ -74,6 +80,10 @@ 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();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -93,7 +103,7 @@ class _ClassicGameState extends State<ClassicGame> {
|
||||||
"GAME OVER",
|
"GAME OVER",
|
||||||
style: TextStyle(fontWeight: FontWeight.bold),
|
style: TextStyle(fontWeight: FontWeight.bold),
|
||||||
),
|
),
|
||||||
Text("${Util.stateText(winner)} has already won"),
|
Text("${winner?.name.toUpperCase()} has already won"),
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () => Navigator.pop(context),
|
onPressed: () => Navigator.pop(context),
|
||||||
child: const Text("Ok")),
|
child: const Text("Ok")),
|
||||||
|
|
@ -112,7 +122,7 @@ class _ClassicGameState extends State<ClassicGame> {
|
||||||
const Spacer(flex: 5),
|
const Spacer(flex: 5),
|
||||||
Center(
|
Center(
|
||||||
child: Text(
|
child: Text(
|
||||||
!ended ? "$turnText's turn" : "${Util.stateText(winner)} wins",
|
!ended ? "$turnText's turn" : "${winner?.name.toUpperCase()} 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),
|
||||||
|
|
|
||||||
114
lib/super.dart
114
lib/super.dart
|
|
@ -13,16 +13,47 @@ class SuperGame extends StatefulWidget {
|
||||||
class _SuperGameState extends State<SuperGame> {
|
class _SuperGameState extends State<SuperGame> {
|
||||||
TTCState turn = TTCState.x;
|
TTCState turn = TTCState.x;
|
||||||
List<List<TTCState>> data = Util.emptyBoardSuper;
|
List<List<TTCState>> data = Util.emptyBoardSuper;
|
||||||
|
TTCState winner = TTCState.empty;
|
||||||
TTCState subGameWinner(int index) => Util.checkWin(data[index]);
|
|
||||||
List<TTCState> get subGameWinners => data.map(Util.checkWin).toList();
|
|
||||||
bool subGameEnded(int i) => subGameWinner(i) != TTCState.empty;
|
|
||||||
TTCState get winner => Util.checkWin(subGameWinners);
|
|
||||||
bool gameEnded() => winner != TTCState.empty;
|
bool gameEnded() => winner != TTCState.empty;
|
||||||
|
|
||||||
|
List<TTCState> subGameWinners = [
|
||||||
|
TTCState.empty,
|
||||||
|
TTCState.empty,
|
||||||
|
TTCState.empty,
|
||||||
|
TTCState.empty,
|
||||||
|
TTCState.empty,
|
||||||
|
TTCState.empty,
|
||||||
|
TTCState.empty,
|
||||||
|
TTCState.empty,
|
||||||
|
TTCState.empty,
|
||||||
|
];
|
||||||
|
bool subGameEnded(int i) => subGameWinners[i] != TTCState.empty;
|
||||||
|
|
||||||
int nextPlay = -1;
|
int nextPlay = -1;
|
||||||
|
|
||||||
void _swapTurn() => turn = Util.nextTurn(turn);
|
void _swapTurn() {
|
||||||
|
switch (turn) {
|
||||||
|
case TTCState.x:
|
||||||
|
turn = TTCState.o;
|
||||||
|
break;
|
||||||
|
case TTCState.o:
|
||||||
|
turn = TTCState.x;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
turn = TTCState.x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TTCState _validateSubGame(int index) {
|
||||||
|
subGameWinners[index] = Util.checkWin(data[index]);
|
||||||
|
print("validated $index");
|
||||||
|
return subGameWinners[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
TTCState _validateGame() {
|
||||||
|
winner = Util.checkWin(subGameWinners);
|
||||||
|
return winner;
|
||||||
|
}
|
||||||
|
|
||||||
bool _checkValidChoice(List<TTCState> game, int index) =>
|
bool _checkValidChoice(List<TTCState> game, int index) =>
|
||||||
game[index] == TTCState.empty;
|
game[index] == TTCState.empty;
|
||||||
|
|
@ -47,6 +78,8 @@ class _SuperGameState extends State<SuperGame> {
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
data[subGame][i] = turn;
|
data[subGame][i] = turn;
|
||||||
|
_validateSubGame(subGame);
|
||||||
|
_validateGame();
|
||||||
nextPlay = subGameEnded(i) ? -1 : i;
|
nextPlay = subGameEnded(i) ? -1 : i;
|
||||||
if (!gameEnded()) {
|
if (!gameEnded()) {
|
||||||
_swapTurn();
|
_swapTurn();
|
||||||
|
|
@ -99,7 +132,7 @@ class _SuperGameState extends State<SuperGame> {
|
||||||
..clearSnackBars()
|
..clearSnackBars()
|
||||||
..showSnackBar(
|
..showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
content: Text("${Util.stateText(subGameWinner(index))}"
|
content: Text("${Util.stateText(subGameWinners[index])}"
|
||||||
" already won the game at "
|
" already won the game at "
|
||||||
"[${Util.cellAddress(index)}]"),
|
"[${Util.cellAddress(index)}]"),
|
||||||
),
|
),
|
||||||
|
|
@ -147,50 +180,47 @@ class _SuperGameState extends State<SuperGame> {
|
||||||
_showSubGameDialog(index);
|
_showSubGameDialog(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _turnText() => Text(
|
|
||||||
gameEnded()
|
|
||||||
? "${Util.stateText(winner)} Wins"
|
|
||||||
: "${Util.stateText(turn)}'s Turn",
|
|
||||||
style: const TextStyle(fontSize: 25),
|
|
||||||
);
|
|
||||||
|
|
||||||
Widget _subGmaeWidget(int i) {
|
|
||||||
if (subGameEnded(i)) {
|
|
||||||
return Text(
|
|
||||||
subGameWinner(i).name.toUpperCase(),
|
|
||||||
style: const TextStyle(fontSize: 40),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return TTCGame(turn: turn, data: data[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Widget> _generateCells() => Iterable.generate(data.length)
|
|
||||||
.map(
|
|
||||||
(i) => DecoratedBox(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: nextPlay == i ? Colors.lightGreenAccent : null,
|
|
||||||
),
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(15),
|
|
||||||
child: _subGmaeWidget(i),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.toList();
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
Iterable.generate(subGameWinners.length)
|
||||||
|
.map((i) => subGameEnded(i))
|
||||||
|
.forEach(print);
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
const Spacer(flex: 5),
|
const Spacer(flex: 5),
|
||||||
Center(
|
Center(
|
||||||
child: _turnText(),
|
child: Text(
|
||||||
|
gameEnded()
|
||||||
|
? "${Util.stateText(winner)} Wins"
|
||||||
|
: "${Util.stateText(turn)}'s Turn",
|
||||||
|
style: const TextStyle(fontSize: 25),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
const Spacer(flex: 1),
|
const Spacer(flex: 1),
|
||||||
GameHash(
|
GameHash(
|
||||||
cellOnTapCallback: _cellOnTapCallback,
|
cellOnTapCallback: _cellOnTapCallback,
|
||||||
children: _generateCells(),
|
children: Iterable.generate(data.length)
|
||||||
),
|
.map(
|
||||||
|
(i) => DecoratedBox(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: nextPlay == i ? Colors.lightGreenAccent : null,
|
||||||
|
),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(15),
|
||||||
|
child: !subGameEnded(i)
|
||||||
|
? TTCGame(
|
||||||
|
turn: turn,
|
||||||
|
data: data[i],
|
||||||
|
)
|
||||||
|
: Text(
|
||||||
|
subGameWinners[i].name.toUpperCase(),
|
||||||
|
style: const TextStyle(fontSize: 40),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.toList()),
|
||||||
const Spacer(flex: 5),
|
const Spacer(flex: 5),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -25,18 +25,6 @@ class Util {
|
||||||
emptyBoardClassic,
|
emptyBoardClassic,
|
||||||
];
|
];
|
||||||
|
|
||||||
static TTCState nextTurn(TTCState currentPlayer,
|
|
||||||
{TTCState defaultState = TTCState.x}) {
|
|
||||||
switch (currentPlayer) {
|
|
||||||
case TTCState.x:
|
|
||||||
return TTCState.o;
|
|
||||||
case TTCState.o:
|
|
||||||
return TTCState.x;
|
|
||||||
default:
|
|
||||||
return defaultState;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static String stateText(TTCState state) => state.name.toUpperCase();
|
static String stateText(TTCState state) => state.name.toUpperCase();
|
||||||
static String cellAddress(int index) =>
|
static String cellAddress(int index) =>
|
||||||
"${index % 3}, ${(index / 3).floor()}";
|
"${index % 3}, ${(index / 3).floor()}";
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue