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