From ce462efd4f91f7100a1caecd51ffb14561b829bd Mon Sep 17 00:00:00 2001 From: Felix Kirchner Date: Fri, 18 Apr 2025 21:12:56 +0200 Subject: [PATCH] Implemented new version of Kamikaze checkbox --- lib/views/round_view.dart | 79 ++++++++++++++++++++++++++++++--------- 1 file changed, 61 insertions(+), 18 deletions(-) diff --git a/lib/views/round_view.dart b/lib/views/round_view.dart index 14da2ca..8e473b1 100644 --- a/lib/views/round_view.dart +++ b/lib/views/round_view.dart @@ -22,6 +22,8 @@ class _RoundViewState extends State { /// Index of the player who said CABO. int _caboPlayerIndex = 0; + int? _kamikazePlayerIndex; // null = kein Kamikaze, sonst Spielerindex + /// List of booleans that represent whether the kamikaze checkbox is checked /// for a player on that index. late final List _isKamikazeChecked = @@ -92,6 +94,7 @@ class _RoundViewState extends State { child: Text( widget.gameSession.players[index], style: TextStyle( + fontWeight: FontWeight.bold, fontSize: gameSession.players.length > 3 ? 14 : 16), ), @@ -116,7 +119,7 @@ class _RoundViewState extends State { width: 100, child: Center(child: Text('Punkte')), ), - SizedBox(width: 20), + SizedBox(width: 28), SizedBox( width: 70, child: Center(child: Text('Kamikaze')), @@ -172,25 +175,43 @@ class _RoundViewState extends State { controller: _pointControllers[index], placeholder: 'Punkte', textAlign: TextAlign.center, - // 👇 Action-Typ explizit setzen - onSubmitted: (_) => _nextField(index), ), ), - SizedBox(width: 20), - SizedBox( - width: 50, - child: CupertinoCheckbox( - activeColor: Styles.primaryColor, - tristate: false, - value: _isKamikazeChecked[index], - onChanged: (bool? value) { - setState(() { - _isKamikazeChecked[index] = value!; - }); - }, + SizedBox(width: 50), + GestureDetector( + onTap: () { + setState(() { + _kamikazePlayerIndex = + (_kamikazePlayerIndex == index) + ? null + : index; + }); + }, + child: Container( + width: 24, + height: 24, + decoration: BoxDecoration( + shape: BoxShape.circle, + color: _kamikazePlayerIndex == index + ? CupertinoColors.systemRed + : CupertinoColors + .tertiarySystemFill, + border: Border.all( + color: _kamikazePlayerIndex == index + ? CupertinoColors.systemRed + : CupertinoColors.systemGrey, + ), + ), + child: _kamikazePlayerIndex == index + ? Icon( + CupertinoIcons.exclamationmark, + size: 16, + color: CupertinoColors.white) + : null, ), ), + SizedBox(width: 22), ], )))); }, @@ -241,13 +262,17 @@ class _RoundViewState extends State { } /// Checks the scores of the current round and assigns points to the players. - /// There are two possible outcomes of a round: + /// There are three possible outcomes of a round: /// /// **Case 1**
+ /// One player has Kamikaze. This player receives 0 points. Every other player + /// receives 50 points. + /// + /// **Case 2**
/// The player who said CABO has the lowest score. They receive 0 points. /// Every other player gets their round score. /// - /// **Case 2**
+ /// **Case 3**
/// The player who said CABO does not have the lowest score. /// They receive 5 extra points added to their round score. /// Every player with the lowest score gets 0 points. @@ -267,7 +292,12 @@ class _RoundViewState extends State { /// List of the index of the player(s) with the lowest score List lowestScoreIndex = _getLowestScoreIndex(roundScores); // Spieler der CABO gesagt hat, hat am wenigsten Punkte - if (lowestScoreIndex.contains(_caboPlayerIndex)) { + if (_kamikazePlayerIndex != null) { + print('${widget.gameSession.players[_kamikazePlayerIndex!]} hat Kamikaze ' + 'und bekommt 0 Punkte'); + print('Alle anderen Spieler bekommen 50 Punkte'); + _applyKamikaze(_kamikazePlayerIndex!, roundScores); + } else if (lowestScoreIndex.contains(_caboPlayerIndex)) { print('${widget.gameSession.players[_caboPlayerIndex]} hat CABO gesagt ' 'und bekommt 0 Punkte'); print('Alle anderen Spieler bekommen ihre Punkte'); @@ -287,6 +317,19 @@ class _RoundViewState extends State { } } + /// Assigns 50 points to all players except the kamikaze player. + /// [kamikazePlayerIndex] is the index of the kamikaze player. + /// [roundScores] is the list of the scores of all players in the + /// current round. + void _applyKamikaze(int kamikazePlayerIndex, List roundScores) { + for (int i = 0; i < widget.gameSession.players.length; i++) { + if (i != kamikazePlayerIndex) { + roundScores[i] += 50; + } + } + gameSession.addRoundScoresToScoreList(roundScores, widget.roundNumber); + } + /// Assigns points to the players based on the scores of the current round. /// [winnerIndex] is the index of the player(s) who receive 0 points /// [loserIndex] is the index of the player who receives 5 extra points