From 5a3c893fc81838b2b11cc6d5fcd5926ab6d21012 Mon Sep 17 00:00:00 2001 From: Felix Kirchner Date: Wed, 23 Apr 2025 21:59:36 +0200 Subject: [PATCH] Implementented the < 101 points rule --- lib/data/game_session.dart | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/data/game_session.dart b/lib/data/game_session.dart index 18e9ca9..7f5d788 100644 --- a/lib/data/game_session.dart +++ b/lib/data/game_session.dart @@ -1,5 +1,13 @@ import 'dart:math'; +/// This class represents a game session for the Cabo game. +/// [gameTitle] is the title of the game. +/// [players] is a string list of player names. +/// [gameMode] is an integer representing the game mode. +/// 0 for the 101 points mode, 1 for unlimited +/// [createdAt] is the timestamp of when the game session was created. +/// [round] is the current round number. +/// [finished] is a boolean indicating if the game session is finished. class GameSession { final String gameTitle; final List players; @@ -8,6 +16,7 @@ class GameSession { milliseconds: Random().nextInt( Duration(days: 21).inMilliseconds + 1))); // DEBUG: Random Timestamp int round = 1; + bool finished = false; GameSession({ required this.gameTitle, @@ -73,12 +82,18 @@ class GameSession { /// list and then sums up the points from the second index to the last /// index. It then stores the result in the first index. This method is /// used to update the total points of each player after a round. + /// If a player reaches the 101 points, void sumPoints() { for (int i = 0; i < playerScores.length; i++) { playerScores[i][0] = 0; for (int j = 1; j < playerScores[i].length; j++) { playerScores[i][0] += playerScores[i][j]; } + if (gameMode == 0 && playerScores[i][0] > 101) { + finished = true; + print('${players[i]} hat die 101 Punkte ueberschritten, ' + 'deswegen wurde das Spiel beendet'); + } } } }