super wip
This commit is contained in:
parent
c2a37ab464
commit
79bf2b015d
|
|
@ -6,8 +6,8 @@ class TTCGame extends StatelessWidget {
|
||||||
const TTCGame({
|
const TTCGame({
|
||||||
super.key,
|
super.key,
|
||||||
required this.turn,
|
required this.turn,
|
||||||
required this.cellOnTapCallback,
|
|
||||||
required this.data,
|
required this.data,
|
||||||
|
this.cellOnTapCallback,
|
||||||
this.cellTextStyle,
|
this.cellTextStyle,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -18,7 +18,7 @@ class TTCGame extends StatelessWidget {
|
||||||
final TextStyle? cellTextStyle;
|
final TextStyle? cellTextStyle;
|
||||||
|
|
||||||
/// hook into end of turn cycle;
|
/// hook into end of turn cycle;
|
||||||
final Function cellOnTapCallback;
|
final void Function(int)? cellOnTapCallback;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|
@ -39,7 +39,7 @@ class GameHash extends StatelessWidget {
|
||||||
const GameHash({super.key, required this.children, this.cellOnTapCallback});
|
const GameHash({super.key, required this.children, this.cellOnTapCallback});
|
||||||
final List<Widget> children;
|
final List<Widget> children;
|
||||||
|
|
||||||
final Function? cellOnTapCallback;
|
final void Function(int)? cellOnTapCallback;
|
||||||
|
|
||||||
Border _genCellBorder(
|
Border _genCellBorder(
|
||||||
int index, {
|
int index, {
|
||||||
|
|
@ -93,6 +93,8 @@ class HashCell extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) => InkWell(
|
Widget build(BuildContext context) => InkWell(
|
||||||
onTap: stateSetCallback,
|
onTap: stateSetCallback,
|
||||||
child: Center(child: child),
|
child: IgnorePointer(
|
||||||
|
child: Center(child: child),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'clasic.dart';
|
import 'package:super_tic_tac_toe/super.dart';
|
||||||
|
import 'classic.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(const MyApp());
|
runApp(const MyApp());
|
||||||
|
|
@ -75,7 +76,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||||
padding: const EdgeInsets.all(10),
|
padding: const EdgeInsets.all(10),
|
||||||
child: type == GameType.classicTTC
|
child: type == GameType.classicTTC
|
||||||
? const ClassicGame()
|
? const ClassicGame()
|
||||||
: const Center(child: Text("Under Construction")),
|
: const SuperGame(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,142 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:super_tic_tac_toe/game.dart';
|
||||||
|
import 'package:super_tic_tac_toe/state.dart';
|
||||||
|
import 'package:super_tic_tac_toe/util.dart';
|
||||||
|
|
||||||
|
class SuperGame extends StatefulWidget {
|
||||||
|
const SuperGame({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<SuperGame> createState() => _SuperGameState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SuperGameState extends State<SuperGame> {
|
||||||
|
TTCState turn = TTCState.x;
|
||||||
|
List<List<TTCState>> data = Util.emptyBoardSuper;
|
||||||
|
List<bool> subGameEnded = [
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
];
|
||||||
|
|
||||||
|
List<TTCState> subGameWinners = [
|
||||||
|
TTCState.empty,
|
||||||
|
TTCState.empty,
|
||||||
|
TTCState.empty,
|
||||||
|
TTCState.empty,
|
||||||
|
TTCState.empty,
|
||||||
|
TTCState.empty,
|
||||||
|
TTCState.empty,
|
||||||
|
TTCState.empty,
|
||||||
|
TTCState.empty,
|
||||||
|
];
|
||||||
|
int nextPlay = -1;
|
||||||
|
|
||||||
|
void _swapTurn() {
|
||||||
|
switch (turn) {
|
||||||
|
case TTCState.x:
|
||||||
|
turn = TTCState.o;
|
||||||
|
break;
|
||||||
|
case TTCState.o:
|
||||||
|
turn = TTCState.x;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
turn = TTCState.x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _subGameDialog(int subGame) {
|
||||||
|
return Dialog(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(10),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
"${Util.stateText(turn)} select cell",
|
||||||
|
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||||
|
),
|
||||||
|
TTCGame(
|
||||||
|
turn: turn,
|
||||||
|
cellOnTapCallback: (int i) {
|
||||||
|
nextPlay = i;
|
||||||
|
setState(() {
|
||||||
|
data[subGame][i] = turn;
|
||||||
|
_swapTurn();
|
||||||
|
});
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
data: data[subGame],
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
|
children: [
|
||||||
|
ElevatedButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
child: const Text("Close"))
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _showSubGameDialog(int i) {
|
||||||
|
if (nextPlay == i || nextPlay == -1) {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) => _subGameDialog(i),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
ScaffoldMessenger.of(context)
|
||||||
|
..clearSnackBars()
|
||||||
|
..showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(
|
||||||
|
"You can only play at [${(nextPlay % 3) + 1},"
|
||||||
|
"${(nextPlay / 3).floor() + 1}]",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
const Spacer(flex: 5),
|
||||||
|
Center(
|
||||||
|
child: Text(
|
||||||
|
"${Util.stateText(turn)}'s Turn",
|
||||||
|
style: const TextStyle(fontSize: 25),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const Spacer(flex: 1),
|
||||||
|
GameHash(
|
||||||
|
cellOnTapCallback: _showSubGameDialog,
|
||||||
|
children: data
|
||||||
|
.map(
|
||||||
|
(game) => Padding(
|
||||||
|
padding: const EdgeInsets.all(15),
|
||||||
|
child: TTCGame(
|
||||||
|
turn: turn,
|
||||||
|
data: game,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.toList()),
|
||||||
|
const Spacer(flex: 5),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,32 @@
|
||||||
import 'state.dart';
|
import 'state.dart';
|
||||||
|
|
||||||
class Util {
|
class Util {
|
||||||
|
static List<TTCState> get emptyBoardClassic => [
|
||||||
|
TTCState.empty,
|
||||||
|
TTCState.empty,
|
||||||
|
TTCState.empty,
|
||||||
|
TTCState.empty,
|
||||||
|
TTCState.empty,
|
||||||
|
TTCState.empty,
|
||||||
|
TTCState.empty,
|
||||||
|
TTCState.empty,
|
||||||
|
TTCState.empty,
|
||||||
|
];
|
||||||
|
|
||||||
|
static List<List<TTCState>> get emptyBoardSuper => [
|
||||||
|
emptyBoardClassic,
|
||||||
|
emptyBoardClassic,
|
||||||
|
emptyBoardClassic,
|
||||||
|
emptyBoardClassic,
|
||||||
|
emptyBoardClassic,
|
||||||
|
emptyBoardClassic,
|
||||||
|
emptyBoardClassic,
|
||||||
|
emptyBoardClassic,
|
||||||
|
emptyBoardClassic,
|
||||||
|
];
|
||||||
|
|
||||||
|
static String stateText(TTCState state) => state.name.toUpperCase();
|
||||||
|
|
||||||
static Iterable<TTCState> getRow(int index, List<TTCState> data) =>
|
static Iterable<TTCState> getRow(int index, List<TTCState> data) =>
|
||||||
data.getRange(index, index + 3);
|
data.getRange(index, index + 3);
|
||||||
static Iterable<TTCState> getCol(int index, List<TTCState> data) => [
|
static Iterable<TTCState> getCol(int index, List<TTCState> data) => [
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue