diff --git a/lib/main.dart b/lib/main.dart index 8ba56df..3b0d659 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -230,7 +230,7 @@ class MyApp extends StatelessWidget { var grid = Grid(); return grid; }, - ), + ), Provider.value( value: gamesServicesController), Provider.value(value: adsController), diff --git a/lib/src/change_name/change_name_screen.dart b/lib/src/change_name/change_name_screen.dart index c550521..7817c2e 100644 --- a/lib/src/change_name/change_name_screen.dart +++ b/lib/src/change_name/change_name_screen.dart @@ -27,9 +27,11 @@ class ChangeNameScreen extends StatelessWidget { rectangularMenuArea: Column( children: [ _gap, - FilledButton(onPressed: () { - GoRouter.of(context).go('/play/session'); - }, child: Text('Start')) + FilledButton( + onPressed: () { + GoRouter.of(context).go('/play/session'); + }, + child: Text('Start')) ], ), ), diff --git a/lib/src/play_session/grid_constants.dart b/lib/src/play_session/grid_constants.dart index 7b4cd50..1c04c01 100644 --- a/lib/src/play_session/grid_constants.dart +++ b/lib/src/play_session/grid_constants.dart @@ -1,6 +1,4 @@ +double dot_size = 12; +double bar_size = 55; -double dot_size=12; -double bar_size=55; - -const int grid_size=5; - +const int grid_size = 5; diff --git a/lib/src/play_session/grid_provider.dart b/lib/src/play_session/grid_provider.dart index 11e717f..5e4c9b6 100644 --- a/lib/src/play_session/grid_provider.dart +++ b/lib/src/play_session/grid_provider.dart @@ -51,29 +51,18 @@ class Grid extends ChangeNotifier { _p2++; } } - for (int i = 0; i < _gridWinner.length; i++) { - print(_gridWinner[i]); - } notifyListeners(); } void setGridCount(int x, int y, int value) { _gridCount[x][y] = value; - // log all grid count as a grid view - print(_gridCount); notifyListeners(); } void incrementGridCount(int x, int y) { - // print("$x ,$y"); - if (_gridCount[x][y] != 4) { _gridCount[x][y]++; } - for (int i = 0; i < _gridWinner.length; i++) { - print(_gridCount[i]); - } - notifyListeners(); } diff --git a/lib/src/play_session/play_session_screen.dart b/lib/src/play_session/play_session_screen.dart index f9f67dc..63ca865 100644 --- a/lib/src/play_session/play_session_screen.dart +++ b/lib/src/play_session/play_session_screen.dart @@ -76,10 +76,10 @@ class _PlaySessionScreenState extends State { Padding( padding: const EdgeInsets.all(8.0), child: SizedBox( - width: double.infinity, + width: 300, child: FilledButton( onPressed: () => GoRouter.of(context).go('/play'), - child: const Text('Back'), + child: const Text('Quit'), ), ), ), @@ -261,33 +261,32 @@ class _GameGridState extends State { children: [ dot(), ...List.generate( - grid_size, - (y) => Row( - children: [ - InkWell( - onTap: () { - if (!gridProvider.getStick1(0, y)) { - gridProvider.incrementGridCount(0, y); - } - gridProvider.setDot1(0, y, true); - if (gridProvider.getGridCount(0, y) != 4) { - gridProvider.setPlayer(); - } else { - if (gridProvider.getWinner(0, y) == -1) { - int winner = - gridProvider.getPlayer() ? 1 : 0; - gridProvider.setWinner(0, y, winner); - } - } - gameState.evaluate(gridProvider.getp1() + - gridProvider.getp2()); - }, - child: - horizontalBar(gridProvider.getStick1(0, y)), - ), - dot(), - ], - )), + grid_size, + (y) => Row( + children: [ + InkWell( + onTap: () { + if (!gridProvider.getStick1(0, y)) { + gridProvider.incrementGridCount(0, y); + } + gridProvider.setDot1(0, y, true); + if (gridProvider.getGridCount(0, y) != 4) { + gridProvider.setPlayer(); + } else { + if (gridProvider.getWinner(0, y) == -1) { + int winner = gridProvider.getPlayer() ? 1 : 0; + gridProvider.setWinner(0, y, winner); + } + } + gameState.evaluate( + gridProvider.getp1() + gridProvider.getp2()); + }, + child: horizontalBar(gridProvider.getStick1(0, y)), + ), + dot(), + ], + ), + ), ], ), ...List.generate(grid_size, (x) { @@ -317,60 +316,53 @@ class _GameGridState extends State { }, child: verticalBar(gridProvider.getStick2(x, 0))), ...List.generate( - grid_size, - (y) => Row( - children: [ - box( - gridProvider.getWinner(x, y) == 1 - ? palette.pen - : palette.redPen, - visible: - gridProvider.getGridCount(x, y) == 4), - InkWell( - onTap: () { - bool scored = false; - int winner = - gridProvider.getPlayer() ? 1 : 0; - if (gridProvider.getStick2(x, y + 1)) { - return; - } - gridProvider.incrementGridCount(x, y); - if (y != grid_size - 1) { - gridProvider.incrementGridCount( - x, y + 1); - } - gridProvider.setDot2(x, y + 1, true); - - if (gridProvider.getGridCount(x, y) == - 4) { - if (gridProvider.getWinner(x, y) == - -1) { - gridProvider.setWinner(x, y, winner); - scored = true; - } - } - if (y != grid_size - 1 && - gridProvider.getGridCount(x, y + 1) == - 4) { - if (gridProvider.getWinner(x, y + 1) == - -1) { - gridProvider.setWinner( - x, y + 1, winner); - scored = true; - } - } - if (scored == false) { - gridProvider.setPlayer(); - } + grid_size, + (y) => Row( + children: [ + box( + gridProvider.getWinner(x, y) == 1 + ? palette.pen + : palette.redPen, + visible: gridProvider.getGridCount(x, y) == 4), + InkWell( + onTap: () { + bool scored = false; + int winner = gridProvider.getPlayer() ? 1 : 0; + if (gridProvider.getStick2(x, y + 1)) { + return; + } + gridProvider.incrementGridCount(x, y); + if (y != grid_size - 1) { + gridProvider.incrementGridCount(x, y + 1); + } + gridProvider.setDot2(x, y + 1, true); - gameState.evaluate(gridProvider.getp1() + - gridProvider.getp2()); - }, - child: verticalBar( - gridProvider.getStick2(x, y + 1)), - ), - ], - )), + if (gridProvider.getGridCount(x, y) == 4) { + if (gridProvider.getWinner(x, y) == -1) { + gridProvider.setWinner(x, y, winner); + scored = true; + } + } + if (y != grid_size - 1 && + gridProvider.getGridCount(x, y + 1) == 4) { + if (gridProvider.getWinner(x, y + 1) == -1) { + gridProvider.setWinner(x, y + 1, winner); + scored = true; + } + } + if (scored == false) { + gridProvider.setPlayer(); + } + + gameState.evaluate(gridProvider.getp1() + + gridProvider.getp2()); + }, + child: + verticalBar(gridProvider.getStick2(x, y + 1)), + ), + ], + ), + ), ], ), // dot and bar @@ -379,98 +371,91 @@ class _GameGridState extends State { children: [ dot(), ...List.generate( - grid_size, - (y) => Row( - children: [ - InkWell( - onTap: () { - /// to keep track of current player in integer form, no bool to int like cpp :( - /// - int winner = - gridProvider.getPlayer() ? 1 : 0; + grid_size, + (y) => Row( + children: [ + InkWell( + onTap: () { + /// to keep track of current player in integer form, no bool to int like cpp :( + /// + int winner = gridProvider.getPlayer() ? 1 : 0; - /// To keep check whether the player scored in current move - /// - bool scored = false; - - if (gridProvider.getStick1(x + 1, y)) { - return; - } - gridProvider.incrementGridCount(x, y); - if (x != grid_size - 1) { - gridProvider.incrementGridCount( - x + 1, y); - } - - /// Now checking for the block with coordinate {x, y} - /// - /// if eligible for the being part of someone score - if (gridProvider.getGridCount(x, y) == - 4) { - /// checking whether the block is already assigned to someone. - if (gridProvider.getWinner(x, y) == - -1) { - /// enter here when block not assigned to anyone - /// - /// Now assign the block win to current player - gridProvider.setWinner( - x, y, winner); - - /// Telling our code that player have scored - /// - scored = true; - } - } - - /// Now checking for the block with coordinate {x+1, y} - /// - /// if the stick even have next block, the adjacent case - if (x != grid_size - 1) { - /// we know now the block exist, pheww! - /// - /// below if statement checks whether - /// the block is eligible to be part of someone score - if (gridProvider.getGridCount( - x + 1, y) == - 4) { - /// Making sure the {x+1, y} block is not assigned. - /// - if (gridProvider.getWinner( - x + 1, y) == - -1) { - /// now assignation of the current block to current player - /// - gridProvider.setWinner( - x + 1, y, winner); - - /// Telling our code that player have scored - /// - scored = true; - } - } - } - - /// if the player have scored, he gets another chance, yaay! - /// - if (scored == false) { - gridProvider.setPlayer(); - } + /// To keep check whether the player scored in current move + /// + bool scored = false; - /// marking the stick touched :) - gridProvider.setDot1(x + 1, y, true); + if (gridProvider.getStick1(x + 1, y)) { + return; + } + gridProvider.incrementGridCount(x, y); + if (x != grid_size - 1) { + gridProvider.incrementGridCount(x + 1, y); + } - /// checking if the game has ended + /// Now checking for the block with coordinate {x, y} + /// + /// if eligible for the being part of someone score + if (gridProvider.getGridCount(x, y) == 4) { + /// checking whether the block is already assigned to someone. + if (gridProvider.getWinner(x, y) == -1) { + /// enter here when block not assigned to anyone + /// + /// Now assign the block win to current player + gridProvider.setWinner(x, y, winner); + + /// Telling our code that player have scored + /// + scored = true; + } + } + + /// Now checking for the block with coordinate {x+1, y} + /// + /// if the stick even have next block, the adjacent case + if (x != grid_size - 1) { + /// we know now the block exist, pheww! + /// + /// below if statement checks whether + /// the block is eligible to be part of someone score + if (gridProvider.getGridCount(x + 1, y) == + 4) { + /// Making sure the {x+1, y} block is not assigned. + /// + if (gridProvider.getWinner(x + 1, y) == + -1) { + /// now assignation of the current block to current player /// + gridProvider.setWinner( + x + 1, y, winner); + + /// Telling our code that player have scored /// - gameState.evaluate( - gridProvider.getp1() + - gridProvider.getp2()); - }, - child: horizontalBar( - gridProvider.getStick1(x + 1, y))), - dot(), - ], - )), + scored = true; + } + } + } + + /// if the player have scored, he gets another chance, yaay! + /// + if (scored == false) { + gridProvider.setPlayer(); + } + + /// marking the stick touched :) + gridProvider.setDot1(x + 1, y, true); + + /// checking if the game has ended + /// + /// + gameState.evaluate(gridProvider.getp1() + + gridProvider.getp2()); + }, + child: horizontalBar( + gridProvider.getStick1(x + 1, y))), + dot(), + ], + ), + ), ], ), ], @@ -489,7 +474,7 @@ Widget horizontalBar(bool visible) { width: bar_size, decoration: BoxDecoration( borderRadius: BorderRadius.circular(10), - color: visible ? Colors.blue : const Color.fromARGB(75, 0, 0, 0), + color: visible ? Colors.black : const Color.fromARGB(75, 0, 0, 0), shape: BoxShape.rectangle), ); } @@ -500,7 +485,7 @@ Widget verticalBar(bool visible) { width: dot_size, decoration: BoxDecoration( borderRadius: BorderRadius.circular(10), - color: visible ? Colors.blue : const Color.fromARGB(75, 0, 0, 0), + color: visible ? Colors.black : const Color.fromARGB(75, 0, 0, 0), shape: BoxShape.rectangle), ); } diff --git a/lib/src/settings/custom_name_dialog.dart b/lib/src/settings/custom_name_dialog.dart index 85e6e42..16f5f01 100644 --- a/lib/src/settings/custom_name_dialog.dart +++ b/lib/src/settings/custom_name_dialog.dart @@ -72,7 +72,7 @@ class _CustomNameDialogState extends State { @override void didChangeDependencies() { - _controller.text = widget.player==Player.player1 + _controller.text = widget.player == Player.player1 ? context.read().player1Name.value : context.read().player2Name.value; super.didChangeDependencies(); diff --git a/lib/src/settings/persistence/local_storage_settings_persistence.dart b/lib/src/settings/persistence/local_storage_settings_persistence.dart index af85c56..77fc09b 100644 --- a/lib/src/settings/persistence/local_storage_settings_persistence.dart +++ b/lib/src/settings/persistence/local_storage_settings_persistence.dart @@ -29,6 +29,7 @@ class LocalStorageSettingsPersistence extends SettingsPersistence { final prefs = await instanceFuture; return prefs.getString('player1Name') ?? 'Player1'; } + @override Future getPlayer2Name() async { final prefs = await instanceFuture; @@ -58,6 +59,7 @@ class LocalStorageSettingsPersistence extends SettingsPersistence { final prefs = await instanceFuture; await prefs.setString('player1Name', value); } + @override Future savePlayer2Name(String value) async { final prefs = await instanceFuture; diff --git a/lib/src/settings/settings_screen.dart b/lib/src/settings/settings_screen.dart index 647489b..d39ca90 100644 --- a/lib/src/settings/settings_screen.dart +++ b/lib/src/settings/settings_screen.dart @@ -39,14 +39,8 @@ class SettingsScreen extends StatelessWidget { ), ), _gap, - const _NameChangeLine( - 'Player1:', - Player.player1 - ), - const _NameChangeLine( - 'Player2:', - Player.player2 - ), + const _NameChangeLine('Player1:', Player.player1), + const _NameChangeLine('Player2:', Player.player2), ValueListenableBuilder( valueListenable: settings.soundsOn, builder: (context, soundsOn, child) => _SettingsLine( @@ -130,7 +124,7 @@ class _NameChangeLine extends StatelessWidget { return InkResponse( highlightShape: BoxShape.rectangle, - onTap: () => showCustomNameDialog(context,player), + onTap: () => showCustomNameDialog(context, player), child: Padding( padding: const EdgeInsets.symmetric(horizontal: 8), child: Row( diff --git a/lib/src/style/palette.dart b/lib/src/style/palette.dart index 1a18d6a..bfce83f 100644 --- a/lib/src/style/palette.dart +++ b/lib/src/style/palette.dart @@ -44,6 +44,4 @@ class Palette { void changeRedPen(Color newColor) { redPen = newColor; } - - } diff --git a/web/favicon.png b/web/favicon.png index 8aaa46a..d65645a 100644 Binary files a/web/favicon.png and b/web/favicon.png differ diff --git a/web/index.html b/web/index.html index 985bcde..74e1787 100644 --- a/web/index.html +++ b/web/index.html @@ -29,7 +29,7 @@ - game_template + Pipo