Document Android Studio
Document Android Studio
dart’ ;
@override
Return MaterialApp(
Theme : ThemeData(
primarySwatch : Colors.blue,
),
Home : TicTacToeGame(),
);
@override
String _gameStatus = ‘’ ;
setState(() {
_board[index] = _currentPlayer ;
_checkGameStatus() ;
}) ;
Void _checkGameStatus() {
List<List<int>> winningCombinations = [
[0, 1, 2],
[3, 4, 5],
[6, 7, 8],
[0, 3, 6],
[1, 4, 7],
[2, 5, 8],
[0, 4, 8],
[2, 4, 6],
];
_board[combination[0]] != ‘’) {
setState(() {
}) ;
Return ;
If ( !_board.contains(‘’)) {
setState(() {
}) ;
Void _resetGame() {
setState(() {
_currentPlayer = ‘X’ ;
_gameStatus = ‘’ ;
}) ;
@override
appBar : AppBar(
),
Body : Column(
mainAxisAlignment : MainAxisAlignment.center,
children : [
_buildBoard(),
SizedBox(height : 20),
Text(
_gameStatus,
),
SizedBox(height : 20),
ElevatedButton(
onPressed : _resetGame,
),
],
),
);
Widget _buildBoard() {
Return GridView.builder(
shrinkWrap : true,
gridDelegate : SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount : 3,
),
itemCount : 9,
return GestureDetector(
child : Container(
margin : EdgeInsets.all(4.0),
color : Colors.blue[50],
child : Center(
child : Text(
_board[index],
),
),
),
);
},
);