make buttons selectable following scoe of the previous throw
continuous-integration/drone/push Build is failing Details

Arthur_BowlingAlgo
Lucas Delanier 2 years ago
parent 86d6f5afb5
commit ea391fc0e8

@ -5,8 +5,7 @@ import 'package:go_router/go_router.dart';
import 'Round.dart'; import 'Round.dart';
class GamePlayer{ class GamePlayer {
late GameDetail _game; late GameDetail _game;
int currentRoundIndex = 0; int currentRoundIndex = 0;
@ -17,29 +16,31 @@ class GamePlayer{
_game = value; _game = value;
} }
void onNext(bool isRoundFinished, BuildContext context){ void onNext(bool isRoundFinished, BuildContext context) {
if(isRoundFinished){ if (isRoundFinished) {
print("++"); print("++");
currentRoundIndex++; currentRoundIndex++;
} }
if(currentRoundIndex>=game.rounds.length){ if (currentRoundIndex >= game.rounds.length) {
print("FINISHED"); print("FINISHED");
context.go("/scoreboard"); context.go("/scoreboard");
}else{ } else {
print("IN GAME : " + currentRoundIndex.toString()); print("IN GAME : " + currentRoundIndex.toString());
if(game.rounds[currentRoundIndex] is Round){ if (game.rounds[currentRoundIndex] is Round) {
print("ROUND"); print("ROUND");
}else{ } else {
print("LAST ROUND"); print("LAST ROUND");
} }
context.pushReplacement("/in-game", extra: game.rounds[currentRoundIndex]); context.pushReplacement("/in-game",
extra: game.rounds[currentRoundIndex]);
} }
} }
void onSpareOrStrike(){ void onSpareOrStrike() {
if(currentRoundIndex<game.rounds.length-game.players.length){ if (currentRoundIndex < game.rounds.length - game.players.length) {
print("ON SPAREORSTRIKE"); print("ON SPAREORSTRIKE");
game.rounds[currentRoundIndex].subscribe(game.rounds[currentRoundIndex+game.players.length]); game.rounds[currentRoundIndex]
.subscribe(game.rounds[currentRoundIndex + game.players.length]);
} }
} }
} }

@ -20,23 +20,26 @@ class InGameScreen2 extends StatefulWidget {
class _InGameScreen2State extends State<InGameScreen2> { class _InGameScreen2State extends State<InGameScreen2> {
late InGameCardThrow widgetHolder; late InGameCardThrow widgetHolder;
int selectedValue = 0; int selectedValue = 0;
void setSelectedValue(int val){ void setSelectedValue(int val) {
selectedValue=val; selectedValue = val;
} }
void initState() { void initState() {
if (widget.currentRound.firstThrow == null) {
if (widget.currentRound.firstThrow == null) widgetHolder = InGameCardThrow(
widgetHolder = InGameCardThrow(numberThrow: 1, currentRound: numberThrow: 1,
widget.currentRound, setSelectedValue: setSelectedValue); currentRound: widget.currentRound,
else if (widget.currentRound.secondThrow == null) { setSelectedValue: setSelectedValue);
widgetHolder = InGameCardThrow(numberThrow: 2 } else if (widget.currentRound.secondThrow == null) {
, currentRound: widgetHolder = InGameCardThrow(
widget.currentRound, setSelectedValue: setSelectedValue); numberThrow: 2,
currentRound: widget.currentRound,
setSelectedValue: setSelectedValue);
} else { } else {
widgetHolder = InGameCardThrow(numberThrow: 3, currentRound: widgetHolder = InGameCardThrow(
widget.currentRound, setSelectedValue: setSelectedValue); numberThrow: 3,
currentRound: widget.currentRound,
setSelectedValue: setSelectedValue);
} }
super.initState(); super.initState();
@ -44,7 +47,6 @@ class _InGameScreen2State extends State<InGameScreen2> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Stack( return Stack(
children: [ children: [
Container( Container(
@ -70,11 +72,10 @@ class _InGameScreen2State extends State<InGameScreen2> {
Spacer(), Spacer(),
ElevatedButton( ElevatedButton(
onPressed: () { onPressed: () {
bool isFinished = widget.currentRound.computeNext( bool isFinished =
selectedValue widget.currentRound.computeNext(selectedValue);
);
if(widget.currentRound.isSpareOrStrike()){ if (widget.currentRound.isSpareOrStrike()) {
MyApp.controller.gamePlayer.onSpareOrStrike(); MyApp.controller.gamePlayer.onSpareOrStrike();
} }
@ -99,7 +100,6 @@ class _InGameScreen2State extends State<InGameScreen2> {
), ),
minimumSize: Size(200, 80), minimumSize: Size(200, 80),
), ),
), ),
Spacer(), Spacer(),
], ],

@ -350,7 +350,12 @@ class InGameCardThrow extends StatefulWidget {
final int numberThrow; final int numberThrow;
final AbstractRound currentRound; final AbstractRound currentRound;
final Function(int) setSelectedValue; final Function(int) setSelectedValue;
const InGameCardThrow({Key? key, required this.numberThrow, required this.currentRound, required this.setSelectedValue}): super(key: key); const InGameCardThrow(
{Key? key,
required this.numberThrow,
required this.currentRound,
required this.setSelectedValue})
: super(key: key);
@override @override
State<InGameCardThrow> createState() => _InGameCardThrowState(); State<InGameCardThrow> createState() => _InGameCardThrowState();
@ -358,6 +363,19 @@ class InGameCardThrow extends StatefulWidget {
class _InGameCardThrowState extends State<InGameCardThrow> { class _InGameCardThrowState extends State<InGameCardThrow> {
GlobalKey<_NumberPadState> _numberPadKey = GlobalKey(); 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();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -393,9 +411,14 @@ class _InGameCardThrowState extends State<InGameCardThrow> {
fontWeight: FontWeight.w400, fontWeight: FontWeight.w400,
decoration: TextDecoration.none)), decoration: TextDecoration.none)),
TextSpan( TextSpan(
text: widget.currentRound.number.toString() + " - " + text: widget.currentRound.number.toString() +
widget.numberThrow.toString()+ " - " +
(widget.numberThrow==1 ? "st" : widget.numberThrow==2? "nd" : "rd"),//'1 - 1st', widget.numberThrow.toString() +
(widget.numberThrow == 1
? "st"
: widget.numberThrow == 2
? "nd"
: "rd"), //'1 - 1st',
style: GoogleFonts.roboto( style: GoogleFonts.roboto(
fontSize: 18, fontSize: 18,
color: CupertinoColors.black, color: CupertinoColors.black,
@ -424,7 +447,8 @@ class _InGameCardThrowState extends State<InGameCardThrow> {
NumberPad( NumberPad(
numberThrow: widget.numberThrow, numberThrow: widget.numberThrow,
setSelectedValue: widget.setSelectedValue, setSelectedValue: widget.setSelectedValue,
currentRound: widget.currentRound currentRound: widget.currentRound,
maxValue: maxValue,
), ),
], ],
), ),
@ -539,7 +563,14 @@ class NumberPad extends StatefulWidget {
final int numberThrow; final int numberThrow;
final AbstractRound currentRound; final AbstractRound currentRound;
final Function(int) setSelectedValue; final Function(int) setSelectedValue;
const NumberPad({Key? key, required this.numberThrow, required this.setSelectedValue, required this.currentRound}) : super(key: key); final int maxValue;
const NumberPad(
{Key? key,
required this.numberThrow,
required this.setSelectedValue,
required this.currentRound,
required this.maxValue})
: super(key: key);
@override @override
State<NumberPad> createState() => _NumberPadState(); State<NumberPad> createState() => _NumberPadState();
@ -576,7 +607,7 @@ class _NumberPadState extends State<NumberPad> {
Number( Number(
currentSelected: NumSelected, currentSelected: NumSelected,
num: 1, num: 1,
isSelectable: 1, isSelectable: widget.maxValue > 1 ? 1 : 0,
onSonChanged: (int newId) { onSonChanged: (int newId) {
updateId(newId); updateId(newId);
}, },
@ -584,7 +615,7 @@ class _NumberPadState extends State<NumberPad> {
Number( Number(
currentSelected: NumSelected, currentSelected: NumSelected,
num: 2, num: 2,
isSelectable: 1, isSelectable: widget.maxValue > 2 ? 1 : 0,
onSonChanged: (int newId) { onSonChanged: (int newId) {
updateId(newId); updateId(newId);
}, },
@ -592,7 +623,7 @@ class _NumberPadState extends State<NumberPad> {
Number( Number(
currentSelected: NumSelected, currentSelected: NumSelected,
num: 3, num: 3,
isSelectable: 1, isSelectable: widget.maxValue > 3 ? 1 : 0,
onSonChanged: (int newId) { onSonChanged: (int newId) {
updateId(newId); updateId(newId);
}, },
@ -605,7 +636,7 @@ class _NumberPadState extends State<NumberPad> {
Number( Number(
currentSelected: NumSelected, currentSelected: NumSelected,
num: 4, num: 4,
isSelectable: 1, isSelectable: widget.maxValue > 4 ? 1 : 0,
onSonChanged: (int newId) { onSonChanged: (int newId) {
updateId(newId); updateId(newId);
}, },
@ -613,7 +644,7 @@ class _NumberPadState extends State<NumberPad> {
Number( Number(
currentSelected: NumSelected, currentSelected: NumSelected,
num: 5, num: 5,
isSelectable: 1, isSelectable: widget.maxValue > 5 ? 1 : 0,
onSonChanged: (int newId) { onSonChanged: (int newId) {
updateId(newId); updateId(newId);
}, },
@ -621,7 +652,7 @@ class _NumberPadState extends State<NumberPad> {
Number( Number(
currentSelected: NumSelected, currentSelected: NumSelected,
num: 6, num: 6,
isSelectable: 1, isSelectable: widget.maxValue > 6 ? 1 : 0,
onSonChanged: (int newId) { onSonChanged: (int newId) {
updateId(newId); updateId(newId);
}, },
@ -634,7 +665,7 @@ class _NumberPadState extends State<NumberPad> {
Number( Number(
currentSelected: NumSelected, currentSelected: NumSelected,
num: 7, num: 7,
isSelectable: 1, isSelectable: widget.maxValue > 7 ? 1 : 0,
onSonChanged: (int newId) { onSonChanged: (int newId) {
updateId(newId); updateId(newId);
}, },
@ -642,7 +673,7 @@ class _NumberPadState extends State<NumberPad> {
Number( Number(
currentSelected: NumSelected, currentSelected: NumSelected,
num: 8, num: 8,
isSelectable: 0, isSelectable: widget.maxValue > 8 ? 1 : 0,
onSonChanged: (int newId) { onSonChanged: (int newId) {
updateId(newId); updateId(newId);
}, },
@ -650,7 +681,7 @@ class _NumberPadState extends State<NumberPad> {
Number( Number(
currentSelected: NumSelected, currentSelected: NumSelected,
num: 9, num: 9,
isSelectable: 0, isSelectable: widget.maxValue > 9 ? 1 : 0,
onSonChanged: (int newId) { onSonChanged: (int newId) {
updateId(newId); updateId(newId);
}, },

Loading…
Cancel
Save