Replaced emojis with unicode and implemented winner string
This commit is contained in:
@@ -17,13 +17,14 @@ class GameSession {
|
|||||||
Duration(days: 21).inMilliseconds + 1))); // DEBUG: Random Timestamp
|
Duration(days: 21).inMilliseconds + 1))); // DEBUG: Random Timestamp
|
||||||
int round = 1;
|
int round = 1;
|
||||||
bool finished = false;
|
bool finished = false;
|
||||||
|
String winner = '';
|
||||||
|
|
||||||
GameSession({
|
GameSession({
|
||||||
required this.gameTitle,
|
required this.gameTitle,
|
||||||
required this.players,
|
required this.players,
|
||||||
required this.gameMode,
|
required this.gameMode,
|
||||||
});
|
});
|
||||||
List<List<int>> playerScores = List.generate(5, (_) => [0]);
|
List<List<int>> playerScores = List.generate(5, (_) => [0, 0]);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
@@ -45,6 +46,22 @@ class GameSession {
|
|||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _determineWinner() {
|
||||||
|
int score = playerScores[0][0];
|
||||||
|
String lowestPlayer = players[0];
|
||||||
|
for (int i = 0; i < players.length; i++) {
|
||||||
|
print('Player: ${players[i]}, Score: ${playerScores[i][0]}');
|
||||||
|
if (playerScores[i][0] < score) {
|
||||||
|
print(
|
||||||
|
'New lowest player: ${players[i]} - Score: ${playerScores[i][0]}');
|
||||||
|
score = playerScores[i][0];
|
||||||
|
lowestPlayer = players[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print('Der Gewinner ist: $lowestPlayer');
|
||||||
|
winner = lowestPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns a string representation of the scores for a specific round.
|
/// Returns a string representation of the scores for a specific round.
|
||||||
/// The method takes a round number as a parameter and returns a string
|
/// The method takes a round number as a parameter and returns a string
|
||||||
/// containing the name of each player and their corressponding score in
|
/// containing the name of each player and their corressponding score in
|
||||||
@@ -72,7 +89,10 @@ class GameSession {
|
|||||||
/// playerScores. Its important that each index of the [roundScores] list
|
/// playerScores. Its important that each index of the [roundScores] list
|
||||||
/// corresponds to the index of the player in the [playerScores] list.
|
/// corresponds to the index of the player in the [playerScores] list.
|
||||||
void addRoundScoresToScoreList(List<int> roundScores, int roundNumber) {
|
void addRoundScoresToScoreList(List<int> roundScores, int roundNumber) {
|
||||||
|
print('addRoundScoresToScoreList: $roundScores');
|
||||||
for (int i = 0; i < roundScores.length; i++) {
|
for (int i = 0; i < roundScores.length; i++) {
|
||||||
|
print(
|
||||||
|
'i: $i, roundNumber: $roundNumber, playerScores[i].length: ${playerScores[i].length}');
|
||||||
playerScores[i][roundNumber] = (roundScores[i]);
|
playerScores[i][roundNumber] = (roundScores[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,6 +113,7 @@ class GameSession {
|
|||||||
finished = true;
|
finished = true;
|
||||||
print('${players[i]} hat die 101 Punkte ueberschritten, '
|
print('${players[i]} hat die 101 Punkte ueberschritten, '
|
||||||
'deswegen wurde das Spiel beendet');
|
'deswegen wurde das Spiel beendet');
|
||||||
|
_determineWinner();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,10 +74,10 @@ class _ActiveGameViewState extends State<ActiveGameView> {
|
|||||||
title: Text(
|
title: Text(
|
||||||
'Runde ${index + 1}',
|
'Runde ${index + 1}',
|
||||||
),
|
),
|
||||||
trailing:
|
trailing: index + 1 != widget.gameSession.round ||
|
||||||
index + 1 == widget.gameSession.playerScores[0].length
|
widget.gameSession.finished == true
|
||||||
? Text('⏳', style: TextStyle(fontSize: 22))
|
? (Text('\u{2705}', style: TextStyle(fontSize: 22)))
|
||||||
: Text('✅', style: TextStyle(fontSize: 22)),
|
: Text('\u{23F3}', style: TextStyle(fontSize: 22)),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
// ignore: unused_local_variable
|
// ignore: unused_local_variable
|
||||||
final val = await Navigator.push(
|
final val = await Navigator.push(
|
||||||
@@ -105,7 +105,6 @@ class _ActiveGameViewState extends State<ActiveGameView> {
|
|||||||
List<int> _getSortedPlayerIndices() {
|
List<int> _getSortedPlayerIndices() {
|
||||||
List<int> playerIndices =
|
List<int> playerIndices =
|
||||||
List<int>.generate(widget.gameSession.players.length, (index) => index);
|
List<int>.generate(widget.gameSession.players.length, (index) => index);
|
||||||
print('Player Indices: $playerIndices');
|
|
||||||
// Sort the indices based on the summed points
|
// Sort the indices based on the summed points
|
||||||
playerIndices.sort((a, b) {
|
playerIndices.sort((a, b) {
|
||||||
int scoreA = widget.gameSession.playerScores[a][0];
|
int scoreA = widget.gameSession.playerScores[a][0];
|
||||||
@@ -122,17 +121,17 @@ class _ActiveGameViewState extends State<ActiveGameView> {
|
|||||||
switch (index) {
|
switch (index) {
|
||||||
case 0:
|
case 0:
|
||||||
return Text(
|
return Text(
|
||||||
'🥇',
|
'\u{1F947}',
|
||||||
style: TextStyle(fontSize: 22),
|
style: TextStyle(fontSize: 22),
|
||||||
);
|
);
|
||||||
case 1:
|
case 1:
|
||||||
return Text(
|
return Text(
|
||||||
'🥈',
|
'\u{1F948}',
|
||||||
style: TextStyle(fontSize: 22),
|
style: TextStyle(fontSize: 22),
|
||||||
);
|
);
|
||||||
case 2:
|
case 2:
|
||||||
return Text(
|
return Text(
|
||||||
'🥉',
|
'\u{1F949}',
|
||||||
style: TextStyle(fontSize: 22),
|
style: TextStyle(fontSize: 22),
|
||||||
);
|
);
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ class _MainMenuViewState extends State<MainMenuView> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
gameSessionArray.sort((b, a) => a.createdAt.compareTo(b.createdAt));
|
gameSessionArray.sort((b, a) => a.createdAt.compareTo(b.createdAt));
|
||||||
calculateRoundNumbers();
|
|
||||||
|
|
||||||
return CupertinoPageScaffold(
|
return CupertinoPageScaffold(
|
||||||
navigationBar: CupertinoNavigationBar(
|
navigationBar: CupertinoNavigationBar(
|
||||||
@@ -89,8 +88,15 @@ class _MainMenuViewState extends State<MainMenuView> {
|
|||||||
padding: EdgeInsets.symmetric(vertical: 10.0),
|
padding: EdgeInsets.symmetric(vertical: 10.0),
|
||||||
child: CupertinoListTile(
|
child: CupertinoListTile(
|
||||||
title: Text(session.gameTitle),
|
title: Text(session.gameTitle),
|
||||||
subtitle:
|
subtitle: session.finished == true
|
||||||
Text('Modus: ${_translateGameMode(session.gameMode)}'),
|
? Text(
|
||||||
|
'\u{1F947} ${session.winner}',
|
||||||
|
style: TextStyle(fontSize: 14),
|
||||||
|
)
|
||||||
|
: Text(
|
||||||
|
'Modus: ${_translateGameMode(session.gameMode)}',
|
||||||
|
style: TextStyle(fontSize: 14),
|
||||||
|
),
|
||||||
trailing: Row(
|
trailing: Row(
|
||||||
children: [
|
children: [
|
||||||
Text('${session.round}'),
|
Text('${session.round}'),
|
||||||
@@ -102,14 +108,15 @@ class _MainMenuViewState extends State<MainMenuView> {
|
|||||||
Icon(CupertinoIcons.person_2_fill),
|
Icon(CupertinoIcons.person_2_fill),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
onTap: () {
|
onTap: () async {
|
||||||
Navigator.push(
|
final val = await Navigator.push(
|
||||||
context,
|
context,
|
||||||
CupertinoPageRoute(
|
CupertinoPageRoute(
|
||||||
builder: (context) => ActiveGameView(
|
builder: (context) => ActiveGameView(
|
||||||
gameSession: gameSessionArray[index]),
|
gameSession: gameSessionArray[index]),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
setState(() {});
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
},
|
},
|
||||||
@@ -129,10 +136,4 @@ class _MainMenuViewState extends State<MainMenuView> {
|
|||||||
return '-';
|
return '-';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void calculateRoundNumbers() {
|
|
||||||
for (var s in gameSessionArray) {
|
|
||||||
s.round = s.playerScores[0].length;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user