Correcting bugs when computing points
continuous-integration/drone/push Build is failing Details

Arthur_BowlingAlgo
Arthur VALIN 2 years ago
parent 47a1e3cf11
commit f28812bc97

@ -73,6 +73,7 @@ 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);
}

@ -15,6 +15,7 @@ class GameDetail {
int _host;
List<AbstractRound> _rounds = [];
List<Player> _players = [];
final Map<Player, int> _points = {};
// Constructor
GameDetail(this._id, this._time, this._winner, this._nbPoints,
@ -79,29 +80,21 @@ class GameDetail {
_players = value;
}
int getPointByPlayerId(int id) {
int pointPlayer = 0;
for (var player in players) {
if (player.id == id) {
for (var element in rounds) {
if (element.player == player) {
pointPlayer += element.points ?? 0;
}
}
return pointPlayer;
}
Map<Player, int> get points => _points;
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());
}
throw Exception("Player not in the game.");
}
Map<Player, int> getRank() {
Map<Player, int> rank = {};
for (var player in players) {
rank.addAll({player: getPointByPlayerId(player.id)});
}
var sortedByValueMap = Map.fromEntries(
rank.entries.toList()..sort((e1, e2) => e2.value.compareTo(e1.value)));
points.entries.toList()..sort((e1, e2) => e2.value.compareTo(e1.value)));
return sortedByValueMap;
}
}

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

@ -23,7 +23,11 @@ class LastRound extends AbstractRound{
return false;
}else if(secondThrow==null){
secondThrow=val;
return ((firstThrow??0)+(secondThrow??0)<10);
if ((firstThrow??0)+(secondThrow??0)<10){
computePoints();
return true ;
}
return false;
}else if((firstThrow??0)+(secondThrow??0)>=10){
thirdThrow=val;
}

@ -13,8 +13,12 @@ class Round extends AbstractRound{
previousRound?.update(val);
unsubscribePreviousRound();
}
return val==10;
}else if(firstThrow!=10 && secondThrow!=null){
if(val==10){
computePoints();
return true;
}
return false;
}else if(firstThrow!=10 && secondThrow==null){
secondThrow=val;
}
computePoints();
@ -24,7 +28,7 @@ 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);
}

@ -600,15 +600,16 @@ class StrikeButton extends StatelessWidget {
class SpareButton extends StatelessWidget {
final int currentSelected;
final IntCallback onSonChanged;
final int valueToReturn;
const SpareButton(
{Key? key, required this.onSonChanged, required this.currentSelected})
{Key? key, required this.onSonChanged, required this.currentSelected, required this.valueToReturn})
: super(key: key);
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
onSonChanged(10);
onSonChanged(valueToReturn);
},
child: Container(
width: double.infinity,
@ -622,7 +623,7 @@ class SpareButton extends StatelessWidget {
"SPARE !",
style: GoogleFonts.roboto(
color:
currentSelected == 10 ? Colors.pink : CupertinoColors.black,
currentSelected == valueToReturn ? Colors.pink : CupertinoColors.black,
decoration: TextDecoration.none,
fontWeight: FontWeight.w900,
fontStyle: FontStyle.italic,
@ -777,6 +778,7 @@ class _NumberPadState extends State<NumberPad> {
onSonChanged: (int newId) {
updateId(newId);
},
valueToReturn: widget.maxValue,
)
],
);

Loading…
Cancel
Save