mirror of
https://github.com/guezoloic/L3-racing-game.git
synced 2026-03-28 19:13:41 +00:00
feat(Rankboard.java): ajout fonction affichage
This commit is contained in:
@@ -1,3 +1,38 @@
|
||||
public class Rankboard {
|
||||
import java.awt.BorderLayout;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
|
||||
public class Rankboard extends GameView
|
||||
{
|
||||
Car[] cars;
|
||||
private final JLabel label;
|
||||
public Rankboard(String title, int width, int height, int x, int y, Car[] cars)
|
||||
{
|
||||
super(title, width, height, x, y);
|
||||
this.cars = cars;
|
||||
this.label = new JLabel();
|
||||
this.add(label, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
private void updateRankText()
|
||||
{
|
||||
Arrays.sort(cars, Comparator.comparingInt(Car::getScore).reversed());
|
||||
StringBuilder s = new StringBuilder();
|
||||
s.append("<html><table><tr><td>Score</td></tr>");
|
||||
for (Car c : cars)
|
||||
{
|
||||
s.append("<tr><td>" + c + ": " + c.getScore() + "%</td></tr>");
|
||||
}
|
||||
s.append("</table></html>");
|
||||
label.setText(s.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void run()
|
||||
{
|
||||
updateRankText();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user