mirror of
https://github.com/guezoloic/L3-racing-game.git
synced 2026-03-28 19:13:41 +00:00
fix: dashboard et mis GObserver
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseAdapter;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
@@ -18,7 +18,9 @@ public class Dashboard extends GameView
|
|||||||
private final JButton button;
|
private final JButton button;
|
||||||
private final Car car;
|
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);
|
super("Dashboard: " + title, width, height, x, y);
|
||||||
|
|
||||||
@@ -27,31 +29,31 @@ public class Dashboard extends GameView
|
|||||||
this.button = new JButton();
|
this.button = new JButton();
|
||||||
|
|
||||||
// ajout background
|
// ajout background
|
||||||
super.window.setBackground(bg);
|
setBackground(car.getColor());
|
||||||
|
|
||||||
init(fn);
|
init(fn);
|
||||||
|
|
||||||
super.window.add(label);
|
frame.add(label);
|
||||||
super.window.add(button);
|
frame.add(button);
|
||||||
}
|
}
|
||||||
|
|
||||||
// fonction uniquement pour l'affichage dynamique
|
// fonction uniquement pour l'affichage dynamique
|
||||||
public void updateButtonText(boolean isPaused)
|
private void updateButtonText()
|
||||||
{
|
{
|
||||||
button.setText(isPaused ? "En Pause" : "En Cours");
|
button.setText(isPaused ? "En Pause" : "En Cours");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init(Supplier<Boolean> fn)
|
private void init(Supplier<Boolean> fn)
|
||||||
{
|
{
|
||||||
// de base, le jeu est en cours
|
updateButtonText();
|
||||||
updateButtonText(false);
|
|
||||||
|
|
||||||
// classe pour le bouton
|
// classe pour le bouton
|
||||||
MouseAdapter ma = new MouseAdapter() {
|
MouseAdapter ma = new MouseAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e)
|
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