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(), ), ], ),