fix: score display
All checks were successful
Linux arm64 / Build (push) Successful in 28s

This commit is contained in:
2025-02-01 12:54:11 +01:00
parent 02089c649b
commit f22debdf5f
6 changed files with 20 additions and 17 deletions

View File

@@ -37,10 +37,10 @@ public class Game {
leaderboard.add(player);
}
public void setPlayerScore(Player player, int newScore) {
player.setScore(newScore);
public void setPlayerRemainingCells(Player player, int newScore) {
player.setRemainingCells(newScore);
Collections.sort(this.leaderboard,
(player1, player2) -> Integer.compare(player1.getScore(), player2.getScore()));
(player1, player2) -> Integer.compare(player1.getRemainingCells(), player2.getRemainingCells()));
}
public void removePlayer(int id) {

View File

@@ -16,11 +16,11 @@ public class Player implements Serializable {
this.score = 0;
}
public int getScore() {
public int getRemainingCells() {
return score;
}
void setScore(int score) {
void setRemainingCells(int score) {
this.score = score;
}

View File

@@ -22,9 +22,12 @@ public class LeaderboardRenderer {
private final ImVec4 cellColorEnemy = new ImVec4(1.0f, 0.0f, 0.0f, 0.5f);
private final int maxPlayersShowed = 2;
private final int emptyCellCount;
public LeaderboardRenderer(Game game, Player player) {
this.game = game;
this.currentPlayer = player;
this.emptyCellCount = game.getDoku().getEmptyCells().size();
}
private void renderRank(int rank) {
@@ -48,7 +51,7 @@ public class LeaderboardRenderer {
ImGui.sameLine();
renderName(player.getPseudo());
ImGui.sameLine();
renderScore(player.getScore());
renderScore(emptyCellCount - player.getRemainingCells());
ImGui.endChild();
ImGui.popStyleColor(3);
}

View File

@@ -21,8 +21,8 @@ public class MultiPlayerCompleteProgress {
public void render() {
Player firstPlayer = game.getLeaderboard().get(0);
ImGui.setCursorPosX(ImGui.getIO().getDisplaySizeX() / 2.0f - progressSize.x / 2.0f);
String progressText = firstPlayer.getPseudo() + " - " + firstPlayer.getScore() + "/" + emptyCellCount;
this.progressBar.render(progressText, progressSize, 1.0f - firstPlayer.getScore() / (float) emptyCellCount);
String progressText = firstPlayer.getPseudo() + " - " + (emptyCellCount - firstPlayer.getRemainingCells()) + "/" + emptyCellCount;
this.progressBar.render(progressText, progressSize, 1.0f - firstPlayer.getRemainingCells() / (float) emptyCellCount);
}
}

View File

@@ -86,7 +86,7 @@ public class ClientConnexion extends Connexion {
public void visitPacket(UpdatePlayerScorePacket packet) {
Player player = this.client.getGame().getPlayerById(packet.getPlayerId());
assert (player != null);
this.client.getGame().setPlayerScore(player, packet.getCellsLeft());
this.client.getGame().setPlayerRemainingCells(player, packet.getCellsLeft());
}
@Override

View File

@@ -63,7 +63,7 @@ public class ServerConnexion extends Connexion {
for (Player p : this.server.getGame().getPlayers().values()) {
if (p.getId() != player.getId()) {
sendPacket(new PlayerJoinPacket(p));
sendPacket(new UpdatePlayerScorePacket(p.getId(), p.getScore()));
sendPacket(new UpdatePlayerScorePacket(p.getId(), p.getRemainingCells()));
}
}
@@ -139,20 +139,20 @@ public class ServerConnexion extends Connexion {
}
if (cell.getSymbolIndex() != Cell.NOSYMBOL && packet.getNewValue() == Cell.NOSYMBOL) {
cell.empty();
this.server.getGame().setPlayerScore(player, player.getScore() + 1);
this.server.broadcastPacket(new UpdatePlayerScorePacket(player.getId(), player.getScore()));
this.server.getGame().setPlayerRemainingCells(player, player.getRemainingCells() + 1);
this.server.broadcastPacket(new UpdatePlayerScorePacket(player.getId(), player.getRemainingCells()));
return;
}
// on rajoute un chiffre à la grille
if (cell.trySetValue(packet.getNewValue())) {
this.server.getGame().setPlayerScore(player, player.getScore() - 1);
this.server.broadcastPacket(new UpdatePlayerScorePacket(player.getId(), player.getScore()));
this.server.getGame().setPlayerRemainingCells(player, player.getRemainingCells() - 1);
this.server.broadcastPacket(new UpdatePlayerScorePacket(player.getId(), player.getRemainingCells()));
}
checkWin();
}
private void checkWin() {
if (this.player.getScore() == 0) {
if (this.player.getRemainingCells() == 0) {
// we don't need to specify the winner since it has to be the first
this.server.broadcastPacket(new EndGamePacket());
this.server.getGame().stopGame();
@@ -162,8 +162,8 @@ public class ServerConnexion extends Connexion {
public void setSudoku(MultiDoku doku) {
this.doku = doku;
assert (player != null);
this.server.getGame().setPlayerScore(player, this.doku.getEmptyCells().size());
this.server.broadcastPacket(new UpdatePlayerScorePacket(player.getId(), player.getScore()));
this.server.getGame().setPlayerRemainingCells(player, this.doku.getEmptyCells().size());
this.server.broadcastPacket(new UpdatePlayerScorePacket(player.getId(), player.getRemainingCells()));
}
}