Refactoring & toString method added
This commit is contained in:
@@ -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++) {
|
||||
|
||||
@@ -19,6 +19,12 @@ class Round {
|
||||
required this.scoreUpdates,
|
||||
this.kamikazePlayerIndex});
|
||||
|
||||
@override
|
||||
toString() {
|
||||
return 'Round $roundNum: scores: $scores, scoreUpdates: $scoreUpdates, '
|
||||
'kamikazePlayerIndex: $kamikazePlayerIndex';
|
||||
}
|
||||
|
||||
/// Converts the Round object to a JSON map.
|
||||
Map<String, dynamic> toJson() => {
|
||||
'roundNum': roundNum,
|
||||
|
||||
@@ -11,36 +11,36 @@ void main() {
|
||||
Globals.addGameSession(GameSession(
|
||||
gameTitle: 'Spiel am 27.02.2025',
|
||||
players: ['Clara', 'Tobias', 'Yannik', 'Lena', 'Lekaia'],
|
||||
gameHasPointLimit: true));
|
||||
isPointsLimitEnabled: true));
|
||||
Globals.addGameSession(GameSession(
|
||||
gameTitle: 'Freundschaftsrunde',
|
||||
players: ['Felix', 'Jonas', 'Nils'],
|
||||
gameHasPointLimit: false));
|
||||
isPointsLimitEnabled: false));
|
||||
Globals.addGameSession(GameSession(
|
||||
gameTitle: 'Familienabend',
|
||||
players: ['Mama', 'Papa', 'Lisa'],
|
||||
gameHasPointLimit: true,
|
||||
isPointsLimitEnabled: true,
|
||||
));
|
||||
Globals.addGameSession(GameSession(
|
||||
gameTitle: 'Turnier 1. Runde',
|
||||
players: ['Tim', 'Max', 'Sophie', 'Lena'],
|
||||
gameHasPointLimit: false));
|
||||
isPointsLimitEnabled: false));
|
||||
Globals.addGameSession(GameSession(
|
||||
gameTitle: '2 Namen max length',
|
||||
players: ['Heinrich', 'Johannes'],
|
||||
gameHasPointLimit: true));
|
||||
isPointsLimitEnabled: true));
|
||||
Globals.addGameSession(GameSession(
|
||||
gameTitle: '3 Namen max length',
|
||||
players: ['Benjamin', 'Stefanie', 'Wolfgang'],
|
||||
gameHasPointLimit: false));
|
||||
isPointsLimitEnabled: false));
|
||||
Globals.addGameSession(GameSession(
|
||||
gameTitle: '4 Namen max length',
|
||||
players: ['Leonhard', 'Mathilde', 'Bernhard', 'Gerlinde'],
|
||||
gameHasPointLimit: true));
|
||||
isPointsLimitEnabled: true));
|
||||
Globals.addGameSession(GameSession(
|
||||
gameTitle: '5 Namen max length',
|
||||
players: ['Hartmuth', 'Elisabet', 'Rosalind', 'Theresia', 'Karoline'],
|
||||
gameHasPointLimit: false));
|
||||
isPointsLimitEnabled: false));
|
||||
|
||||
runApp(const App());
|
||||
}
|
||||
|
||||
@@ -284,7 +284,7 @@ class _CreateGameState extends State<CreateGame> {
|
||||
GameSession gameSession = GameSession(
|
||||
gameTitle: _gameTitleTextController.text,
|
||||
players: players,
|
||||
gameHasPointLimit: selectedMode!,
|
||||
isPointsLimitEnabled: selectedMode!,
|
||||
);
|
||||
Globals.addGameSession(gameSession);
|
||||
LocalStorageService.saveGameSessions();
|
||||
|
||||
@@ -97,7 +97,7 @@ class _MainMenuViewState extends State<MainMenuView> {
|
||||
style: const TextStyle(fontSize: 14),
|
||||
)
|
||||
: Text(
|
||||
'Modus: ${_translateGameMode(session.gameHasPointLimit)}',
|
||||
'Modus: ${_translateGameMode(session.isPointsLimitEnabled)}',
|
||||
style: const TextStyle(fontSize: 14),
|
||||
),
|
||||
trailing: Row(
|
||||
|
||||
Reference in New Issue
Block a user