final scoreboard works well 🎉
continuous-integration/drone/push Build is failing Details

Arthur_BowlingAlgo
Lucas Delanier 2 years ago
parent ea391fc0e8
commit 47a1e3cf11

@ -1,4 +1,5 @@
import 'package:bowl_in/model/AbstractRound.dart'; 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/model/Round.dart';
import 'package:bowl_in/views/ingame_screen2.dart'; import 'package:bowl_in/views/ingame_screen2.dart';
import 'package:bowl_in/widgets/button_new_party.dart'; import 'package:bowl_in/widgets/button_new_party.dart';
@ -50,7 +51,7 @@ final GoRouter router = GoRouter(
GoRoute( GoRoute(
path: 'scoreboard', path: 'scoreboard',
builder: (BuildContext context, GoRouterState state) { builder: (BuildContext context, GoRouterState state) {
return FinalScoreBoard(); return FinalScoreBoard(gameDeatil: state.extra as GameDetail);
}, },
), ),
], ],

@ -17,15 +17,8 @@ class GameDetail {
List<Player> _players = []; List<Player> _players = [];
// Constructor // Constructor
GameDetail( GameDetail(this._id, this._time, this._winner, this._nbPoints,
this._id, this._isFinished, this._host, this._players) {
this._time,
this._winner,
this._nbPoints,
this._isFinished,
this._host,
this._players){
for (int i = 1; i <= 9; i++) { for (int i = 1; i <= 9; i++) {
players.forEach((element) { players.forEach((element) {
this.rounds.add(Round(null, null, 0, element, i)); this.rounds.add(Round(null, null, 0, element, i));
@ -35,7 +28,6 @@ class GameDetail {
players.forEach((element) { players.forEach((element) {
this.rounds.add(LastRound(null, null, 0, element, 10, null)); this.rounds.add(LastRound(null, null, 0, element, 10, null));
}); });
} }
// Getters and setters // Getters and setters
@ -102,14 +94,14 @@ class GameDetail {
throw Exception("Player not in the game."); throw Exception("Player not in the game.");
} }
Map<int, int> getRank() { Map<Player, int> getRank() {
Map<int, int> rank = {}; Map<Player, int> rank = {};
for (var player in players) { 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))); rank.entries.toList()..sort((e1, e2) => e2.value.compareTo(e1.value)));
return sortedByKeyMap; return sortedByValueMap;
} }
} }

@ -23,7 +23,7 @@ class GamePlayer {
} }
if (currentRoundIndex >= game.rounds.length) { if (currentRoundIndex >= game.rounds.length) {
print("FINISHED"); print("FINISHED");
context.go("/scoreboard"); context.go("/scoreboard", extra: game);
} else { } else {
print("IN GAME : " + currentRoundIndex.toString()); print("IN GAME : " + currentRoundIndex.toString());
if (game.rounds[currentRoundIndex] is Round) { if (game.rounds[currentRoundIndex] is Round) {

@ -9,5 +9,5 @@ abstract class IGameManager {
List<GameDetail> getGamesByPlayer(Player user); List<GameDetail> getGamesByPlayer(Player user);
List<GameDetail> getGamesByPlayers(List<Player> users); List<GameDetail> getGamesByPlayers(List<Player> users);
List<Player> getPlayersByIdGame(int id); List<Player> getPlayersByIdGame(int id);
Map<int, int> getRankByIdGame(int id); Map<Player, int> getRankByIdGame(int id);
} }

@ -73,7 +73,7 @@ class GameManager extends IGameManager {
throw Exception("Game not found."); throw Exception("Game not found.");
} }
Map<int, int> getRankByIdGame(int id) { Map<Player, int> getRankByIdGame(int id) {
for (var game in parent.gameDetails) { for (var game in parent.gameDetails) {
if (game.id == id) { if (game.id == id) {
return game.getRank(); return game.getRank();

@ -164,7 +164,7 @@ class ScoreBoardModal extends StatelessWidget {
child: Stack( child: Stack(
alignment: Alignment.topCenter, alignment: Alignment.topCenter,
children: [ children: [
Positioned( /*Positioned(
child: PodiumGameOverWidget( child: PodiumGameOverWidget(
isfirst: 2, isfirst: 2,
pseudo: 'Lucas', pseudo: 'Lucas',
@ -189,7 +189,7 @@ class ScoreBoardModal extends StatelessWidget {
), ),
top: 70, top: 70,
right: 30, right: 30,
) )*/
], ],
), ),
)), )),

@ -4,21 +4,57 @@ import 'package:bowl_in/widgets/profil_listpodium_widget.dart';
import 'package:bowl_in/widgets/scores_list_widget.dart'; import 'package:bowl_in/widgets/scores_list_widget.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
import '../model/AbstractRound.dart'; import '../model/AbstractRound.dart';
import '../model/GameDetail.dart';
import '../model/Player.dart';
class FinalScoreBoard extends StatefulWidget { 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 @override
State<FinalScoreBoard> createState() => _FinalScoreBoardState(); State<FinalScoreBoard> createState() => _FinalScoreBoardState();
} }
class _FinalScoreBoardState extends State<FinalScoreBoard> { class _FinalScoreBoardState extends State<FinalScoreBoard> {
late Map<Player, int> rank;
late List<Player> pseudoList;
late List<int> scoreList;
@override
void initState() {
rank = widget.gameDeatil.getRank();
pseudoList = rank.keys.toList();
scoreList = rank.values.toList();
super.initState();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( 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),
],
)),
),
Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
height: 120,
),
Container(
margin: EdgeInsets.fromLTRB(30, 0, 30, 35), margin: EdgeInsets.fromLTRB(30, 0, 30, 35),
width: double.infinity, width: double.infinity,
height: 470, height: 470,
@ -33,7 +69,9 @@ class _FinalScoreBoardState extends State<FinalScoreBoard> {
spreadRadius: 5.0, spreadRadius: 5.0,
), ),
]), ]),
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [ child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding( Padding(
padding: EdgeInsets.fromLTRB(15, 5, 15, 50), padding: EdgeInsets.fromLTRB(15, 5, 15, 50),
child: RichText( child: RichText(
@ -54,32 +92,38 @@ class _FinalScoreBoardState extends State<FinalScoreBoard> {
child: Stack( child: Stack(
alignment: Alignment.topCenter, alignment: Alignment.topCenter,
children: [ children: [
Positioned( rank.length > 1
? Positioned(
child: PodiumGameOverWidget( child: PodiumGameOverWidget(
isfirst: 2, isfirst: 2,
pseudo: 'Lucas', player: pseudoList[1],
score: 123, score: scoreList[1],
), ),
top: 70, top: 70,
left: 30, left: 30,
), )
Positioned( : Container(),
rank.length > 0
? Positioned(
child: PodiumGameOverWidget( child: PodiumGameOverWidget(
isfirst: 1, isfirst: 1,
pseudo: 'Momo', player: pseudoList[0],
score: 160, score: scoreList[0],
), ),
top: 10, top: 10,
), )
Positioned( : Container(),
rank.length > 2
? Positioned(
child: PodiumGameOverWidget( child: PodiumGameOverWidget(
isfirst: 3, isfirst: 3,
pseudo: 'popo', player: pseudoList[2],
score: 110, score: scoreList[2],
), ),
top: 70, top: 70,
right: 30, right: 30,
) )
: Container()
], ],
)), )),
Container( Container(
@ -87,7 +131,8 @@ class _FinalScoreBoardState extends State<FinalScoreBoard> {
height: 100, height: 100,
decoration: BoxDecoration( decoration: BoxDecoration(
image: DecorationImage( image: DecorationImage(
image: AssetImage("assets/images/congrats_background.png"), image: AssetImage(
"assets/images/congrats_background.png"),
fit: BoxFit.cover), fit: BoxFit.cover),
), ),
), ),
@ -104,18 +149,48 @@ class _FinalScoreBoardState extends State<FinalScoreBoard> {
), ),
), ),
) )
])); ])),
Spacer(),
ElevatedButton(
onPressed: () {
context.go("/");
},
child: Text(
"LEAVE",
style: GoogleFonts.roboto(
fontWeight: FontWeight.bold,
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 { class PodiumGameOverWidget extends StatelessWidget {
final int isfirst; final int isfirst;
final String pseudo; final Player player;
final int score; final int score;
const PodiumGameOverWidget( const PodiumGameOverWidget(
{Key? key, {Key? key,
required this.isfirst, required this.isfirst,
required this.pseudo, required this.player,
required this.score}) required this.score})
: super(key: key); : super(key: key);
@ -131,8 +206,7 @@ class PodiumGameOverWidget extends StatelessWidget {
height: this.isfirst == 1 ? 65 : 50, height: this.isfirst == 1 ? 65 : 50,
decoration: BoxDecoration( decoration: BoxDecoration(
image: DecorationImage( image: DecorationImage(
image: AssetImage("assets/images/image_user_red.png"), image: AssetImage(player.image), fit: BoxFit.cover),
fit: BoxFit.cover),
borderRadius: BorderRadius.all(Radius.circular(70)), borderRadius: BorderRadius.all(Radius.circular(70)),
), ),
), ),
@ -151,7 +225,7 @@ class PodiumGameOverWidget extends StatelessWidget {
Padding( Padding(
padding: EdgeInsets.fromLTRB(0, 3, 0, 0), padding: EdgeInsets.fromLTRB(0, 3, 0, 0),
child: Text( child: Text(
this.pseudo, this.player.name,
style: GoogleFonts.roboto( style: GoogleFonts.roboto(
color: Colors.black, color: Colors.black,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,

Loading…
Cancel
Save