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