Added caboPlayerIndex in Round-Class
This commit is contained in:
@@ -82,7 +82,7 @@ class GameSession {
|
||||
}
|
||||
}
|
||||
addRoundScoresToList(
|
||||
roundNum, roundScores, scoreUpdates, kamikazePlayerIndex);
|
||||
roundNum, roundScores, scoreUpdates, 0, kamikazePlayerIndex);
|
||||
}
|
||||
|
||||
/// Checks the scores of the current round and assigns points to the players.
|
||||
@@ -116,7 +116,7 @@ class GameSession {
|
||||
print('${players[caboPlayerIndex]} hat CABO gesagt '
|
||||
'und bekommt 0 Punkte');
|
||||
print('Alle anderen Spieler bekommen ihre Punkte');
|
||||
_assignPoints(roundNum, roundScores, [caboPlayerIndex]);
|
||||
_assignPoints(roundNum, roundScores, caboPlayerIndex, [caboPlayerIndex]);
|
||||
} else {
|
||||
// A player other than the one who said CABO has the fewest points.
|
||||
print('${players[caboPlayerIndex]} hat CABO gesagt, '
|
||||
@@ -125,7 +125,8 @@ class GameSession {
|
||||
for (int i in lowestScoreIndex) {
|
||||
print('${players[i]}: ${roundScores[i]} Punkte');
|
||||
}
|
||||
_assignPoints(roundNum, roundScores, lowestScoreIndex, caboPlayerIndex);
|
||||
_assignPoints(roundNum, roundScores, caboPlayerIndex, lowestScoreIndex,
|
||||
caboPlayerIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,8 +152,9 @@ class GameSession {
|
||||
/// [roundNum] is the number of the current round.
|
||||
/// [roundScores] is the raw list of the scores of all players in the current round.
|
||||
/// [winnerIndex] is the index of the player who receives 5 extra points
|
||||
void _assignPoints(int roundNum, List<int> roundScores, List<int> winnerIndex,
|
||||
[int loserIndex = -1]) {
|
||||
void _assignPoints(int roundNum, List<int> roundScores, int caboPlayerIndex,
|
||||
List<int> winnerIndex,
|
||||
[int? loserIndex]) {
|
||||
/// List of the updates for every player score
|
||||
List<int> scoreUpdates = [...roundScores];
|
||||
print('Folgende Punkte wurden aus der Runde übernommen:');
|
||||
@@ -163,7 +165,7 @@ class GameSession {
|
||||
print('${players[i]} hat gewonnen und bekommt 0 Punkte');
|
||||
scoreUpdates[i] = 0;
|
||||
}
|
||||
if (loserIndex != -1) {
|
||||
if (loserIndex != null) {
|
||||
print('${players[loserIndex]} bekommt 5 Fehlerpunkte');
|
||||
scoreUpdates[loserIndex] += 5;
|
||||
}
|
||||
@@ -172,7 +174,7 @@ class GameSession {
|
||||
print('${players[i]}: ${scoreUpdates[i]}');
|
||||
}
|
||||
print('scoreUpdates: $scoreUpdates, roundScores: $roundScores');
|
||||
addRoundScoresToList(roundNum, roundScores, scoreUpdates);
|
||||
addRoundScoresToList(roundNum, roundScores, scoreUpdates, caboPlayerIndex);
|
||||
}
|
||||
|
||||
/// Sets the scores of the players for a specific round.
|
||||
@@ -181,13 +183,18 @@ class GameSession {
|
||||
/// playerScores. Its important that each index of the [roundScores] list
|
||||
/// corresponds to the index of the player in the [playerScores] list.
|
||||
void addRoundScoresToList(
|
||||
int roundNum, List<int> roundScores, List<int> scoreUpdates,
|
||||
[int? kamikazePlayerIndex]) {
|
||||
int roundNum,
|
||||
List<int> roundScores,
|
||||
List<int> scoreUpdates,
|
||||
int caboPlayerIndex, [
|
||||
int? kamikazePlayerIndex,
|
||||
]) {
|
||||
Round newRound = Round(
|
||||
roundNum: roundNum,
|
||||
caboPlayerIndex: caboPlayerIndex,
|
||||
kamikazePlayerIndex: kamikazePlayerIndex,
|
||||
scores: roundScores,
|
||||
scoreUpdates: scoreUpdates,
|
||||
kamikazePlayerIndex: kamikazePlayerIndex,
|
||||
);
|
||||
if (roundNum > roundList.length) {
|
||||
roundList.add(newRound);
|
||||
|
||||
@@ -9,34 +9,40 @@ import 'package:cabo_counter/data/game_session.dart';
|
||||
/// kamikaze, this value is null.
|
||||
class Round {
|
||||
final int roundNum;
|
||||
final int caboPlayerIndex;
|
||||
final int? kamikazePlayerIndex;
|
||||
final List<int> scores;
|
||||
final List<int> scoreUpdates;
|
||||
final int? kamikazePlayerIndex;
|
||||
|
||||
Round(
|
||||
{required this.roundNum,
|
||||
required this.scores,
|
||||
required this.scoreUpdates,
|
||||
this.kamikazePlayerIndex});
|
||||
Round({
|
||||
required this.roundNum,
|
||||
required this.caboPlayerIndex,
|
||||
this.kamikazePlayerIndex,
|
||||
required this.scores,
|
||||
required this.scoreUpdates,
|
||||
});
|
||||
|
||||
@override
|
||||
toString() {
|
||||
return 'Round $roundNum: scores: $scores, scoreUpdates: $scoreUpdates, '
|
||||
'kamikazePlayerIndex: $kamikazePlayerIndex';
|
||||
return 'Round $roundNum, caboPlayerIndex: $caboPlayerIndex, '
|
||||
'kamikazePlayerIndex: $kamikazePlayerIndex, scores: $scores, '
|
||||
'scoreUpdates: $scoreUpdates, ';
|
||||
}
|
||||
|
||||
/// Converts the Round object to a JSON map.
|
||||
Map<String, dynamic> toJson() => {
|
||||
'roundNum': roundNum,
|
||||
'caboPlayerIndex': caboPlayerIndex,
|
||||
'kamikazePlayerIndex': kamikazePlayerIndex,
|
||||
'scores': scores,
|
||||
'scoreUpdates': scoreUpdates,
|
||||
'kamikazePlayerIndex': kamikazePlayerIndex,
|
||||
};
|
||||
|
||||
/// Creates a Round object from a JSON map.
|
||||
Round.fromJson(Map<String, dynamic> json)
|
||||
: roundNum = json['roundNum'],
|
||||
caboPlayerIndex = json['caboPlayerIndex'],
|
||||
kamikazePlayerIndex = json['kamikazePlayerIndex'],
|
||||
scores = List<int>.from(json['scores']),
|
||||
scoreUpdates = List<int>.from(json['scoreUpdates']),
|
||||
kamikazePlayerIndex = json['kamikazePlayerIndex'];
|
||||
scoreUpdates = List<int>.from(json['scoreUpdates']);
|
||||
}
|
||||
|
||||
@@ -53,6 +53,8 @@ class _RoundViewState extends State<RoundView> {
|
||||
_scoreControllerList[i].text =
|
||||
gameSession.roundList[widget.roundNumber - 1].scores[i].toString();
|
||||
}
|
||||
_caboPlayerIndex =
|
||||
gameSession.roundList[widget.roundNumber - 1].caboPlayerIndex;
|
||||
_kamikazePlayerIndex =
|
||||
gameSession.roundList[widget.roundNumber - 1].kamikazePlayerIndex;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user