From 47a1e3cf11a1adda24b5cae2c2c4453b9649c444 Mon Sep 17 00:00:00 2001 From: Lucas Delanier Date: Sat, 18 Mar 2023 14:31:51 +0100 Subject: [PATCH] final scoreboard works well :tada: --- .../bowlin_project/lib/config/app_router.dart | 5 +- .../bowlin_project/lib/model/GameDetail.dart | 24 +- .../bowlin_project/lib/model/GamePlayer.dart | 2 +- .../lib/model/IGameManager.dart | 2 +- .../lib/model/StubManager/GameManager.dart | 2 +- .../lib/widgets/button_new_party.dart | 4 +- .../lib/widgets/ingame_widgets.dart | 244 ++++++++++++------ 7 files changed, 175 insertions(+), 108 deletions(-) diff --git a/Sources/bowlin_project/lib/config/app_router.dart b/Sources/bowlin_project/lib/config/app_router.dart index 7a8e49b..9106c04 100644 --- a/Sources/bowlin_project/lib/config/app_router.dart +++ b/Sources/bowlin_project/lib/config/app_router.dart @@ -1,4 +1,5 @@ import 'package:bowl_in/model/AbstractRound.dart'; +import 'package:bowl_in/model/GameDetail.dart'; import 'package:bowl_in/model/Round.dart'; import 'package:bowl_in/views/ingame_screen2.dart'; import 'package:bowl_in/widgets/button_new_party.dart'; @@ -41,7 +42,7 @@ final GoRouter router = GoRouter( GoRoute( path: 'in-game', builder: (BuildContext context, GoRouterState state) { - if(state.extra is AbstractRound) { + if (state.extra is AbstractRound) { return InGameScreen2(currentRound: state.extra as AbstractRound); } return InGameScreen(); @@ -50,7 +51,7 @@ final GoRouter router = GoRouter( GoRoute( path: 'scoreboard', builder: (BuildContext context, GoRouterState state) { - return FinalScoreBoard(); + return FinalScoreBoard(gameDeatil: state.extra as GameDetail); }, ), ], diff --git a/Sources/bowlin_project/lib/model/GameDetail.dart b/Sources/bowlin_project/lib/model/GameDetail.dart index c5b5f14..a4d1c45 100644 --- a/Sources/bowlin_project/lib/model/GameDetail.dart +++ b/Sources/bowlin_project/lib/model/GameDetail.dart @@ -17,16 +17,9 @@ class GameDetail { List _players = []; // Constructor - GameDetail( - this._id, - this._time, - this._winner, - this._nbPoints, - this._isFinished, - this._host, - this._players){ - - for(int i=1; i<=9; i++){ + GameDetail(this._id, this._time, this._winner, this._nbPoints, + this._isFinished, this._host, this._players) { + for (int i = 1; i <= 9; i++) { players.forEach((element) { this.rounds.add(Round(null, null, 0, element, i)); }); @@ -35,7 +28,6 @@ class GameDetail { players.forEach((element) { this.rounds.add(LastRound(null, null, 0, element, 10, null)); }); - } // Getters and setters @@ -102,14 +94,14 @@ class GameDetail { throw Exception("Player not in the game."); } - Map getRank() { - Map rank = {}; + Map getRank() { + Map rank = {}; for (var player in players) { - rank.addAll({player.id: getPointByPlayerId(player.id)}); + rank.addAll({player: getPointByPlayerId(player.id)}); } - var sortedByKeyMap = Map.fromEntries( + var sortedByValueMap = Map.fromEntries( rank.entries.toList()..sort((e1, e2) => e2.value.compareTo(e1.value))); - return sortedByKeyMap; + return sortedByValueMap; } } diff --git a/Sources/bowlin_project/lib/model/GamePlayer.dart b/Sources/bowlin_project/lib/model/GamePlayer.dart index 03b5489..43f64c7 100644 --- a/Sources/bowlin_project/lib/model/GamePlayer.dart +++ b/Sources/bowlin_project/lib/model/GamePlayer.dart @@ -23,7 +23,7 @@ class GamePlayer { } if (currentRoundIndex >= game.rounds.length) { print("FINISHED"); - context.go("/scoreboard"); + context.go("/scoreboard", extra: game); } else { print("IN GAME : " + currentRoundIndex.toString()); if (game.rounds[currentRoundIndex] is Round) { diff --git a/Sources/bowlin_project/lib/model/IGameManager.dart b/Sources/bowlin_project/lib/model/IGameManager.dart index e761719..0d5f434 100644 --- a/Sources/bowlin_project/lib/model/IGameManager.dart +++ b/Sources/bowlin_project/lib/model/IGameManager.dart @@ -9,5 +9,5 @@ abstract class IGameManager { List getGamesByPlayer(Player user); List getGamesByPlayers(List users); List getPlayersByIdGame(int id); - Map getRankByIdGame(int id); + Map getRankByIdGame(int id); } diff --git a/Sources/bowlin_project/lib/model/StubManager/GameManager.dart b/Sources/bowlin_project/lib/model/StubManager/GameManager.dart index 2a0efff..cbff266 100644 --- a/Sources/bowlin_project/lib/model/StubManager/GameManager.dart +++ b/Sources/bowlin_project/lib/model/StubManager/GameManager.dart @@ -73,7 +73,7 @@ class GameManager extends IGameManager { throw Exception("Game not found."); } - Map getRankByIdGame(int id) { + Map getRankByIdGame(int id) { for (var game in parent.gameDetails) { if (game.id == id) { return game.getRank(); diff --git a/Sources/bowlin_project/lib/widgets/button_new_party.dart b/Sources/bowlin_project/lib/widgets/button_new_party.dart index ef5f5a5..81a6fb4 100644 --- a/Sources/bowlin_project/lib/widgets/button_new_party.dart +++ b/Sources/bowlin_project/lib/widgets/button_new_party.dart @@ -164,7 +164,7 @@ class ScoreBoardModal extends StatelessWidget { child: Stack( alignment: Alignment.topCenter, children: [ - Positioned( + /*Positioned( child: PodiumGameOverWidget( isfirst: 2, pseudo: 'Lucas', @@ -189,7 +189,7 @@ class ScoreBoardModal extends StatelessWidget { ), top: 70, right: 30, - ) + )*/ ], ), )), diff --git a/Sources/bowlin_project/lib/widgets/ingame_widgets.dart b/Sources/bowlin_project/lib/widgets/ingame_widgets.dart index 17b8b25..4624b16 100644 --- a/Sources/bowlin_project/lib/widgets/ingame_widgets.dart +++ b/Sources/bowlin_project/lib/widgets/ingame_widgets.dart @@ -4,118 +4,193 @@ import 'package:bowl_in/widgets/profil_listpodium_widget.dart'; import 'package:bowl_in/widgets/scores_list_widget.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:go_router/go_router.dart'; import 'package:google_fonts/google_fonts.dart'; import '../model/AbstractRound.dart'; +import '../model/GameDetail.dart'; +import '../model/Player.dart'; class FinalScoreBoard extends StatefulWidget { - const FinalScoreBoard({Key? key}) : super(key: key); + final GameDetail gameDeatil; + const FinalScoreBoard({Key? key, required this.gameDeatil}) : super(key: key); @override State createState() => _FinalScoreBoardState(); } class _FinalScoreBoardState extends State { + late Map rank; + late List pseudoList; + late List scoreList; + @override + void initState() { + rank = widget.gameDeatil.getRank(); + pseudoList = rank.keys.toList(); + scoreList = rank.values.toList(); + super.initState(); + } + @override Widget build(BuildContext context) { - return Container( - margin: EdgeInsets.fromLTRB(30, 0, 30, 35), - width: double.infinity, - height: 470, - decoration: BoxDecoration( - image: DecorationImage( - image: AssetImage("assets/images/ingame_cardgame.png"), - fit: BoxFit.fill), - boxShadow: [ - BoxShadow( - color: CupertinoColors.black.withOpacity(0.15), - blurRadius: 10.0, - spreadRadius: 5.0, - ), - ]), - child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [ - Padding( - padding: EdgeInsets.fromLTRB(15, 5, 15, 50), - child: RichText( - text: TextSpan( - style: DefaultTextStyle.of(context).style, - children: [ - TextSpan( - text: 'GAME OVER', - style: GoogleFonts.roboto( - fontSize: 15, - color: CupertinoColors.black, - fontWeight: FontWeight.w900, - decoration: TextDecoration.none)), - ], - ), - )), - Expanded( - 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, - ) + return Stack( + children: [ + Container( + width: MediaQuery.of(context).size.width, + height: MediaQuery.of(context).size.height, + decoration: const BoxDecoration( + gradient: LinearGradient( + begin: Alignment.topLeft, + end: Alignment.bottomRight, + colors: [ + Color(0xff19BDE0), + Color(0xff4A17DC), ], )), - Container( - width: double.infinity, - height: 100, - decoration: BoxDecoration( - image: DecorationImage( - image: AssetImage("assets/images/congrats_background.png"), - fit: BoxFit.cover), + ), + Column( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + SizedBox( + height: 120, ), - ), - Padding( - padding: EdgeInsets.fromLTRB(0, 0, 0, 10), - child: Align( + Container( + margin: EdgeInsets.fromLTRB(30, 0, 30, 35), + width: double.infinity, + height: 470, + decoration: BoxDecoration( + image: DecorationImage( + image: AssetImage("assets/images/ingame_cardgame.png"), + fit: BoxFit.fill), + boxShadow: [ + BoxShadow( + color: CupertinoColors.black.withOpacity(0.15), + blurRadius: 10.0, + spreadRadius: 5.0, + ), + ]), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Padding( + padding: EdgeInsets.fromLTRB(15, 5, 15, 50), + child: RichText( + text: TextSpan( + style: DefaultTextStyle.of(context).style, + children: [ + TextSpan( + text: 'GAME OVER', + style: GoogleFonts.roboto( + fontSize: 15, + color: CupertinoColors.black, + fontWeight: FontWeight.w900, + decoration: TextDecoration.none)), + ], + ), + )), + Expanded( + 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() + ], + )), + Container( + width: double.infinity, + height: 100, + decoration: BoxDecoration( + image: DecorationImage( + image: AssetImage( + "assets/images/congrats_background.png"), + fit: BoxFit.cover), + ), + ), + Padding( + padding: EdgeInsets.fromLTRB(0, 0, 0, 10), + child: Align( + child: Text( + "Play again", + style: GoogleFonts.roboto( + decoration: TextDecoration.none, + color: Colors.grey, + fontWeight: FontWeight.bold, + fontSize: 20), + ), + ), + ) + ])), + Spacer(), + ElevatedButton( + onPressed: () { + context.go("/"); + }, child: Text( - "Play again", + "LEAVE", style: GoogleFonts.roboto( - decoration: TextDecoration.none, - color: Colors.grey, fontWeight: FontWeight.bold, - fontSize: 20), + fontSize: 40, + color: Color(0xff1ABAE0)), + ), + style: ElevatedButton.styleFrom( + side: BorderSide( + width: 7, + color: Color(0xff1ABAE0), + ), + onPrimary: Colors.transparent, + primary: Colors.transparent, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(55), + ), + minimumSize: Size(200, 80), ), ), - ) - ])); + Spacer(), + ], + ) + ], + ); } } class PodiumGameOverWidget extends StatelessWidget { final int isfirst; - final String pseudo; + final Player player; final int score; const PodiumGameOverWidget( {Key? key, required this.isfirst, - required this.pseudo, + required this.player, required this.score}) : super(key: key); @@ -131,8 +206,7 @@ class PodiumGameOverWidget extends StatelessWidget { height: this.isfirst == 1 ? 65 : 50, decoration: BoxDecoration( image: DecorationImage( - image: AssetImage("assets/images/image_user_red.png"), - fit: BoxFit.cover), + image: AssetImage(player.image), fit: BoxFit.cover), borderRadius: BorderRadius.all(Radius.circular(70)), ), ), @@ -151,7 +225,7 @@ class PodiumGameOverWidget extends StatelessWidget { Padding( padding: EdgeInsets.fromLTRB(0, 3, 0, 0), child: Text( - this.pseudo, + this.player.name, style: GoogleFonts.roboto( color: Colors.black, fontWeight: FontWeight.bold,