Refactoring & toString method added

This commit is contained in:
Felix Kirchner
2025-05-01 13:06:49 +02:00
parent 6ad69671db
commit cd6931093e
5 changed files with 24 additions and 18 deletions

View File

@@ -3,7 +3,7 @@ import 'package:cabo_counter/data/round.dart';
/// This class represents a game session for Cabo game.
/// [createdAt] is the timestamp of when the game session was created.
/// [gameTitle] is the title of the game.
/// [gameHasPointLimit] is a boolean indicating if the game has the default
/// [isPointsLimitEnabled] is a boolean indicating if the game has the default
/// point limit of 101 points or not.
/// [players] is a string list of player names.
/// [playerScores] is a list of the summed scores of all players.
@@ -13,7 +13,7 @@ import 'package:cabo_counter/data/round.dart';
class GameSession {
final DateTime createdAt = DateTime.now();
final String gameTitle;
final bool gameHasPointLimit;
final bool isPointsLimitEnabled;
final List<String> players;
late List<int> playerScores;
List<Round> roundList = [];
@@ -23,16 +23,16 @@ class GameSession {
GameSession({
required this.gameTitle,
required this.gameHasPointLimit,
required this.isPointsLimitEnabled,
required this.players,
}) {
playerScores = List.filled(players.length, 0);
}
@override
String toString() {
toString() {
return ('GameSession: [createdAt: $createdAt, gameTitle: $gameTitle, '
'gameHasPointLimit: $gameHasPointLimit, players: $players, '
'isPointsLimitEnabled: $isPointsLimitEnabled, players: $players, '
'playerScores: $playerScores, roundList: $roundList, '
'roundNumber: $roundNumber, isGameFinished: $isGameFinished, '
'winner: $winner]');
@@ -41,7 +41,7 @@ class GameSession {
/// Converts the GameSession object to a JSON map.
Map<String, dynamic> toJson() => {
'gameTitle': gameTitle,
'gameHasPointLimit': gameHasPointLimit,
'gameHasPointLimit': isPointsLimitEnabled,
'players': players,
'playerScores': playerScores,
'roundNumber': roundNumber,
@@ -53,7 +53,7 @@ class GameSession {
/// Creates a GameSession object from a JSON map.
GameSession.fromJson(Map<String, dynamic> json)
: gameTitle = json['gameTitle'],
gameHasPointLimit = json['gameHasPointLimit'],
isPointsLimitEnabled = json['gameHasPointLimit'],
players = List<String>.from(json['players']),
playerScores = List<int>.from(json['playerScores']),
roundNumber = json['roundNumber'],
@@ -208,7 +208,7 @@ class GameSession {
/// the winner.
void updatePoints() {
_sumPoints();
if (gameHasPointLimit) {
if (isPointsLimitEnabled) {
_checkHundredPointsReached();
for (int i = 0; i < playerScores.length; i++) {