This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Player{ | |
String playerHandle; | |
List<int> playerMoves =[]; | |
Player({this.playerHandle}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
class GameBtn{ | |
final int id; | |
String text; | |
Color bg; | |
bool enabled; | |
GameBtn({this.id, this.text="", this.bg = Colors.grey, this.enabled=true}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
//TODO import GameBtn class | |
//TODO import Player class | |
class GamePage extends StatefulWidget { | |
@override | |
_GamePageState createState() => _GamePageState(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:easy_tic_tac_toe/pages/game_page.dart'; | |
class WelcomePage extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Material( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:easy_tic_tac_toe/pages/welcome.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
// This widget is the root of your application. | |
@override | |
Widget build(BuildContext context) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<GameBtn> buttonsList; | |
//TODO initialise player and game variables | |
List<GameBtn> generateNewGameBtns(){ | |
var gameButtons = <GameBtn>[ | |
GameBtn(id:0), | |
GameBtn(id:1), | |
GameBtn(id:2), | |
GameBtn(id:3), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
appBar: AppBar( | |
title: Text("Tic Tac Toe"), | |
), | |
body: Column( | |
mainAxisAlignment: MainAxisAlignment.start, | |
crossAxisAlignment: CrossAxisAlignment.stretch, | |
children: <Widget>[ | |
Expanded( | |
child: GridView.builder( | |
padding: const EdgeInsets.all(10.0), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void play(int gameBtnId){ | |
if( gameOver ){ | |
return; | |
} | |
setState((){ | |
if( activePlayer.playerHandle == "playerOne" ){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool playerWon(List<int> playerMoves){ | |
bool won = false; | |
// first line horizontal | |
if(playerMoves.contains(0) && playerMoves.contains(1) && playerMoves.contains(2)){ | |
return won = true; | |
} | |
// second line horizontal | |
if(playerMoves.contains(3) && playerMoves.contains(4) && playerMoves.contains(5)){ | |
return won = true; | |
} |