mirror of
https://github.com/guezoloic/racing-game.git
synced 2026-03-31 11:11:38 +00:00
feat: enlever gameview observer et ajout dans l'observer de base
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user