rework: ajout plusieurs classes et modification logique

This commit is contained in:
2025-11-08 17:27:35 +01:00
parent e32805bcd6
commit 09302dd880
8 changed files with 256 additions and 139 deletions

70
src/Dashboard.java Normal file
View File

@@ -0,0 +1,70 @@
import java.awt.Color;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.function.Function;
import java.util.function.Supplier;
import javax.swing.JButton;
import javax.swing.JLabel;
/**
* bouton en bas, couleur choisi de la fenetre
* affiche: carburant restant et tour de piste
*/
public class Dashboard extends GameView
{
private final JLabel label;
private final JButton button;
private final Car car;
public Dashboard(Car car, String title, Supplier<Boolean> fn, Color bg, int width, int height, int x, int y)
{
super("Dashboard: " + title, width, height, x, y);
this.car = car;
this.label = new JLabel();
this.button = new JButton();
// ajout background
super.window.setBackground(bg);
init(fn);
super.window.add(label);
super.window.add(button);
}
// fonction uniquement pour l'affichage dynamique
public void updateButtonText(boolean isPaused)
{
button.setText(isPaused ? "En Pause" : "En Cours");
}
private void init(Supplier<Boolean> fn)
{
// de base, le jeu est en cours
updateButtonText(false);
// classe pour le bouton
MouseAdapter ma = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e)
{
fn.get();
}
};
this.button.addMouseListener(ma);
}
@Override
public void run()
{
label.setText(
"<html><table><tr><td>Carburant Restant: " + car.getFuel()
+ "</td></tr><tr><td>Nombre de Tour: " + car.getRound()
+ "</td></tr></table></html>"
);
}
}