Skip to content
Snippets Groups Projects
Commit 415f5afe authored by Benoît Harrault's avatar Benoît Harrault
Browse files

Merge branch '18-clean-code' into 'master'

Resolve "Clean code"

Closes #18

See merge request !16
parents 72e4d13d 31da4fea
No related branches found
No related tags found
1 merge request!16Resolve "Clean code"
Pipeline #2933 passed
org.gradle.jvmargs=-Xmx1536M org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true android.useAndroidX=true
android.enableJetifier=true android.enableJetifier=true
app.versionName=1.0.10 app.versionName=1.0.11
app.versionCode=11 app.versionCode=12
...@@ -3,7 +3,7 @@ import 'package:puissance4/coordinate.dart'; ...@@ -3,7 +3,7 @@ import 'package:puissance4/coordinate.dart';
import 'match_page.dart'; import 'match_page.dart';
class Board { class Board {
List<List<Color>> _boxes = List.generate( List<List<Color?>> _boxes = List.generate(
7, 7,
(i) => List.generate( (i) => List.generate(
7, 7,
...@@ -13,33 +13,34 @@ class Board { ...@@ -13,33 +13,34 @@ class Board {
Board(); Board();
Board.from(List<List<Color>> boxes) { Board.from(List<List<Color?>> boxes) {
_boxes = boxes; _boxes = boxes;
} }
Color getBox(Coordinate coordinate) => _boxes[coordinate.col][coordinate.row]; Color? getBox(Coordinate coordinate) =>
_boxes[coordinate.col ?? 0][coordinate.row ?? 0];
int getColumnTarget(int col) => _boxes[col].lastIndexOf(null); int getColumnTarget(int? col) => _boxes[col ?? 0].lastIndexOf(null);
void setBox(Coordinate coordinate, Color player) => void setBox(Coordinate coordinate, Color? player) =>
_boxes[coordinate.col][coordinate.row] = player; _boxes[coordinate.col ?? 0][coordinate.row ?? 0] = player;
void reset() { void reset() {
_boxes.forEach((r) => r.forEach((p) => p = null)); _boxes.forEach((r) => r.forEach((p) => p = null));
} }
bool checkWinner(Coordinate coordinate, Color player) { bool checkWinner(Coordinate coordinate, Color? player) {
return checkHorizontally(coordinate, player) || return checkHorizontally(coordinate, player) ||
checkVertically(coordinate, player) || checkVertically(coordinate, player) ||
checkDiagonally(coordinate, player); checkDiagonally(coordinate, player);
} }
bool checkHorizontally(Coordinate coordinate, Color player) { bool checkHorizontally(Coordinate coordinate, Color? player) {
var r = 0; var r = 0;
for (; for (;
coordinate.col + r < 7 && (coordinate.col ?? 0) + r < 7 &&
r < 4 && r < 4 &&
getBox(coordinate.copyWith(col: coordinate.col + r)) == player; getBox(coordinate.copyWith(col: (coordinate.col ?? 0) + r)) == player;
++r) {} ++r) {}
if (r >= 4) { if (r >= 4) {
return true; return true;
...@@ -47,9 +48,9 @@ class Board { ...@@ -47,9 +48,9 @@ class Board {
var l = 0; var l = 0;
for (; for (;
coordinate.col - l >= 0 && (coordinate.col ?? 0) - l >= 0 &&
l < 4 && l < 4 &&
getBox(coordinate.copyWith(col: coordinate.col - l)) == player; getBox(coordinate.copyWith(col: (coordinate.col ?? 0) - l)) == player;
++l) {} ++l) {}
if (l >= 4 || l + r >= 5) { if (l >= 4 || l + r >= 5) {
return true; return true;
...@@ -58,15 +59,15 @@ class Board { ...@@ -58,15 +59,15 @@ class Board {
return false; return false;
} }
bool checkDiagonally(Coordinate coordinate, Color player) { bool checkDiagonally(Coordinate coordinate, Color? player) {
var ur = 0; var ur = 0;
for (; for (;
coordinate.col + ur < 7 && (coordinate.col ?? 0) + ur < 7 &&
coordinate.row + ur < 7 && (coordinate.row ?? 0) + ur < 7 &&
ur < 4 && ur < 4 &&
getBox(coordinate.copyWith( getBox(coordinate.copyWith(
col: coordinate.col + ur, col: (coordinate.col ?? 0) + ur,
row: coordinate.row + ur, row: (coordinate.row ?? 0) + ur,
)) == )) ==
player; player;
++ur) {} ++ur) {}
...@@ -75,12 +76,12 @@ class Board { ...@@ -75,12 +76,12 @@ class Board {
} }
var dl = 0; var dl = 0;
for (; for (;
coordinate.col - dl >= 0 && (coordinate.col ?? 0) - dl >= 0 &&
coordinate.row - dl >= 0 && (coordinate.row ?? 0) - dl >= 0 &&
dl < 4 && dl < 4 &&
getBox(coordinate.copyWith( getBox(coordinate.copyWith(
col: coordinate.col - dl, col: (coordinate.col ?? 0) - dl,
row: coordinate.row - dl, row: (coordinate.row ?? 0) - dl,
)) == )) ==
player; player;
++dl) {} ++dl) {}
...@@ -90,12 +91,12 @@ class Board { ...@@ -90,12 +91,12 @@ class Board {
var dr = 0; var dr = 0;
for (; for (;
coordinate.col + dr < 7 && (coordinate.col ?? 0) + dr < 7 &&
coordinate.row - dr >= 0 && (coordinate.row ?? 0) - dr >= 0 &&
dr < 4 && dr < 4 &&
getBox(coordinate.copyWith( getBox(coordinate.copyWith(
col: coordinate.col + dr, col: (coordinate.col ?? 0) + dr,
row: coordinate.row - dr, row: (coordinate.row ?? 0) - dr,
)) == )) ==
player; player;
++dr) {} ++dr) {}
...@@ -105,12 +106,12 @@ class Board { ...@@ -105,12 +106,12 @@ class Board {
var ul = 0; var ul = 0;
for (; for (;
coordinate.col - ul >= 0 && (coordinate.col ?? 0) - ul >= 0 &&
coordinate.row + ul < 7 && (coordinate.row ?? 0) + ul < 7 &&
ul < 4 && ul < 4 &&
getBox(coordinate.copyWith( getBox(coordinate.copyWith(
col: coordinate.col - ul, col: (coordinate.col ?? 0) - ul,
row: coordinate.row + ul, row: (coordinate.row ?? 0) + ul,
)) == )) ==
player; player;
++ul) {} ++ul) {}
...@@ -120,13 +121,13 @@ class Board { ...@@ -120,13 +121,13 @@ class Board {
return false; return false;
} }
bool checkVertically(Coordinate coordinate, Color player) { bool checkVertically(Coordinate coordinate, Color? player) {
var u = 0; var u = 0;
for (; for (;
coordinate.row + u < 7 && (coordinate.row ?? 0) + u < 7 &&
u < 4 && u < 4 &&
getBox(coordinate.copyWith( getBox(coordinate.copyWith(
row: coordinate.row + u, row: (coordinate.row ?? 0) + u,
)) == )) ==
player; player;
++u) {} ++u) {}
...@@ -135,10 +136,10 @@ class Board { ...@@ -135,10 +136,10 @@ class Board {
} }
var d = 0; var d = 0;
for (; for (;
coordinate.row - d >= 0 && (coordinate.row ?? 0) - d >= 0 &&
d < 4 && d < 4 &&
getBox(coordinate.copyWith( getBox(coordinate.copyWith(
row: coordinate.row - d, row: (coordinate.row ?? 0) - d,
)) == )) ==
player; player;
++d) {} ++d) {}
......
class Coordinate { class Coordinate {
final int row, col; final int? row, col;
Coordinate( Coordinate(
this.col, this.col,
...@@ -7,8 +7,8 @@ class Coordinate { ...@@ -7,8 +7,8 @@ class Coordinate {
); );
Coordinate copyWith({ Coordinate copyWith({
int col, int? col,
int row, int? row,
}) => }) =>
Coordinate( Coordinate(
col ?? this.col, col ?? this.col,
......
...@@ -37,13 +37,13 @@ class HarderCpu extends Cpu { ...@@ -37,13 +37,13 @@ class HarderCpu extends Cpu {
@override @override
Future<int> chooseCol(Board board) async { Future<int> chooseCol(Board board) async {
final List<double> scores = List.filled(7, 0); final List<double?> scores = List.filled(7, 0.0);
await Future.delayed(Duration(seconds: 1 + _random.nextInt(2))); await Future.delayed(Duration(seconds: 1 + _random.nextInt(2)));
return _compute(board, 0, 1, scores); return _compute(board, 0, 1, scores);
} }
int _compute(Board board, int step, int deepness, List<double> scores) { int _compute(Board board, int step, int deepness, List<double?> scores) {
for (var i = 0; i < 7; ++i) { for (var i = 0; i < 7; ++i) {
final boardCopy = board.clone(); final boardCopy = board.clone();
...@@ -57,7 +57,7 @@ class HarderCpu extends Cpu { ...@@ -57,7 +57,7 @@ class HarderCpu extends Cpu {
boardCopy.setBox(coordinate, color); boardCopy.setBox(coordinate, color);
if (boardCopy.checkWinner(coordinate, color)) { if (boardCopy.checkWinner(coordinate, color)) {
scores[i] += deepness / (step + 1); scores[i] = (scores[i] ?? 0) + deepness / (step + 1);
continue; continue;
} }
...@@ -71,7 +71,7 @@ class HarderCpu extends Cpu { ...@@ -71,7 +71,7 @@ class HarderCpu extends Cpu {
boardCopy.setBox(coordinate, otherPlayer); boardCopy.setBox(coordinate, otherPlayer);
if (boardCopy.checkWinner(coordinate, otherPlayer)) { if (boardCopy.checkWinner(coordinate, otherPlayer)) {
scores[i] -= deepness / (step + 1); scores[i] = (scores[i] ?? 0) - deepness / (step + 1);
continue; continue;
} }
...@@ -84,11 +84,11 @@ class HarderCpu extends Cpu { ...@@ -84,11 +84,11 @@ class HarderCpu extends Cpu {
return _getBestScoreIndex(scores); return _getBestScoreIndex(scores);
} }
int _getBestScoreIndex(List<double> scores) { int _getBestScoreIndex(List<double?> scores) {
int bestScoreIndex = scores.indexWhere((s) => s != null); int bestScoreIndex = scores.indexWhere((s) => s != null);
scores.asMap().forEach((index, score) { scores.asMap().forEach((index, score) {
if (score != null && if (score != null &&
(score > scores[bestScoreIndex] || (score > (scores[bestScoreIndex] ?? 0) ||
(score == scores[bestScoreIndex] && _random.nextBool()))) { (score == scores[bestScoreIndex] && _random.nextBool()))) {
bestScoreIndex = index; bestScoreIndex = index;
} }
...@@ -105,7 +105,7 @@ class HardestCpu extends HarderCpu { ...@@ -105,7 +105,7 @@ class HardestCpu extends HarderCpu {
@override @override
Future<int> chooseCol(Board board) async { Future<int> chooseCol(Board board) async {
final List<double> scores = List.filled(7, 0); final List<double?> scores = List.filled(7, 0);
await Future.delayed(Duration(seconds: 2 + _random.nextInt(2))); await Future.delayed(Duration(seconds: 2 + _random.nextInt(2)));
return _compute(board, 0, 4, scores); return _compute(board, 0, 4, scores);
......
...@@ -19,15 +19,15 @@ class CpuLevelPage extends StatelessWidget { ...@@ -19,15 +19,15 @@ class CpuLevelPage extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max, mainAxisSize: MainAxisSize.max,
children: <Widget>[ children: <Widget>[
FlatButton( TextButton(
color: Colors.yellow, style: TextButton.styleFrom(
backgroundColor: Colors.yellow,
padding: EdgeInsets.all(15), padding: EdgeInsets.all(15),
),
child: Text( child: Text(
'☺️ FACILE', '☺️ FACILE',
style: Theme.of(context) style:
.textTheme Theme.of(context).textTheme.headline4?.copyWith(color: Colors.black),
.headline4
.copyWith(color: Colors.black),
), ),
onPressed: () { onPressed: () {
Navigator.pushNamed( Navigator.pushNamed(
...@@ -35,21 +35,20 @@ class CpuLevelPage extends StatelessWidget { ...@@ -35,21 +35,20 @@ class CpuLevelPage extends StatelessWidget {
'/match', '/match',
arguments: { arguments: {
'mode': Mode.PVC, 'mode': Mode.PVC,
'cpu': 'cpu': DumbCpu(Random().nextBool() ? Color.RED : Color.YELLOW),
DumbCpu(Random().nextBool() ? Color.RED : Color.YELLOW),
}, },
); );
}, },
), ),
FlatButton( TextButton(
color: Colors.red, style: TextButton.styleFrom(
backgroundColor: Colors.red,
padding: EdgeInsets.all(15), padding: EdgeInsets.all(15),
),
child: Text( child: Text(
'🤔 DIFFICILE', '🤔 DIFFICILE',
style: Theme.of(context) style:
.textTheme Theme.of(context).textTheme.headline4?.copyWith(color: Colors.white),
.headline4
.copyWith(color: Colors.white),
), ),
onPressed: () { onPressed: () {
Navigator.pushNamed( Navigator.pushNamed(
...@@ -57,21 +56,20 @@ class CpuLevelPage extends StatelessWidget { ...@@ -57,21 +56,20 @@ class CpuLevelPage extends StatelessWidget {
'/match', '/match',
arguments: { arguments: {
'mode': Mode.PVC, 'mode': Mode.PVC,
'cpu': HarderCpu( 'cpu': HarderCpu(Random().nextBool() ? Color.RED : Color.YELLOW),
Random().nextBool() ? Color.RED : Color.YELLOW),
}, },
); );
}, },
), ),
FlatButton( TextButton(
color: Colors.deepPurpleAccent, style: TextButton.styleFrom(
backgroundColor: Colors.deepPurpleAccent,
padding: EdgeInsets.all(15), padding: EdgeInsets.all(15),
),
child: Text( child: Text(
'🤯 TRES DIFFICILE', '🤯 TRES DIFFICILE',
style: Theme.of(context) style:
.textTheme Theme.of(context).textTheme.headline4?.copyWith(color: Colors.white),
.headline4
.copyWith(color: Colors.white),
), ),
onPressed: () { onPressed: () {
Navigator.pushNamed( Navigator.pushNamed(
...@@ -79,8 +77,7 @@ class CpuLevelPage extends StatelessWidget { ...@@ -79,8 +77,7 @@ class CpuLevelPage extends StatelessWidget {
'/match', '/match',
arguments: { arguments: {
'mode': Mode.PVC, 'mode': Mode.PVC,
'cpu': HardestCpu( 'cpu': HardestCpu(Random().nextBool() ? Color.RED : Color.YELLOW),
Random().nextBool() ? Color.RED : Color.YELLOW),
}, },
); );
}, },
......
...@@ -4,13 +4,13 @@ import 'match_page.dart'; ...@@ -4,13 +4,13 @@ import 'match_page.dart';
class GameChip extends StatelessWidget { class GameChip extends StatelessWidget {
const GameChip({ const GameChip({
Key key, Key? key,
this.translation, this.translation,
@required this.color, this.color,
}) : super(key: key); }) : super(key: key);
final Animation<double> translation; final Animation<double>? translation;
final Color color; final Color? color;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
......
...@@ -16,15 +16,15 @@ class HomePage extends StatelessWidget { ...@@ -16,15 +16,15 @@ class HomePage extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max, mainAxisSize: MainAxisSize.max,
children: <Widget>[ children: <Widget>[
FlatButton( TextButton(
color: Colors.green, style: TextButton.styleFrom(
backgroundColor: Colors.green,
padding: EdgeInsets.all(15), padding: EdgeInsets.all(15),
),
child: Text( child: Text(
'🧑 2 JOUEURS 🧑', '🧑 2 JOUEURS 🧑',
style: Theme.of(context) style:
.textTheme Theme.of(context).textTheme.headline4?.copyWith(color: Colors.white),
.headline4
.copyWith(color: Colors.white),
), ),
onPressed: () { onPressed: () {
Navigator.pushNamed( Navigator.pushNamed(
...@@ -36,15 +36,15 @@ class HomePage extends StatelessWidget { ...@@ -36,15 +36,15 @@ class HomePage extends StatelessWidget {
); );
}, },
), ),
FlatButton( TextButton(
color: Colors.orange, style: TextButton.styleFrom(
backgroundColor: Colors.orange,
padding: EdgeInsets.all(15), padding: EdgeInsets.all(15),
),
child: Text( child: Text(
'🧑 1 JOUEUR 🤖', '🧑 1 JOUEUR 🤖',
style: Theme.of(context) style:
.textTheme Theme.of(context).textTheme.headline4?.copyWith(color: Colors.white),
.headline4
.copyWith(color: Colors.white),
), ),
onPressed: () { onPressed: () {
Navigator.pushNamed( Navigator.pushNamed(
...@@ -56,15 +56,15 @@ class HomePage extends StatelessWidget { ...@@ -56,15 +56,15 @@ class HomePage extends StatelessWidget {
); );
}, },
), ),
FlatButton( TextButton(
color: Colors.white, style: TextButton.styleFrom(
backgroundColor: Colors.white,
padding: EdgeInsets.all(15), padding: EdgeInsets.all(15),
),
child: Text( child: Text(
'🤖 DEMO 🤖', '🤖 DEMO 🤖',
style: Theme.of(context) style:
.textTheme Theme.of(context).textTheme.headline4?.copyWith(color: Colors.black),
.headline4
.copyWith(color: Colors.black),
), ),
onPressed: () { onPressed: () {
final harderCpu = final harderCpu =
......
...@@ -14,7 +14,7 @@ class MyApp extends StatelessWidget { ...@@ -14,7 +14,7 @@ class MyApp extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return MaterialApp(
title: 'Flutter fiar', title: 'Puissance 4',
theme: ThemeData( theme: ThemeData(
primarySwatch: Colors.blue, primarySwatch: Colors.blue,
), ),
......
...@@ -21,14 +21,14 @@ enum Mode { ...@@ -21,14 +21,14 @@ enum Mode {
class MatchPage extends StatefulWidget { class MatchPage extends StatefulWidget {
final Mode mode; final Mode mode;
final Cpu cpu; final Cpu? cpu;
final Cpu cpu2; final Cpu? cpu2;
const MatchPage({ const MatchPage({
Key key, Key? key,
this.mode, required this.mode,
this.cpu, required this.cpu,
this.cpu2, required this.cpu2,
}) : super(key: key); }) : super(key: key);
@override @override
...@@ -37,10 +37,10 @@ class MatchPage extends StatefulWidget { ...@@ -37,10 +37,10 @@ class MatchPage extends StatefulWidget {
class _MatchPageState extends State<MatchPage> with TickerProviderStateMixin { class _MatchPageState extends State<MatchPage> with TickerProviderStateMixin {
final board = Board(); final board = Board();
Color turn; Color? turn;
Color winner; Color? winner;
List<List<Animation<double>>> translations = List.generate( List<List<Animation<double>?>> translations = List.generate(
7, 7,
(i) => List.generate( (i) => List.generate(
7, 7,
...@@ -73,7 +73,6 @@ class _MatchPageState extends State<MatchPage> with TickerProviderStateMixin { ...@@ -73,7 +73,6 @@ class _MatchPageState extends State<MatchPage> with TickerProviderStateMixin {
child: Padding( child: Padding(
padding: const EdgeInsets.only(top: 32.0), padding: const EdgeInsets.only(top: 32.0),
child: Stack( child: Stack(
overflow: Overflow.clip,
fit: StackFit.loose, fit: StackFit.loose,
children: <Widget>[ children: <Widget>[
Positioned.fill( Positioned.fill(
...@@ -99,7 +98,7 @@ class _MatchPageState extends State<MatchPage> with TickerProviderStateMixin { ...@@ -99,7 +98,7 @@ class _MatchPageState extends State<MatchPage> with TickerProviderStateMixin {
style: Theme.of(context) style: Theme.of(context)
.textTheme .textTheme
.headline6 .headline6
.copyWith(color: Colors.white), ?.copyWith(color: Colors.white),
) )
: Column( : Column(
children: <Widget>[ children: <Widget>[
...@@ -109,11 +108,13 @@ class _MatchPageState extends State<MatchPage> with TickerProviderStateMixin { ...@@ -109,11 +108,13 @@ class _MatchPageState extends State<MatchPage> with TickerProviderStateMixin {
style: Theme.of(context) style: Theme.of(context)
.textTheme .textTheme
.headline5 .headline5
.copyWith(color: Colors.white), ?.copyWith(color: Colors.white),
), ),
Padding( Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: GameChip(color: turn), child: GameChip(
color: turn,
),
), ),
_buildPlayerName(context), _buildPlayerName(context),
], ],
...@@ -130,7 +131,7 @@ class _MatchPageState extends State<MatchPage> with TickerProviderStateMixin { ...@@ -130,7 +131,7 @@ class _MatchPageState extends State<MatchPage> with TickerProviderStateMixin {
String name; String name;
if (widget.mode == Mode.PVC) { if (widget.mode == Mode.PVC) {
if (turn == widget.cpu.color) { if (turn == widget.cpu?.color) {
name = 'CPU - ${widget.cpu.toString()}'; name = 'CPU - ${widget.cpu.toString()}';
} else { } else {
name = 'USER'; name = 'USER';
...@@ -142,7 +143,7 @@ class _MatchPageState extends State<MatchPage> with TickerProviderStateMixin { ...@@ -142,7 +143,7 @@ class _MatchPageState extends State<MatchPage> with TickerProviderStateMixin {
name = 'PLAYER2'; name = 'PLAYER2';
} }
} else { } else {
if (turn == widget.cpu.color) { if (turn == widget.cpu?.color) {
name = 'CPU1 - ${widget.cpu.toString()}'; name = 'CPU1 - ${widget.cpu.toString()}';
} else { } else {
name = 'CPU2 - ${widget.cpu2.toString()}'; name = 'CPU2 - ${widget.cpu2.toString()}';
...@@ -151,22 +152,18 @@ class _MatchPageState extends State<MatchPage> with TickerProviderStateMixin { ...@@ -151,22 +152,18 @@ class _MatchPageState extends State<MatchPage> with TickerProviderStateMixin {
return Text( return Text(
name, name,
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: Theme.of(context) style: Theme.of(context).textTheme.headline5?.copyWith(color: Colors.white),
.textTheme
.headline5
.copyWith(color: Colors.white),
); );
} }
@override @override
void initState() { void initState() {
super.initState(); super.initState();
turn = widget.cpu?.otherPlayer ?? turn = Random().nextBool() ? Color.RED : Color.YELLOW;
(Random().nextBool() ? Color.RED : Color.YELLOW); if (widget.mode == Mode.PVC && turn == widget.cpu?.color) {
if (widget.mode == Mode.PVC && turn == widget.cpu.color) {
cpuMove(widget.cpu); cpuMove(widget.cpu);
} else if (widget.mode == Mode.DEMO) { } else if (widget.mode == Mode.DEMO) {
if (turn == widget.cpu.color) { if (turn == widget.cpu?.color) {
cpuMove(widget.cpu); cpuMove(widget.cpu);
} else { } else {
cpuMove(widget.cpu2); cpuMove(widget.cpu2);
...@@ -179,8 +176,7 @@ class _MatchPageState extends State<MatchPage> with TickerProviderStateMixin { ...@@ -179,8 +176,7 @@ class _MatchPageState extends State<MatchPage> with TickerProviderStateMixin {
padding: const EdgeInsets.all(0), padding: const EdgeInsets.all(0),
shrinkWrap: true, shrinkWrap: true,
physics: NeverScrollableScrollPhysics(), physics: NeverScrollableScrollPhysics(),
gridDelegate: gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 7),
SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 7),
childrenDelegate: SliverChildBuilderDelegate( childrenDelegate: SliverChildBuilderDelegate(
(context, i) { (context, i) {
final col = i % 7; final col = i % 7;
...@@ -204,8 +200,7 @@ class _MatchPageState extends State<MatchPage> with TickerProviderStateMixin { ...@@ -204,8 +200,7 @@ class _MatchPageState extends State<MatchPage> with TickerProviderStateMixin {
return GridView.custom( return GridView.custom(
padding: const EdgeInsets.all(0), padding: const EdgeInsets.all(0),
physics: NeverScrollableScrollPhysics(), physics: NeverScrollableScrollPhysics(),
gridDelegate: gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 7),
SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 7),
shrinkWrap: true, shrinkWrap: true,
childrenDelegate: SliverChildBuilderDelegate( childrenDelegate: SliverChildBuilderDelegate(
(context, i) { (context, i) {
...@@ -236,12 +231,12 @@ class _MatchPageState extends State<MatchPage> with TickerProviderStateMixin { ...@@ -236,12 +231,12 @@ class _MatchPageState extends State<MatchPage> with TickerProviderStateMixin {
} }
} }
void cpuMove(Cpu cpu) async { void cpuMove(Cpu? cpu) async {
int col = await cpu.chooseCol(board); int? col = await cpu?.chooseCol(board);
putChip(col); putChip(col);
if (winner == null && widget.mode == Mode.DEMO) { if (winner == null && widget.mode == Mode.DEMO) {
if (turn == widget.cpu.color) { if (turn == widget.cpu?.color) {
cpuMove(widget.cpu); cpuMove(widget.cpu);
} else { } else {
cpuMove(widget.cpu2); cpuMove(widget.cpu2);
...@@ -249,7 +244,7 @@ class _MatchPageState extends State<MatchPage> with TickerProviderStateMixin { ...@@ -249,7 +244,7 @@ class _MatchPageState extends State<MatchPage> with TickerProviderStateMixin {
} }
} }
void putChip(int col) { void putChip(int? col) {
final target = board.getColumnTarget(col); final target = board.getColumnTarget(col);
final player = turn; final player = turn;
...@@ -273,7 +268,7 @@ class _MatchPageState extends State<MatchPage> with TickerProviderStateMixin { ...@@ -273,7 +268,7 @@ class _MatchPageState extends State<MatchPage> with TickerProviderStateMixin {
}); });
} }
translations[col][target] = Tween( translations[col ?? 0][target] = Tween(
begin: 0.0, begin: 0.0,
end: 1.0, end: 1.0,
).animate(CurvedAnimation( ).animate(CurvedAnimation(
...@@ -293,7 +288,7 @@ class _MatchPageState extends State<MatchPage> with TickerProviderStateMixin { ...@@ -293,7 +288,7 @@ class _MatchPageState extends State<MatchPage> with TickerProviderStateMixin {
} }
} }
void showWinnerDialog(BuildContext context, Color player) { void showWinnerDialog(BuildContext context, Color? player) {
setState(() { setState(() {
winner = player; winner = player;
}); });
......
...@@ -42,14 +42,14 @@ packages: ...@@ -42,14 +42,14 @@ packages:
name: collection name: collection
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.15.0" version: "1.16.0"
fake_async: fake_async:
dependency: transitive dependency: transitive
description: description:
name: fake_async name: fake_async
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.2.0" version: "1.3.0"
flutter: flutter:
dependency: "direct main" dependency: "direct main"
description: flutter description: flutter
...@@ -73,7 +73,7 @@ packages: ...@@ -73,7 +73,7 @@ packages:
name: material_color_utilities name: material_color_utilities
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.1.3" version: "0.1.4"
meta: meta:
dependency: transitive dependency: transitive
description: description:
...@@ -87,7 +87,7 @@ packages: ...@@ -87,7 +87,7 @@ packages:
name: path name: path
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.8.0" version: "1.8.1"
sky_engine: sky_engine:
dependency: transitive dependency: transitive
description: flutter description: flutter
...@@ -99,7 +99,7 @@ packages: ...@@ -99,7 +99,7 @@ packages:
name: source_span name: source_span
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.8.1" version: "1.8.2"
stack_trace: stack_trace:
dependency: transitive dependency: transitive
description: description:
...@@ -134,20 +134,13 @@ packages: ...@@ -134,20 +134,13 @@ packages:
name: test_api name: test_api
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.4.8" version: "0.4.9"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
vector_math: vector_math:
dependency: transitive dependency: transitive
description: description:
name: vector_math name: vector_math
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.1" version: "2.1.2"
sdks: sdks:
dart: ">=2.14.0 <3.0.0" dart: ">=2.17.0-0 <3.0.0"
...@@ -4,7 +4,7 @@ publish_to: 'none' ...@@ -4,7 +4,7 @@ publish_to: 'none'
version: 1.0.0+1 version: 1.0.0+1
environment: environment:
sdk: ">=2.7.0 <3.0.0" sdk: ">=2.12.0 <3.0.0"
dependencies: dependencies:
flutter: flutter:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment