feat: enlever gameview observer et ajout dans l'observer de base

This commit is contained in:
2025-11-10 14:54:51 +01:00
parent 72eccbf721
commit f9e1580da5
7 changed files with 95 additions and 114 deletions

View File

@@ -30,10 +30,10 @@ public class Rankboard extends GameView
* @param x Position horizontale de la fenêtre
* @param y Position verticale de la fenêtre
*/
public Rankboard(String title, ArrayList<Car> cars, int width, int height, int x, int y)
public Rankboard(Game game, String title, int width, int height, int x, int y)
{
super(title, width, height, x, y);
this.cars = cars;
super(game, title, width, height, x, y);
this.cars = game.getCars();
this.label = new JLabel();
this.add(label, BorderLayout.CENTER);
}
@@ -47,17 +47,19 @@ public class Rankboard extends GameView
*/
private void updateRankText()
{
// cloner pour de modifier la classe principale
ArrayList<Car> cars_clone = new ArrayList<>(cars);
cars_clone.sort(Comparator.comparingInt(Car::getScore).reversed());
StringBuilder s = new StringBuilder();
s.append("<html><table>");
for (Car c : cars_clone)
for (Car c : cars)
{
s.append("<tr><td>" + c + ": " + c.getScore() + "%</td></tr>");
s.append("<tr><td>" + c.getName() + ": " + c.getScore() + "%</td></tr>");
}
s.append("</table></html>");
System.out.println(s);
label.setText(s.toString());
}
@@ -66,9 +68,9 @@ public class Rankboard extends GameView
* Méthode appelée par GameView.update().
* Elle met à jour le classement affiché.
*/
protected void run()
public boolean apply()
{
updateRankText();
return true;
}
}