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