mirror of
https://github.com/guezoloic/racing-game.git
synced 2026-03-28 18:03:50 +00:00
fix: dashboard et mis GObserver
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
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;
|
||||
@@ -18,7 +18,9 @@ public class Dashboard extends GameView
|
||||
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)
|
||||
private static boolean isPaused = false;
|
||||
|
||||
public Dashboard(Car car, String title, Supplier<Boolean> fn, int width, int height, int x, int y)
|
||||
{
|
||||
super("Dashboard: " + title, width, height, x, y);
|
||||
|
||||
@@ -27,31 +29,31 @@ public class Dashboard extends GameView
|
||||
this.button = new JButton();
|
||||
|
||||
// ajout background
|
||||
super.window.setBackground(bg);
|
||||
setBackground(car.getColor());
|
||||
|
||||
init(fn);
|
||||
|
||||
super.window.add(label);
|
||||
super.window.add(button);
|
||||
frame.add(label);
|
||||
frame.add(button);
|
||||
}
|
||||
|
||||
// fonction uniquement pour l'affichage dynamique
|
||||
public void updateButtonText(boolean isPaused)
|
||||
private void updateButtonText()
|
||||
{
|
||||
button.setText(isPaused ? "En Pause" : "En Cours");
|
||||
}
|
||||
|
||||
private void init(Supplier<Boolean> fn)
|
||||
{
|
||||
// de base, le jeu est en cours
|
||||
updateButtonText(false);
|
||||
updateButtonText();
|
||||
|
||||
// classe pour le bouton
|
||||
MouseAdapter ma = new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e)
|
||||
{
|
||||
fn.get();
|
||||
isPaused = fn.get();
|
||||
updateButtonText();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
13
src/GObserver.java
Normal file
13
src/GObserver.java
Normal file
@@ -0,0 +1,13 @@
|
||||
@FunctionalInterface
|
||||
/**
|
||||
* L'interface utilisée pour Game.
|
||||
*/
|
||||
public interface GObserver
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @return true si la fonction s'est bien passé sinon false (le programme va se
|
||||
* stopper)
|
||||
*/
|
||||
public boolean apply();
|
||||
}
|
||||
Reference in New Issue
Block a user