From 87d7c7c5a79bf2362bc68b336007e6080d6a2710 Mon Sep 17 00:00:00 2001 From: "arthur.valin" Date: Mon, 20 Mar 2023 11:24:42 +0100 Subject: [PATCH 1/9] Adding game to user when finished --- .../bowlin_project/lib/model/AbstractRound.dart | 1 - Sources/bowlin_project/lib/model/Game.dart | 12 +++++++----- Sources/bowlin_project/lib/model/GameDetail.dart | 12 +++++++++++- Sources/bowlin_project/lib/model/Guest.dart | 14 +++++++++++++- Sources/bowlin_project/lib/model/Player.dart | 8 ++++---- Sources/bowlin_project/lib/model/Round.dart | 1 - .../lib/model/StubManager/GameManager.dart | 4 ++-- .../lib/model/StubManager/StubData.dart | 15 ++++++++------- .../lib/model/StubManager/UserManager.dart | 2 +- Sources/bowlin_project/lib/model/User.dart | 7 +++++-- .../bowlin_project/lib/views/ingame_screen.dart | 4 +++- .../lib/widgets/scores_list_widget.dart | 6 ++---- 12 files changed, 56 insertions(+), 30 deletions(-) diff --git a/Sources/bowlin_project/lib/model/AbstractRound.dart b/Sources/bowlin_project/lib/model/AbstractRound.dart index fa8d612..e21073c 100644 --- a/Sources/bowlin_project/lib/model/AbstractRound.dart +++ b/Sources/bowlin_project/lib/model/AbstractRound.dart @@ -73,7 +73,6 @@ abstract class AbstractRound { void update(int val){ points = (points ?? 0) + val; - print("ROUND " + number.toString() + " - " + player.id.toString() + "Update points : " + points.toString()); previousRound?.update(val); } diff --git a/Sources/bowlin_project/lib/model/Game.dart b/Sources/bowlin_project/lib/model/Game.dart index 8325b89..8f6c909 100644 --- a/Sources/bowlin_project/lib/model/Game.dart +++ b/Sources/bowlin_project/lib/model/Game.dart @@ -1,13 +1,15 @@ +import 'Player.dart'; + class Game { int _id; DateTime _date; int _pointsCurrentUser; bool _isFinished; - List _playersId = []; + List _players = []; // Constructor Game(this._id, this._date, this._pointsCurrentUser, this._isFinished, - this._playersId); + this._players); // Getters and setters int get id => _id; @@ -34,9 +36,9 @@ class Game { _isFinished = value; } - List get playersId => _playersId; + List get players => _players; - set playersId(List value) { - _playersId = value; + set playersId(List value) { + _players = value; } } diff --git a/Sources/bowlin_project/lib/model/GameDetail.dart b/Sources/bowlin_project/lib/model/GameDetail.dart index 988fc41..35de3f7 100644 --- a/Sources/bowlin_project/lib/model/GameDetail.dart +++ b/Sources/bowlin_project/lib/model/GameDetail.dart @@ -5,6 +5,7 @@ import 'package:bowl_in/model/LastRound.dart'; import 'Player.dart'; import 'Round.dart'; +import 'User.dart'; class GameDetail { int _id; @@ -25,10 +26,10 @@ class GameDetail { this.rounds.add(Round(null, null, 0, element, i)); }); } - players.forEach((element) { this.rounds.add(LastRound(null, null, 0, element, 10, null)); }); + } // Getters and setters @@ -83,6 +84,14 @@ class GameDetail { Map get points => _points; + void addGameToUsers(){ + for(var p in players){ + if(p is User){ + p.games.add(Game(this.id, this.time, points[p] ?? 0, true, players)); + } + } + } + void computeScores(){ print("====COMPUTE POINTS===="); for(var element in rounds){ @@ -90,6 +99,7 @@ class GameDetail { points[element.player] = (points[element.player] ?? 0) + (element.points ?? 0); print(element.player.name + " : " + points[element.player].toString()); } + addGameToUsers(); } Map getRank() { diff --git a/Sources/bowlin_project/lib/model/Guest.dart b/Sources/bowlin_project/lib/model/Guest.dart index 081bea0..244087a 100644 --- a/Sources/bowlin_project/lib/model/Guest.dart +++ b/Sources/bowlin_project/lib/model/Guest.dart @@ -1,6 +1,18 @@ +import 'dart:math'; + import 'Player.dart'; +const _images = [ + "./assets/images/image_user_cyan.png", + "./assets/images/image_user_red.png", + "./assets/images/image_user_yellow.png", + "./assets/images/image_user_pink.png", + "./assets/images/image_user_orange.png", + "./assets/images/image_user_green.png", + "./assets/images/image_user_purple.png", +]; + class Guest extends Player { // Constructor - Guest(int id, String image, String name) : super(id, image, name); + Guest(String name) : super(name, _images[Random().nextInt(_images.length)]); } diff --git a/Sources/bowlin_project/lib/model/Player.dart b/Sources/bowlin_project/lib/model/Player.dart index ebf0963..c9a6dfd 100644 --- a/Sources/bowlin_project/lib/model/Player.dart +++ b/Sources/bowlin_project/lib/model/Player.dart @@ -1,13 +1,10 @@ class Player { - final int _id; String _name; String _image; // Constructor - Player(this._id, this._name, this._image); - + Player(this._name, this._image); // Getters and setters - int get id => _id; String get name => _name; @@ -20,4 +17,7 @@ class Player { set image(String value) { _image = value; } + + + } diff --git a/Sources/bowlin_project/lib/model/Round.dart b/Sources/bowlin_project/lib/model/Round.dart index ee1128b..4f79629 100644 --- a/Sources/bowlin_project/lib/model/Round.dart +++ b/Sources/bowlin_project/lib/model/Round.dart @@ -28,7 +28,6 @@ class Round extends AbstractRound{ @override void computePoints() { points = (firstThrow ?? 0)+(secondThrow ?? 0); - print("ROUND " + number.toString() + " - " + player.id.toString() + "Compute points : " + points.toString()); if(previousRound?.isStrike() ?? false){ previousRound?.update(points ?? 0); } diff --git a/Sources/bowlin_project/lib/model/StubManager/GameManager.dart b/Sources/bowlin_project/lib/model/StubManager/GameManager.dart index cbff266..bca54b7 100644 --- a/Sources/bowlin_project/lib/model/StubManager/GameManager.dart +++ b/Sources/bowlin_project/lib/model/StubManager/GameManager.dart @@ -28,7 +28,7 @@ class GameManager extends IGameManager { List games = []; for (var element in parent.gameDetails) { for (Player player in element.players) { - if (player.id == id) { + if (player is User && player.id == id) { games.add(element); break; } @@ -41,7 +41,7 @@ class GameManager extends IGameManager { List games = []; for (var element in parent.gameDetails) { for (Player player in element.players) { - if (player.id == user.id) { + if (player is User && user is User && player.id == user.id) { games.add(element); break; } diff --git a/Sources/bowlin_project/lib/model/StubManager/StubData.dart b/Sources/bowlin_project/lib/model/StubManager/StubData.dart index 5727214..c0dd698 100644 --- a/Sources/bowlin_project/lib/model/StubManager/StubData.dart +++ b/Sources/bowlin_project/lib/model/StubManager/StubData.dart @@ -1,5 +1,6 @@ library StubLib; +import '../Guest.dart'; import '../IManager.dart'; import '../Game.dart'; import '../IUserManager.dart'; @@ -32,13 +33,13 @@ class StubData extends IManager { IGameManager get gameMgr => _gameMgr; List players = [ - Player(1, "Mathieu", "./assets/images/image_user_cyan.png"), - Player(2, "Robin", "./assets/images/image_user_purple.png"), - Player(3, "Lucas", "./assets/images/image_user_red.png"), - Player(4, "Emre", "./assets/images/image_user_blue.png"), - Player(5, "Louison", "./assets/images/image_user_cyan.png"), - Player(6, "Arthur", "./assets/images/image_user_yellow.png"), - Player(7, "David", "./assets/images/image_user_pink.png"), + Guest("Mathieu"), + Guest("Robin"), + Guest("Lucas"), + Guest("Emre"), + Guest("Louison"), + Guest("Arthur"), + Guest("David"), User( 8, "Emre", diff --git a/Sources/bowlin_project/lib/model/StubManager/UserManager.dart b/Sources/bowlin_project/lib/model/StubManager/UserManager.dart index 2ef5fb7..c4e7f57 100644 --- a/Sources/bowlin_project/lib/model/StubManager/UserManager.dart +++ b/Sources/bowlin_project/lib/model/StubManager/UserManager.dart @@ -28,7 +28,7 @@ class UserManager extends IUserManager { Player getUserById(int id) { for (var player in parent.players) { - if (player.id == id) { + if (player is User && player.id == id) { return player; } } diff --git a/Sources/bowlin_project/lib/model/User.dart b/Sources/bowlin_project/lib/model/User.dart index a9a4069..b1740aa 100644 --- a/Sources/bowlin_project/lib/model/User.dart +++ b/Sources/bowlin_project/lib/model/User.dart @@ -4,6 +4,7 @@ import 'Player.dart'; import 'Stat.dart'; class User extends Player { + final int _id; String _mail; List _achievements = []; List _friends = []; @@ -11,9 +12,11 @@ class User extends Player { List games = []; // Constructor - User(int id, String name, String image, this._mail, this._achievements, + User(this._id, String name, String image, this._mail, this._achievements, this._friends, this._stat) - : super(id, name, image); + : super(name, image); + + int get id => _id; // Getters and setters String get mail => _mail; diff --git a/Sources/bowlin_project/lib/views/ingame_screen.dart b/Sources/bowlin_project/lib/views/ingame_screen.dart index 68558a4..653e3c1 100644 --- a/Sources/bowlin_project/lib/views/ingame_screen.dart +++ b/Sources/bowlin_project/lib/views/ingame_screen.dart @@ -6,6 +6,8 @@ import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import 'package:google_fonts/google_fonts.dart'; +import '../model/Game.dart'; +import '../model/Guest.dart'; import '../widgets/button_new_party.dart'; import '../widgets/ingame_widgets.dart'; import '../widgets/scores_list_widget.dart'; @@ -53,7 +55,7 @@ class _InGameScreenState extends State { ElevatedButton( onPressed: () { GameDetail gd = GameDetail(1, DateTime.now(), null, 123, false, - MyApp.controller.userCurrent.id, [MyApp.controller.userCurrent, MyApp.controller.userMgr.getUserById(2)]); + MyApp.controller.userCurrent.id, [MyApp.controller.userCurrent, new Guest("Louison")]); MyApp.controller.gamePlayer.game = gd; MyApp.controller.gameCurrent = gd; diff --git a/Sources/bowlin_project/lib/widgets/scores_list_widget.dart b/Sources/bowlin_project/lib/widgets/scores_list_widget.dart index e8117a6..2765cc5 100644 --- a/Sources/bowlin_project/lib/widgets/scores_list_widget.dart +++ b/Sources/bowlin_project/lib/widgets/scores_list_widget.dart @@ -111,11 +111,9 @@ class CardGame extends StatelessWidget { child: Wrap( spacing: 5, runSpacing: 5, - children: game.playersId + children: game.players .map((e) => ProfilPicture( - path: MyApp.controller.userMgr - .getUserById(e) - .image + path: e.image .toString(), )) .toList()))), -- 2.36.3 From 8a8e51b70066e7a429ff2713a8ba5a31b2a7c92f Mon Sep 17 00:00:00 2001 From: "arthur.valin" Date: Mon, 20 Mar 2023 12:59:12 +0100 Subject: [PATCH 2/9] Computing stats after game --- .../lib/model/AbstractRound.dart | 3 ++ .../bowlin_project/lib/model/GameDetail.dart | 15 ++++-- .../bowlin_project/lib/model/LastRound.dart | 40 ++++++++++++++ Sources/bowlin_project/lib/model/Round.dart | 22 ++++++++ Sources/bowlin_project/lib/model/Stat.dart | 23 ++++++++ .../lib/model/StubManager/StubData.dart | 54 +++++++++---------- .../lib/views/analysis_screen.dart | 9 ++-- .../lib/widgets/analysis_card.dart | 5 +- 8 files changed, 134 insertions(+), 37 deletions(-) diff --git a/Sources/bowlin_project/lib/model/AbstractRound.dart b/Sources/bowlin_project/lib/model/AbstractRound.dart index e21073c..81c1e62 100644 --- a/Sources/bowlin_project/lib/model/AbstractRound.dart +++ b/Sources/bowlin_project/lib/model/AbstractRound.dart @@ -66,6 +66,9 @@ abstract class AbstractRound { return (firstThrow ?? 0)+(secondThrow ?? 0)==10; } + int getNbStrike(); + int getNbSpares(); + int getPinsKnockedDown(); void subscribe(AbstractRound nextRound){ nextRound.previousRound=this; diff --git a/Sources/bowlin_project/lib/model/GameDetail.dart b/Sources/bowlin_project/lib/model/GameDetail.dart index 35de3f7..4b159e9 100644 --- a/Sources/bowlin_project/lib/model/GameDetail.dart +++ b/Sources/bowlin_project/lib/model/GameDetail.dart @@ -10,7 +10,7 @@ import 'User.dart'; class GameDetail { int _id; DateTime _time; - int? _winner; + Player? _winner; int _nbPoints; bool _isFinished; int _host; @@ -45,9 +45,9 @@ class GameDetail { _time = value; } - int? get winner => _winner; + Player? get winner => _winner; - set winner(int? value) { + set winner(Player? value) { _winner = value; } @@ -88,17 +88,22 @@ class GameDetail { for(var p in players){ if(p is User){ p.games.add(Game(this.id, this.time, points[p] ?? 0, true, players)); + p.stat.updateStats(this, p); } } } + void computeWinner(){ + print(getRank().entries.first.key.name); + this.winner = getRank().entries.first.key; + } + void computeScores(){ print("====COMPUTE POINTS===="); for(var element in rounds){ - print(element.points); points[element.player] = (points[element.player] ?? 0) + (element.points ?? 0); - print(element.player.name + " : " + points[element.player].toString()); } + computeWinner(); addGameToUsers(); } diff --git a/Sources/bowlin_project/lib/model/LastRound.dart b/Sources/bowlin_project/lib/model/LastRound.dart index c7bebd4..3c90d7c 100644 --- a/Sources/bowlin_project/lib/model/LastRound.dart +++ b/Sources/bowlin_project/lib/model/LastRound.dart @@ -55,4 +55,44 @@ class LastRound extends AbstractRound{ return secondThrow==10; } } + + @override + int getNbSpares() { + int nb = 0; + if(firstThrow!=10){ + if((firstThrow??0)+(secondThrow??0)==10){ + nb+=1; + } + }else{ + if((thirdThrow??0)+(secondThrow??0)==10) { + nb+=1; + } + } + return nb; + } + + @override + int getNbStrike() { + int nb = 0; + if(firstThrow==10){ + nb+=1; + if(secondThrow==10){ + nb+=1; + if(thirdThrow==10) { + nb+=1; + } + } + }else{ + if(thirdThrow==10) { + nb+=1; + } + } + return nb; + } + + @override + int getPinsKnockedDown() { + return (firstThrow??0)+(secondThrow??0)+(thirdThrow??0); + } + } diff --git a/Sources/bowlin_project/lib/model/Round.dart b/Sources/bowlin_project/lib/model/Round.dart index 4f79629..f9c81d1 100644 --- a/Sources/bowlin_project/lib/model/Round.dart +++ b/Sources/bowlin_project/lib/model/Round.dart @@ -39,5 +39,27 @@ class Round extends AbstractRound{ return firstThrow==null; } + @override + int getNbSpares() { + if(isSpare()){ + return 1; + } + return 0; + } + + @override + int getNbStrike() { + if(isStrike()){ + return 1; + } + return 0; + } + + @override + int getPinsKnockedDown() { + return (firstThrow ?? 0)+(secondThrow ?? 0); + } + + } diff --git a/Sources/bowlin_project/lib/model/Stat.dart b/Sources/bowlin_project/lib/model/Stat.dart index f16097b..2c874c4 100644 --- a/Sources/bowlin_project/lib/model/Stat.dart +++ b/Sources/bowlin_project/lib/model/Stat.dart @@ -1,3 +1,8 @@ +import 'package:bowl_in/model/GameDetail.dart'; +import 'package:bowl_in/model/Player.dart'; + +import 'User.dart'; + class Stat { int _nbVictory; int _nbDefeat; @@ -76,4 +81,22 @@ class Stat { set avgPinsPerRound(double value) { _avgPinsPerRound = value; } + + void updateStats(GameDetail gd, Player p){ + nbGames +=1; + if(gd.winner == p){ + nbVictory +=1; + } + double totalpins = 0; + for(var r in gd.rounds){ + + if(p == r.player){ + nbStrikes += r.getNbStrike(); + nbSpares += r.getNbSpares(); + totalpins = totalpins + r.getPinsKnockedDown(); + } + } + avgPinsPerRound = ((avgPinsPerRound * (nbGames-1)) + (totalpins/10))/nbGames; + + } } diff --git a/Sources/bowlin_project/lib/model/StubManager/StubData.dart b/Sources/bowlin_project/lib/model/StubManager/StubData.dart index c0dd698..a4a2ef5 100644 --- a/Sources/bowlin_project/lib/model/StubManager/StubData.dart +++ b/Sources/bowlin_project/lib/model/StubManager/StubData.dart @@ -52,15 +52,15 @@ class StubData extends IManager { ], [], Stat( - 10, - 2, - 12, - 130, - 7, - 6, - 700, - 58.33, - 30.2)), + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0)), User( 9, "Dave", @@ -84,15 +84,15 @@ class StubData extends IManager { ], [], Stat( - 10, - 2, - 12, - 110, - 7, - 6, - 700, - 58.33, - 30.2)), + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0)), User( 22, "Louison", @@ -179,15 +179,15 @@ class StubData extends IManager { 30.2)), ], Stat( - 2, - 7, - 9, - 80, - 4, - 3, - 250, - 27.77, - 10.55)) + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0)) ]; List _gameDetails = []; diff --git a/Sources/bowlin_project/lib/views/analysis_screen.dart b/Sources/bowlin_project/lib/views/analysis_screen.dart index 1fdea2f..303ef90 100644 --- a/Sources/bowlin_project/lib/views/analysis_screen.dart +++ b/Sources/bowlin_project/lib/views/analysis_screen.dart @@ -86,11 +86,14 @@ class _AnalysisScreenState extends State { children: [ StatsCard( title: "Number of victory", - val: MyApp.controller.userCurrent.stat.nbVictory - .toDouble()), + val: MyApp.controller.userCurrent.stat.nbVictory.toDouble(), + precision: 0, + ), StatsCard( title: "Average pins per round", - val: MyApp.controller.userCurrent.stat.avgPinsPerRound), + val: MyApp.controller.userCurrent.stat.avgPinsPerRound, + precision: 2, + ), ], )) ]), diff --git a/Sources/bowlin_project/lib/widgets/analysis_card.dart b/Sources/bowlin_project/lib/widgets/analysis_card.dart index 58105da..f9bd586 100644 --- a/Sources/bowlin_project/lib/widgets/analysis_card.dart +++ b/Sources/bowlin_project/lib/widgets/analysis_card.dart @@ -101,8 +101,9 @@ class GameCard extends StatelessWidget { class StatsCard extends StatelessWidget { final String title; final double val; + final int precision; - const StatsCard({Key? key, required this.title, required this.val}) + const StatsCard({Key? key, required this.title, required this.val, required this.precision}) : super(key: key); @override @@ -137,7 +138,7 @@ class StatsCard extends StatelessWidget { ), Spacer(), Text( - this.val.toString(), + this.val.toStringAsFixed(precision), style: GoogleFonts.roboto( fontWeight: FontWeight.w900, fontSize: 28, -- 2.36.3 From 62a785f489fc15dfb89fa7bc4b8ca968e131bc11 Mon Sep 17 00:00:00 2001 From: "arthur.valin" Date: Mon, 20 Mar 2023 13:02:39 +0100 Subject: [PATCH 3/9] Computing stats after game --- Sources/bowlin_project/lib/model/Stat.dart | 13 +++++-------- .../lib/model/StubManager/StubData.dart | 7 ------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/Sources/bowlin_project/lib/model/Stat.dart b/Sources/bowlin_project/lib/model/Stat.dart index 2c874c4..d68fa57 100644 --- a/Sources/bowlin_project/lib/model/Stat.dart +++ b/Sources/bowlin_project/lib/model/Stat.dart @@ -5,7 +5,6 @@ import 'User.dart'; class Stat { int _nbVictory; - int _nbDefeat; int _nbGames; int _highscore; int _nbStrikes; @@ -17,7 +16,6 @@ class Stat { // Constructor Stat( this._nbVictory, - this._nbDefeat, this._nbGames, this._highscore, this._nbStrikes, @@ -34,12 +32,6 @@ class Stat { _nbVictory = value; } - int get nbDefeat => _nbDefeat; - - set nbDefeat(int value) { - _nbDefeat = value; - } - int get nbGames => _nbGames; set nbGames(int value) { @@ -87,6 +79,11 @@ class Stat { if(gd.winner == p){ nbVictory +=1; } + + if((gd.points[p] ?? 0) > highscore){ + highscore = gd.points[p] ?? 0; + } + double totalpins = 0; for(var r in gd.rounds){ diff --git a/Sources/bowlin_project/lib/model/StubManager/StubData.dart b/Sources/bowlin_project/lib/model/StubManager/StubData.dart index a4a2ef5..001b928 100644 --- a/Sources/bowlin_project/lib/model/StubManager/StubData.dart +++ b/Sources/bowlin_project/lib/model/StubManager/StubData.dart @@ -59,7 +59,6 @@ class StubData extends IManager { 0, 0, 0, - 0, 0)), User( 9, @@ -91,7 +90,6 @@ class StubData extends IManager { 0, 0, 0, - 0, 0)), User( 22, @@ -106,7 +104,6 @@ class StubData extends IManager { [], Stat( 10, - 2, 12, 150, 7, @@ -127,7 +124,6 @@ class StubData extends IManager { [], Stat( 10, - 2, 12, 10, 7, @@ -148,7 +144,6 @@ class StubData extends IManager { [], Stat( 10, - 2, 12, 40, 7, @@ -169,7 +164,6 @@ class StubData extends IManager { [], Stat( 10, - 2, 12, 76, 7, @@ -186,7 +180,6 @@ class StubData extends IManager { 0, 0, 0, - 0, 0)) ]; -- 2.36.3 From bf4da7a38a653ebfece1e3b20be0b6a69fc6f210 Mon Sep 17 00:00:00 2001 From: "arthur.valin" Date: Mon, 20 Mar 2023 14:11:34 +0100 Subject: [PATCH 4/9] Correcting bug with NumberPad maxvalue --- .../bowlin_project/lib/model/AbstractRound.dart | 1 + Sources/bowlin_project/lib/model/LastRound.dart | 16 ++++++++++++++++ Sources/bowlin_project/lib/model/Round.dart | 10 ++++++++-- .../lib/widgets/ingame_widgets.dart | 11 +---------- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/Sources/bowlin_project/lib/model/AbstractRound.dart b/Sources/bowlin_project/lib/model/AbstractRound.dart index 81c1e62..b636611 100644 --- a/Sources/bowlin_project/lib/model/AbstractRound.dart +++ b/Sources/bowlin_project/lib/model/AbstractRound.dart @@ -53,6 +53,7 @@ abstract class AbstractRound { bool computeNext(int val); void computePoints(); bool shotIsStrike(); + int getMaxPinsThisShot(); bool isStrike() { return firstThrow==10; diff --git a/Sources/bowlin_project/lib/model/LastRound.dart b/Sources/bowlin_project/lib/model/LastRound.dart index 3c90d7c..71cbb86 100644 --- a/Sources/bowlin_project/lib/model/LastRound.dart +++ b/Sources/bowlin_project/lib/model/LastRound.dart @@ -95,4 +95,20 @@ class LastRound extends AbstractRound{ return (firstThrow??0)+(secondThrow??0)+(thirdThrow??0); } + + @override + int getMaxPinsThisShot() { + if(firstThrow==null){ + return 10; + }else if(firstThrow==10 && secondThrow==null){ + return 10; + }else if(secondThrow==null){ + return 10 - (firstThrow??0); + }else if(secondThrow==10){ + return 10; + }else{ + return 10 - (secondThrow??0); + } + } + } diff --git a/Sources/bowlin_project/lib/model/Round.dart b/Sources/bowlin_project/lib/model/Round.dart index f9c81d1..6e1d9c3 100644 --- a/Sources/bowlin_project/lib/model/Round.dart +++ b/Sources/bowlin_project/lib/model/Round.dart @@ -60,6 +60,12 @@ class Round extends AbstractRound{ return (firstThrow ?? 0)+(secondThrow ?? 0); } - - + @override + int getMaxPinsThisShot() { + if(firstThrow==null){ + return 10; + }else{ + return 10 - (firstThrow ?? 0); + } + } } diff --git a/Sources/bowlin_project/lib/widgets/ingame_widgets.dart b/Sources/bowlin_project/lib/widgets/ingame_widgets.dart index ed10c6c..07de61a 100644 --- a/Sources/bowlin_project/lib/widgets/ingame_widgets.dart +++ b/Sources/bowlin_project/lib/widgets/ingame_widgets.dart @@ -437,17 +437,8 @@ class InGameCardThrow extends StatefulWidget { class _InGameCardThrowState extends State { GlobalKey<_NumberPadState> _numberPadKey = GlobalKey(); - late var maxValue; void initState() { - if (widget.currentRound.firstThrow == null) { - maxValue = 10; - } else if (widget.currentRound.secondThrow == null) { - maxValue = 10 - (widget.currentRound.firstThrow ?? 0); - } else { - maxValue = 10; - } - super.initState(); } @@ -522,7 +513,7 @@ class _InGameCardThrowState extends State { numberThrow: widget.numberThrow, setSelectedValue: widget.setSelectedValue, currentRound: widget.currentRound, - maxValue: maxValue, + maxValue: widget.currentRound.getMaxPinsThisShot(), ), ], ), -- 2.36.3 From e19e44f4e00e9ebf396648d942eae7fbaf9bd0eb Mon Sep 17 00:00:00 2001 From: Lucas Delanier Date: Mon, 20 Mar 2023 17:41:33 +0100 Subject: [PATCH 5/9] add effect of button add player and textfield on guest player to rename them --- .../lib/model/IGameManager.dart | 1 + .../lib/model/StubManager/GameManager.dart | 5 + .../lib/views/ingame_screen.dart | 11 +- .../lib/widgets/button_new_party.dart | 79 +++++++------ .../lib/widgets/ingame_widgets.dart | 109 ++++++++++++------ .../lib/widgets/scores_list_widget.dart | 7 +- 6 files changed, 140 insertions(+), 72 deletions(-) diff --git a/Sources/bowlin_project/lib/model/IGameManager.dart b/Sources/bowlin_project/lib/model/IGameManager.dart index 0d5f434..175cf32 100644 --- a/Sources/bowlin_project/lib/model/IGameManager.dart +++ b/Sources/bowlin_project/lib/model/IGameManager.dart @@ -10,4 +10,5 @@ abstract class IGameManager { List getGamesByPlayers(List users); List getPlayersByIdGame(int id); Map getRankByIdGame(int id); + addGame(GameDetail gd); } diff --git a/Sources/bowlin_project/lib/model/StubManager/GameManager.dart b/Sources/bowlin_project/lib/model/StubManager/GameManager.dart index bca54b7..13f3630 100644 --- a/Sources/bowlin_project/lib/model/StubManager/GameManager.dart +++ b/Sources/bowlin_project/lib/model/StubManager/GameManager.dart @@ -81,4 +81,9 @@ class GameManager extends IGameManager { } throw Exception("Game not found."); } + + @override + addGame(GameDetail gd) { + parent.gameDetails.add(gd); + } } diff --git a/Sources/bowlin_project/lib/views/ingame_screen.dart b/Sources/bowlin_project/lib/views/ingame_screen.dart index 653e3c1..f2004a8 100644 --- a/Sources/bowlin_project/lib/views/ingame_screen.dart +++ b/Sources/bowlin_project/lib/views/ingame_screen.dart @@ -54,12 +54,19 @@ class _InGameScreenState extends State { Spacer(), ElevatedButton( onPressed: () { - GameDetail gd = GameDetail(1, DateTime.now(), null, 123, false, - MyApp.controller.userCurrent.id, [MyApp.controller.userCurrent, new Guest("Louison")]); + GameDetail gd = GameDetail( + 1, + DateTime.now(), + null, + 123, + false, + MyApp.controller.userCurrent.id, + [MyApp.controller.userCurrent, new Guest("Louison")]); MyApp.controller.gamePlayer.game = gd; MyApp.controller.gameCurrent = gd; MyApp.controller.gamePlayer.onNext(false, context); + MyApp.controller.gameMgr.addGame(gd); }, child: Text( "PLAY", diff --git a/Sources/bowlin_project/lib/widgets/button_new_party.dart b/Sources/bowlin_project/lib/widgets/button_new_party.dart index 81a6fb4..e31275e 100644 --- a/Sources/bowlin_project/lib/widgets/button_new_party.dart +++ b/Sources/bowlin_project/lib/widgets/button_new_party.dart @@ -4,6 +4,10 @@ import 'package:flutter/services.dart'; import 'package:go_router/go_router.dart'; import 'package:google_fonts/google_fonts.dart'; +import '../main.dart'; +import '../model/GameDetail.dart'; +import '../model/Player.dart'; +import '../model/User.dart'; import 'ingame_widgets.dart'; class ButtonNewParty extends StatelessWidget { @@ -143,10 +147,14 @@ class NewGameModal extends StatelessWidget { } class ScoreBoardModal extends StatelessWidget { - const ScoreBoardModal({Key? key}) : super(key: key); + final GameDetail gamedetail; + const ScoreBoardModal({Key? key, required this.gamedetail}) : super(key: key); @override Widget build(BuildContext context) { + var rank = gamedetail.getRank(); + var pseudoList = rank.keys.toList(); + var scoreList = rank.values.toList(); return Dialog( child: Stack( alignment: Alignment.topCenter, @@ -159,39 +167,42 @@ class ScoreBoardModal extends StatelessWidget { child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [ Expanded( - child: Padding( - padding: EdgeInsets.fromLTRB(0, 40, 0, 0), - child: Stack( - alignment: Alignment.topCenter, - children: [ - /*Positioned( - child: PodiumGameOverWidget( - isfirst: 2, - pseudo: 'Lucas', - score: 123, - ), - top: 70, - left: 30, - ), - Positioned( - child: PodiumGameOverWidget( - isfirst: 1, - pseudo: 'Momo', - score: 160, - ), - top: 10, - ), - Positioned( - child: PodiumGameOverWidget( - isfirst: 3, - pseudo: 'popo', - score: 110, - ), - top: 70, - right: 30, - )*/ - ], - ), + child: Stack( + alignment: Alignment.topCenter, + children: [ + rank.length > 1 + ? Positioned( + child: PodiumGameOverWidget( + isfirst: 2, + player: pseudoList[1], + score: scoreList[1], + ), + top: 70, + left: 30, + ) + : Container(), + rank.length > 0 + ? Positioned( + child: PodiumGameOverWidget( + isfirst: 1, + player: pseudoList[0], + score: scoreList[0], + ), + top: 10, + ) + : Container(), + rank.length > 2 + ? Positioned( + child: PodiumGameOverWidget( + isfirst: 3, + player: pseudoList[2], + score: scoreList[2], + ), + top: 70, + right: 30, + ) + : Container() + ], )), ]), ) diff --git a/Sources/bowlin_project/lib/widgets/ingame_widgets.dart b/Sources/bowlin_project/lib/widgets/ingame_widgets.dart index 07de61a..58ad7cf 100644 --- a/Sources/bowlin_project/lib/widgets/ingame_widgets.dart +++ b/Sources/bowlin_project/lib/widgets/ingame_widgets.dart @@ -1,5 +1,6 @@ import 'dart:ui'; +import 'package:bowl_in/main.dart'; import 'package:bowl_in/widgets/profil_listpodium_widget.dart'; import 'package:bowl_in/widgets/scores_list_widget.dart'; import 'package:flutter/cupertino.dart'; @@ -9,6 +10,7 @@ import 'package:google_fonts/google_fonts.dart'; import '../model/AbstractRound.dart'; import '../model/GameDetail.dart'; +import '../model/Guest.dart'; import '../model/Player.dart'; class FinalScoreBoard extends StatefulWidget { @@ -255,6 +257,13 @@ class InGameCardConfig extends StatefulWidget { } class _InGameCardConfigState extends State { + late List listPlayer; + @override + void initState() { + listPlayer = [MyApp.controller.userCurrent]; + super.initState(); + } + @override Widget build(BuildContext context) { return Container( @@ -298,7 +307,7 @@ class _InGameCardConfigState extends State { ], ), )), - ListUserInGame(), + ListUserInGame(listPlayer: listPlayer), Spacer(), Image( image: AssetImage("assets/images/start_sentence.png"), @@ -307,7 +316,12 @@ class _InGameCardConfigState extends State { Padding( padding: EdgeInsets.fromLTRB(15, 0, 15, 15), child: ElevatedButton( - onPressed: () {}, + onPressed: () { + setState(() { + if (listPlayer.length < 10) + listPlayer.add(new Guest("guest")); + }); + }, child: Text( "+ Add a player", style: GoogleFonts.roboto( @@ -332,7 +346,8 @@ class _InGameCardConfigState extends State { } class ListUserInGame extends StatefulWidget { - const ListUserInGame({Key? key}) : super(key: key); + final List listPlayer; + const ListUserInGame({Key? key, required this.listPlayer}) : super(key: key); @override State createState() => _ListUserInGameState(); @@ -347,23 +362,29 @@ class _ListUserInGameState extends State { crossAxisAlignment: CrossAxisAlignment.end, children: [ ConstrainedBox( - constraints: new BoxConstraints( - maxHeight: 170, - ), - child: ListView(children: [ - UserInGame(), - UserInGame(), - UserInGame(), - UserInGame(), - UserInGame(), - ])), - Text( - "3 player(s)", - style: GoogleFonts.roboto( - fontWeight: FontWeight.w500, - fontSize: 15, - color: CupertinoColors.black, - decoration: TextDecoration.none), + constraints: new BoxConstraints( + maxHeight: 170, + ), + child: ListView.builder( + itemCount: widget.listPlayer.length, + itemBuilder: (context, index) { + return UserInGame(player: widget.listPlayer[index]); + }), + ), + RichText( + text: TextSpan( + text: widget.listPlayer.length.toString(), + style: GoogleFonts.roboto( + fontWeight: FontWeight.w500, + fontSize: 15, + color: CupertinoColors.black, + decoration: TextDecoration.none), + children: const [ + TextSpan( + text: ' player(s)', + style: TextStyle(fontWeight: FontWeight.bold)), + ], + ), ) ], )); @@ -371,13 +392,15 @@ class _ListUserInGameState extends State { } class UserInGame extends StatefulWidget { - const UserInGame({Key? key}) : super(key: key); + final Player player; + const UserInGame({Key? key, required this.player}) : super(key: key); @override State createState() => _UserInGameState(); } class _UserInGameState extends State { + final userNameTextField = TextEditingController(); @override Widget build(BuildContext context) { return Container( @@ -399,20 +422,36 @@ class _UserInGameState extends State { decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(70)), image: DecorationImage( - image: AssetImage("assets/images/image_user_cyan.png"), - fit: BoxFit.cover), + image: AssetImage(widget.player.image), fit: BoxFit.cover), ), ), SizedBox( width: 10, ), - Text( - "Emre", - style: GoogleFonts.roboto( - fontSize: 18, - decoration: TextDecoration.none, - color: Color(0xff241E40)), - ), + widget.player is Guest + ? Material( + surfaceTintColor: Colors.transparent, + child: SizedBox( + width: 230, + child: TextField( + controller: userNameTextField, + style: const TextStyle(color: Colors.black), + decoration: InputDecoration( + border: InputBorder.none, + hintText: 'Pseudonyme', + ), + cursorColor: Colors.purple, + textAlign: TextAlign.left, + ), + ), + ) + : Text( + widget.player.name, + style: GoogleFonts.roboto( + fontSize: 18, + decoration: TextDecoration.none, + color: Color(0xff241E40)), + ), Spacer(), ], ), @@ -593,7 +632,10 @@ class SpareButton extends StatelessWidget { final IntCallback onSonChanged; final int valueToReturn; const SpareButton( - {Key? key, required this.onSonChanged, required this.currentSelected, required this.valueToReturn}) + {Key? key, + required this.onSonChanged, + required this.currentSelected, + required this.valueToReturn}) : super(key: key); @override @@ -613,8 +655,9 @@ class SpareButton extends StatelessWidget { child: Text( "SPARE !", style: GoogleFonts.roboto( - color: - currentSelected == valueToReturn ? Colors.pink : CupertinoColors.black, + color: currentSelected == valueToReturn + ? Colors.pink + : CupertinoColors.black, decoration: TextDecoration.none, fontWeight: FontWeight.w900, fontStyle: FontStyle.italic, diff --git a/Sources/bowlin_project/lib/widgets/scores_list_widget.dart b/Sources/bowlin_project/lib/widgets/scores_list_widget.dart index 2765cc5..c66c665 100644 --- a/Sources/bowlin_project/lib/widgets/scores_list_widget.dart +++ b/Sources/bowlin_project/lib/widgets/scores_list_widget.dart @@ -113,8 +113,7 @@ class CardGame extends StatelessWidget { runSpacing: 5, children: game.players .map((e) => ProfilPicture( - path: e.image - .toString(), + path: e.image.toString(), )) .toList()))), const Spacer(), @@ -147,7 +146,9 @@ class CardGame extends StatelessWidget { showDialog( context: context, builder: (BuildContext context) { - return ScoreBoardModal(); + return ScoreBoardModal( + gamedetail: + MyApp.controller.gameMgr.getGameById(game.id)); }); }, )); -- 2.36.3 From c64d8926ab78169458f066277440ef3e2191e6c0 Mon Sep 17 00:00:00 2001 From: "arthur.valin" Date: Mon, 20 Mar 2023 18:49:01 +0100 Subject: [PATCH 6/9] Adding players to game on creation --- .../bowlin_project/lib/views/ingame_screen.dart | 8 +++++--- .../lib/widgets/ingame_widgets.dart | 15 +++++++++------ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Sources/bowlin_project/lib/views/ingame_screen.dart b/Sources/bowlin_project/lib/views/ingame_screen.dart index f2004a8..eb128dd 100644 --- a/Sources/bowlin_project/lib/views/ingame_screen.dart +++ b/Sources/bowlin_project/lib/views/ingame_screen.dart @@ -8,6 +8,7 @@ import 'package:google_fonts/google_fonts.dart'; import '../model/Game.dart'; import '../model/Guest.dart'; +import '../model/Player.dart'; import '../widgets/button_new_party.dart'; import '../widgets/ingame_widgets.dart'; import '../widgets/scores_list_widget.dart'; @@ -20,10 +21,12 @@ class InGameScreen extends StatefulWidget { } class _InGameScreenState extends State { + late List listPlayers; late Widget widgetHolder; void initState() { - widgetHolder = InGameCardConfig(); + listPlayers = [MyApp.controller.userCurrent]; + widgetHolder = InGameCardConfig(listPlayer: listPlayers); super.initState(); } @@ -60,8 +63,7 @@ class _InGameScreenState extends State { null, 123, false, - MyApp.controller.userCurrent.id, - [MyApp.controller.userCurrent, new Guest("Louison")]); + MyApp.controller.userCurrent.id, listPlayers); MyApp.controller.gamePlayer.game = gd; MyApp.controller.gameCurrent = gd; diff --git a/Sources/bowlin_project/lib/widgets/ingame_widgets.dart b/Sources/bowlin_project/lib/widgets/ingame_widgets.dart index 58ad7cf..a619d37 100644 --- a/Sources/bowlin_project/lib/widgets/ingame_widgets.dart +++ b/Sources/bowlin_project/lib/widgets/ingame_widgets.dart @@ -250,17 +250,16 @@ class PodiumGameOverWidget extends StatelessWidget { } class InGameCardConfig extends StatefulWidget { - const InGameCardConfig({Key? key}) : super(key: key); + final List listPlayer; + const InGameCardConfig({Key? key, required this.listPlayer}) : super(key: key); @override State createState() => _InGameCardConfigState(); } class _InGameCardConfigState extends State { - late List listPlayer; @override void initState() { - listPlayer = [MyApp.controller.userCurrent]; super.initState(); } @@ -307,7 +306,7 @@ class _InGameCardConfigState extends State { ], ), )), - ListUserInGame(listPlayer: listPlayer), + ListUserInGame(listPlayer: widget.listPlayer), Spacer(), Image( image: AssetImage("assets/images/start_sentence.png"), @@ -318,8 +317,8 @@ class _InGameCardConfigState extends State { child: ElevatedButton( onPressed: () { setState(() { - if (listPlayer.length < 10) - listPlayer.add(new Guest("guest")); + if (widget.listPlayer.length < 10) + widget.listPlayer.add(new Guest("guest")); }); }, child: Text( @@ -438,10 +437,14 @@ class _UserInGameState extends State { style: const TextStyle(color: Colors.black), decoration: InputDecoration( border: InputBorder.none, + filled: true, + fillColor: Color(0xffF2F2F2), hintText: 'Pseudonyme', ), cursorColor: Colors.purple, textAlign: TextAlign.left, + onChanged: (str)=> widget.player.name=str + , ), ), ) -- 2.36.3 From 36031ebf07e8aaba35a70727d7450a413ba68fa8 Mon Sep 17 00:00:00 2001 From: "arthur.valin" Date: Mon, 20 Mar 2023 19:16:40 +0100 Subject: [PATCH 7/9] Adding deletion of players during game creation --- .../lib/views/analysis_screen.dart | 2 +- .../lib/widgets/ingame_widgets.dart | 37 +++++++++++++++---- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/Sources/bowlin_project/lib/views/analysis_screen.dart b/Sources/bowlin_project/lib/views/analysis_screen.dart index 303ef90..254785f 100644 --- a/Sources/bowlin_project/lib/views/analysis_screen.dart +++ b/Sources/bowlin_project/lib/views/analysis_screen.dart @@ -85,7 +85,7 @@ class _AnalysisScreenState extends State { verticalDirection: VerticalDirection.up, children: [ StatsCard( - title: "Number of victory", + title: "Number of victories", val: MyApp.controller.userCurrent.stat.nbVictory.toDouble(), precision: 0, ), diff --git a/Sources/bowlin_project/lib/widgets/ingame_widgets.dart b/Sources/bowlin_project/lib/widgets/ingame_widgets.dart index a619d37..2a948a8 100644 --- a/Sources/bowlin_project/lib/widgets/ingame_widgets.dart +++ b/Sources/bowlin_project/lib/widgets/ingame_widgets.dart @@ -12,6 +12,7 @@ import '../model/AbstractRound.dart'; import '../model/GameDetail.dart'; import '../model/Guest.dart'; import '../model/Player.dart'; +import '../model/User.dart'; class FinalScoreBoard extends StatefulWidget { final GameDetail gameDeatil; @@ -263,6 +264,12 @@ class _InGameCardConfigState extends State { super.initState(); } + void onDelete(Player p){ + setState(() { + widget.listPlayer.remove(p); + }); + } + @override Widget build(BuildContext context) { return Container( @@ -306,7 +313,7 @@ class _InGameCardConfigState extends State { ], ), )), - ListUserInGame(listPlayer: widget.listPlayer), + ListUserInGame(listPlayer: widget.listPlayer, onDelete: onDelete), Spacer(), Image( image: AssetImage("assets/images/start_sentence.png"), @@ -346,13 +353,15 @@ class _InGameCardConfigState extends State { class ListUserInGame extends StatefulWidget { final List listPlayer; - const ListUserInGame({Key? key, required this.listPlayer}) : super(key: key); + final Function(Player) onDelete; + const ListUserInGame({Key? key, required this.listPlayer, required this.onDelete}) : super(key: key); @override State createState() => _ListUserInGameState(); } class _ListUserInGameState extends State { + @override Widget build(BuildContext context) { return Padding( @@ -367,7 +376,7 @@ class _ListUserInGameState extends State { child: ListView.builder( itemCount: widget.listPlayer.length, itemBuilder: (context, index) { - return UserInGame(player: widget.listPlayer[index]); + return UserInGame(player: widget.listPlayer[index], onDelete: widget.onDelete); }), ), RichText( @@ -392,7 +401,8 @@ class _ListUserInGameState extends State { class UserInGame extends StatefulWidget { final Player player; - const UserInGame({Key? key, required this.player}) : super(key: key); + final Function(Player) onDelete; + const UserInGame({Key? key, required this.player, required this.onDelete}) : super(key: key); @override State createState() => _UserInGameState(); @@ -431,7 +441,7 @@ class _UserInGameState extends State { ? Material( surfaceTintColor: Colors.transparent, child: SizedBox( - width: 230, + width: 220, child: TextField( controller: userNameTextField, style: const TextStyle(color: Colors.black), @@ -448,14 +458,25 @@ class _UserInGameState extends State { ), ), ) - : Text( + : SizedBox( + width: 220, + child: Text( widget.player.name, style: GoogleFonts.roboto( fontSize: 18, decoration: TextDecoration.none, - color: Color(0xff241E40)), + color: Color(0xff241E40)) + ), ), - Spacer(), + (widget.player is User && (widget.player as User).id == MyApp.controller.userCurrent.id) ? + Icon(Icons.lock, color: Colors.amber) : + GestureDetector( + onTap: () { + widget.onDelete(widget.player); + }, + child: Icon(Icons.close) + ), + Spacer() ], ), ); -- 2.36.3 From 316eda5ef64d5f6c245e70e20ae2d89741f31c74 Mon Sep 17 00:00:00 2001 From: "arthur.valin" Date: Mon, 20 Mar 2023 19:36:08 +0100 Subject: [PATCH 8/9] Computing ID and correcting bugs with ScoreBoard modal --- Sources/bowlin_project/lib/config/app_router.dart | 2 +- Sources/bowlin_project/lib/model/GamePlayer.dart | 8 ++++++++ Sources/bowlin_project/lib/model/IGameManager.dart | 1 + Sources/bowlin_project/lib/model/IManager.dart | 2 +- .../bowlin_project/lib/model/StubManager/GameManager.dart | 5 +++++ Sources/bowlin_project/lib/views/ingame_screen.dart | 5 ++--- Sources/bowlin_project/lib/widgets/ingame_widgets.dart | 6 +++--- 7 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Sources/bowlin_project/lib/config/app_router.dart b/Sources/bowlin_project/lib/config/app_router.dart index 9106c04..1bc45be 100644 --- a/Sources/bowlin_project/lib/config/app_router.dart +++ b/Sources/bowlin_project/lib/config/app_router.dart @@ -51,7 +51,7 @@ final GoRouter router = GoRouter( GoRoute( path: 'scoreboard', builder: (BuildContext context, GoRouterState state) { - return FinalScoreBoard(gameDeatil: state.extra as GameDetail); + return FinalScoreBoard(gameDetail: state.extra as GameDetail); }, ), ], diff --git a/Sources/bowlin_project/lib/model/GamePlayer.dart b/Sources/bowlin_project/lib/model/GamePlayer.dart index efab5d1..8deb5c6 100644 --- a/Sources/bowlin_project/lib/model/GamePlayer.dart +++ b/Sources/bowlin_project/lib/model/GamePlayer.dart @@ -1,3 +1,4 @@ +import 'package:bowl_in/model/IManager.dart'; import 'package:flutter/cupertino.dart'; import 'GameDetail.dart'; @@ -7,8 +8,11 @@ import 'Round.dart'; class GamePlayer { late GameDetail _game; + final IManager _parent; int currentRoundIndex = 0; + GamePlayer(this._parent); + GameDetail get game => _game; set game(GameDetail value) { @@ -23,6 +27,10 @@ class GamePlayer { } if (currentRoundIndex >= game.rounds.length) { print("FINISHED"); + + game.id=_parent.gameMgr.getNextId(); + _parent.gameMgr.addGame(game); + game.computeScores(); context.go("/scoreboard", extra: game); } else { diff --git a/Sources/bowlin_project/lib/model/IGameManager.dart b/Sources/bowlin_project/lib/model/IGameManager.dart index 175cf32..6040d3c 100644 --- a/Sources/bowlin_project/lib/model/IGameManager.dart +++ b/Sources/bowlin_project/lib/model/IGameManager.dart @@ -10,5 +10,6 @@ abstract class IGameManager { List getGamesByPlayers(List users); List getPlayersByIdGame(int id); Map getRankByIdGame(int id); + int getNextId(); addGame(GameDetail gd); } diff --git a/Sources/bowlin_project/lib/model/IManager.dart b/Sources/bowlin_project/lib/model/IManager.dart index 5adb82f..00ecb8c 100644 --- a/Sources/bowlin_project/lib/model/IManager.dart +++ b/Sources/bowlin_project/lib/model/IManager.dart @@ -10,7 +10,7 @@ import 'Game.dart'; abstract class IManager { late User _userCurrent; late GameDetail _gameCurrent; - late GamePlayer _gamePlayer = GamePlayer(); + late GamePlayer _gamePlayer = GamePlayer(this); late IUserManager _userMgr; late IGameManager _gameMgr; diff --git a/Sources/bowlin_project/lib/model/StubManager/GameManager.dart b/Sources/bowlin_project/lib/model/StubManager/GameManager.dart index 13f3630..511acaf 100644 --- a/Sources/bowlin_project/lib/model/StubManager/GameManager.dart +++ b/Sources/bowlin_project/lib/model/StubManager/GameManager.dart @@ -86,4 +86,9 @@ class GameManager extends IGameManager { addGame(GameDetail gd) { parent.gameDetails.add(gd); } + + @override + int getNextId() { + return parent.gameDetails.length; + } } diff --git a/Sources/bowlin_project/lib/views/ingame_screen.dart b/Sources/bowlin_project/lib/views/ingame_screen.dart index eb128dd..6a47b3c 100644 --- a/Sources/bowlin_project/lib/views/ingame_screen.dart +++ b/Sources/bowlin_project/lib/views/ingame_screen.dart @@ -58,17 +58,16 @@ class _InGameScreenState extends State { ElevatedButton( onPressed: () { GameDetail gd = GameDetail( - 1, + -1, DateTime.now(), null, - 123, + 0, false, MyApp.controller.userCurrent.id, listPlayers); MyApp.controller.gamePlayer.game = gd; MyApp.controller.gameCurrent = gd; MyApp.controller.gamePlayer.onNext(false, context); - MyApp.controller.gameMgr.addGame(gd); }, child: Text( "PLAY", diff --git a/Sources/bowlin_project/lib/widgets/ingame_widgets.dart b/Sources/bowlin_project/lib/widgets/ingame_widgets.dart index 2a948a8..2ebdfb6 100644 --- a/Sources/bowlin_project/lib/widgets/ingame_widgets.dart +++ b/Sources/bowlin_project/lib/widgets/ingame_widgets.dart @@ -15,8 +15,8 @@ import '../model/Player.dart'; import '../model/User.dart'; class FinalScoreBoard extends StatefulWidget { - final GameDetail gameDeatil; - const FinalScoreBoard({Key? key, required this.gameDeatil}) : super(key: key); + final GameDetail gameDetail; + const FinalScoreBoard({Key? key, required this.gameDetail}) : super(key: key); @override State createState() => _FinalScoreBoardState(); @@ -28,7 +28,7 @@ class _FinalScoreBoardState extends State { late List scoreList; @override void initState() { - rank = widget.gameDeatil.getRank(); + rank = widget.gameDetail.getRank(); pseudoList = rank.keys.toList(); scoreList = rank.values.toList(); super.initState(); -- 2.36.3 From b8b67380c1dcb4d0b56e771c04b246b97439786e Mon Sep 17 00:00:00 2001 From: "arthur.valin" Date: Mon, 20 Mar 2023 20:09:17 +0100 Subject: [PATCH 9/9] Adding reordering on game creation --- .../lib/widgets/ingame_widgets.dart | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/Sources/bowlin_project/lib/widgets/ingame_widgets.dart b/Sources/bowlin_project/lib/widgets/ingame_widgets.dart index 2ebdfb6..8b9cf57 100644 --- a/Sources/bowlin_project/lib/widgets/ingame_widgets.dart +++ b/Sources/bowlin_project/lib/widgets/ingame_widgets.dart @@ -266,10 +266,22 @@ class _InGameCardConfigState extends State { void onDelete(Player p){ setState(() { + widget.listPlayer.remove(p); }); } + void onReorder(int oldIndex, int newIndex){ + setState(() { + + if (oldIndex < newIndex) { + newIndex -= 1; + } + final Player item = widget.listPlayer.removeAt(oldIndex); + widget.listPlayer.insert(newIndex, item); + }); + } + @override Widget build(BuildContext context) { return Container( @@ -313,7 +325,7 @@ class _InGameCardConfigState extends State { ], ), )), - ListUserInGame(listPlayer: widget.listPlayer, onDelete: onDelete), + ListUserInGame(listPlayer: widget.listPlayer, onDelete: onDelete, onReorder: onReorder,), Spacer(), Image( image: AssetImage("assets/images/start_sentence.png"), @@ -354,7 +366,8 @@ class _InGameCardConfigState extends State { class ListUserInGame extends StatefulWidget { final List listPlayer; final Function(Player) onDelete; - const ListUserInGame({Key? key, required this.listPlayer, required this.onDelete}) : super(key: key); + final Function(int, int) onReorder; + const ListUserInGame({Key? key, required this.listPlayer, required this.onDelete, required this.onReorder}) : super(key: key); @override State createState() => _ListUserInGameState(); @@ -373,11 +386,13 @@ class _ListUserInGameState extends State { constraints: new BoxConstraints( maxHeight: 170, ), - child: ListView.builder( - itemCount: widget.listPlayer.length, + child: ReorderableListView.builder( + itemCount: widget.listPlayer.length, itemBuilder: (context, index) { - return UserInGame(player: widget.listPlayer[index], onDelete: widget.onDelete); - }), + return UserInGame(key:ValueKey(widget.listPlayer[index]) ,player: widget.listPlayer[index], onDelete: widget.onDelete, index: index); + }, + onReorder: widget.onReorder, + ), ), RichText( text: TextSpan( @@ -402,7 +417,8 @@ class _ListUserInGameState extends State { class UserInGame extends StatefulWidget { final Player player; final Function(Player) onDelete; - const UserInGame({Key? key, required this.player, required this.onDelete}) : super(key: key); + final int index; + const UserInGame({Key? key, required this.player, required this.onDelete, required this.index}) : super(key: key); @override State createState() => _UserInGameState(); @@ -425,7 +441,9 @@ class _UserInGameState extends State { ), child: Row( children: [ - Container( + ReorderableDragStartListener( + index: widget.index, + child : Container( width: 30, height: 30, decoration: BoxDecoration( @@ -434,6 +452,7 @@ class _UserInGameState extends State { image: AssetImage(widget.player.image), fit: BoxFit.cover), ), ), + ), SizedBox( width: 10, ), -- 2.36.3