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

@ -6,7 +6,6 @@ import 'package:go_router/go_router.dart';
import 'Round.dart';
class GamePlayer {
late GameDetail _game;
int currentRoundIndex = 0;
@ -32,14 +31,16 @@ class GamePlayer{
} else {
print("LAST ROUND");
}
context.pushReplacement("/in-game", extra: game.rounds[currentRoundIndex]);
context.pushReplacement("/in-game",
extra: game.rounds[currentRoundIndex]);
}
}
void onSpareOrStrike() {
if (currentRoundIndex < game.rounds.length - game.players.length) {
print("ON SPAREORSTRIKE");
game.rounds[currentRoundIndex].subscribe(game.rounds[currentRoundIndex+game.players.length]);
game.rounds[currentRoundIndex]
.subscribe(game.rounds[currentRoundIndex + game.players.length]);
}
}
}

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

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

Loading…
Cancel
Save