Refactored variable & changing limit from 101 to 101
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/// 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.
|
||||
/// [pointLimit] is a boolean indicating if the game has the
|
||||
/// [gameHasPointLimit] is a boolean indicating if the game has the
|
||||
/// default point limit of 101 points or not.
|
||||
/// [createdAt] is the timestamp of when the game session was created.
|
||||
/// [round] is the current round number.
|
||||
@@ -10,7 +10,7 @@
|
||||
class GameSession {
|
||||
final DateTime createdAt = DateTime.now();
|
||||
final String gameTitle;
|
||||
final bool pointLimit;
|
||||
final bool gameHasPointLimit;
|
||||
final List<String> players;
|
||||
List<List<int>> playerScores = List.generate(5, (_) => [0, 0]);
|
||||
int round = 1;
|
||||
@@ -20,14 +20,14 @@ class GameSession {
|
||||
GameSession({
|
||||
required this.gameTitle,
|
||||
required this.players,
|
||||
required this.pointLimit,
|
||||
required this.gameHasPointLimit,
|
||||
});
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return ('GameSession: [gameTitle: $gameTitle, '
|
||||
'players: $players, '
|
||||
'round: $round, pointLimit: $pointLimit, '
|
||||
'round: $round, pointLimit: $gameHasPointLimit, '
|
||||
'playerScores: $playerScores]');
|
||||
}
|
||||
|
||||
@@ -106,9 +106,9 @@ class GameSession {
|
||||
for (int j = 1; j < playerScores[i].length; j++) {
|
||||
playerScores[i][0] += playerScores[i][j];
|
||||
}
|
||||
if (pointLimit && playerScores[i][0] > 101) {
|
||||
if (gameHasPointLimit && playerScores[i][0] > 100) {
|
||||
finished = true;
|
||||
print('${players[i]} hat die 101 Punkte ueberschritten, '
|
||||
print('${players[i]} hat die 100 Punkte ueberschritten, '
|
||||
'deswegen wurde das Spiel beendet');
|
||||
_determineWinner();
|
||||
}
|
||||
|
||||
@@ -131,7 +131,8 @@ class _CreateGameState extends State<CreateGame> {
|
||||
showCupertinoDialog(
|
||||
context: context,
|
||||
builder: (context) => CupertinoAlertDialog(
|
||||
title: const Text('Maximale Spielerzahl erreicht'),
|
||||
title:
|
||||
const Text('Maximale Spielerzahl erreicht'),
|
||||
content: const Text(
|
||||
'Es können maximal 5 Spieler hinzugefügt '
|
||||
'werden.'),
|
||||
@@ -276,7 +277,8 @@ class _CreateGameState extends State<CreateGame> {
|
||||
GameSession gameSession = GameSession(
|
||||
gameTitle: _gameTitleTextController.text,
|
||||
players: players,
|
||||
pointLimit: selectedMode == '101 Pkt.' ? true : false,
|
||||
gameHasPointLimit:
|
||||
selectedMode == '101 Pkt.' ? true : false,
|
||||
);
|
||||
Navigator.push(
|
||||
context,
|
||||
|
||||
@@ -18,36 +18,36 @@ class _MainMenuViewState extends State<MainMenuView> {
|
||||
GameSession(
|
||||
gameTitle: 'Spiel am 27.02.2025',
|
||||
players: ['Clara', 'Tobias', 'Yannik', 'Lena', 'Lekaia'],
|
||||
pointLimit: true),
|
||||
gameHasPointLimit: true),
|
||||
GameSession(
|
||||
gameTitle: 'Freundschaftsrunde',
|
||||
players: ['Felix', 'Jonas', 'Nils'],
|
||||
pointLimit: false),
|
||||
gameHasPointLimit: false),
|
||||
GameSession(
|
||||
gameTitle: 'Familienabend',
|
||||
players: ['Mama', 'Papa', 'Lisa'],
|
||||
pointLimit: true,
|
||||
gameHasPointLimit: true,
|
||||
),
|
||||
GameSession(
|
||||
gameTitle: 'Turnier 1. Runde',
|
||||
players: ['Tim', 'Max', 'Sophie', 'Lena'],
|
||||
pointLimit: false),
|
||||
gameHasPointLimit: false),
|
||||
GameSession(
|
||||
gameTitle: '2 Namen max length',
|
||||
players: ['Heinrich', 'Johannes'],
|
||||
pointLimit: true),
|
||||
gameHasPointLimit: true),
|
||||
GameSession(
|
||||
gameTitle: '3 Namen max length',
|
||||
players: ['Benjamin', 'Stefanie', 'Wolfgang'],
|
||||
pointLimit: false),
|
||||
gameHasPointLimit: false),
|
||||
GameSession(
|
||||
gameTitle: '4 Namen max length',
|
||||
players: ['Leonhard', 'Mathilde', 'Bernhard', 'Gerlinde'],
|
||||
pointLimit: true),
|
||||
gameHasPointLimit: true),
|
||||
GameSession(
|
||||
gameTitle: '5 Namen max length',
|
||||
players: ['Hartmuth', 'Elisabet', 'Rosalind', 'Theresia', 'Karoline'],
|
||||
pointLimit: false),
|
||||
gameHasPointLimit: false),
|
||||
];
|
||||
|
||||
@override
|
||||
@@ -97,7 +97,7 @@ class _MainMenuViewState extends State<MainMenuView> {
|
||||
style: const TextStyle(fontSize: 14),
|
||||
)
|
||||
: Text(
|
||||
'Modus: ${_translateGameMode(session.pointLimit)}',
|
||||
'Modus: ${_translateGameMode(session.gameHasPointLimit)}',
|
||||
style: const TextStyle(fontSize: 14),
|
||||
),
|
||||
trailing: Row(
|
||||
|
||||
Reference in New Issue
Block a user