mirror of
https://github.com/guezoloic/racing-game.git
synced 2026-03-28 18:03:50 +00:00
rework: ajout plusieurs classes et modification logique
This commit is contained in:
70
src/Dashboard.java
Normal file
70
src/Dashboard.java
Normal 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>"
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user