mirror of
https://github.com/guezoloic/racing-game.git
synced 2026-03-28 18:03:50 +00:00
Ajout de la partie view du projet
This commit is contained in:
47
view/PanneauClassement.java
Normal file
47
view/PanneauClassement.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package view;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.*;
|
||||
import model.*;
|
||||
|
||||
/**
|
||||
* Panneau latéral affichant le classement des voitures.
|
||||
*/
|
||||
public class PanneauClassement extends JPanel {
|
||||
|
||||
private Game jeu;
|
||||
|
||||
public PanneauClassement(Game jeu) {
|
||||
this.jeu = jeu;
|
||||
setPreferredSize(new Dimension(250, 0));
|
||||
}
|
||||
|
||||
public void mettreAJour(Game jeu) {
|
||||
this.jeu = jeu;
|
||||
repaint();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setFont(new Font("Arial", Font.BOLD, 14));
|
||||
g.drawString("🏆 Classement :", 20, 30);
|
||||
|
||||
java.util.List<Car> liste = new ArrayList<>(Arrays.asList(jeu.getCars()));
|
||||
liste.sort(Comparator.comparingInt(Car::getScore).reversed());
|
||||
|
||||
int y = 60;
|
||||
for (int i = 0; i < liste.size(); i++) {
|
||||
Car c = liste.get(i);
|
||||
String medal = switch (i) {
|
||||
case 0 -> "🥇";
|
||||
case 1 -> "🥈";
|
||||
case 2 -> "🥉";
|
||||
default -> "";
|
||||
};
|
||||
g.drawString(medal + " Voiture " + (i + 1) + " - Score : " + c.getScore(), 20, y);
|
||||
y += 25;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user