From bf41c6269e167e8691c7c7f1a7bc642f8c8ae5d3 Mon Sep 17 00:00:00 2001 From: Chahrazad650 Date: Sat, 13 Dec 2025 08:00:08 +0100 Subject: [PATCH] =?UTF-8?q?ajout=20des=20actions=20acc=C3=A9l=C3=A9rer/ral?= =?UTF-8?q?lentir=20et=20correction=20de=20la=20condition=20de=20d=C3=A9ra?= =?UTF-8?q?page=20(>=3D)=20(Car)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Car.java | 42 ++++++++++++++++++++++++++++++++++++++++-- src/Dashboard.java | 6 ++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/Car.java b/src/Car.java index d5e1e6d..eb55224 100644 --- a/src/Car.java +++ b/src/Car.java @@ -47,7 +47,7 @@ public class Car { public static enum State { /** * L'état NORMAL du Vehicule avance selon un chiffre au alentour de 1 à 6 cases - * par tour. Il consomme 6 unités de carburant à chaque tour. Si l'on + * par tour. Il consomme 2 unités de carburant à chaque tour. Si l'on * accelere, il passe à l'état BOOST. Si on Rallenti, il passe à l'état LOW. */ // @formatter:off @@ -202,6 +202,44 @@ public class Car { return fuel; } + /** Retourne l'état courant de la voiture. */ + public State getState() { + return state; + } + + /** Clique sur "Accelerer" : change d'état et retourne un message (si nécessaire). */ + public String accelerate() { + // Si endommagée => l'énoncé dit qu'on ne peut pas bouger + if (state.isDamaged()) { + return "Voiture endommagée : impossible d'accélérer"; + } + State next = state.accelerate(); + + // Énoncé : en BOOST, si on accélère encore => message "déjà max" + if (state == State.BOOST && next == State.BOOST) { + return "Déjà à la vitesse maximale"; + } + state = next; + return ""; + } + + /** Clique sur "Rallentir" : change d'état et retourne un message (si nécessaire). */ + public String decelerate() { + if (state.isDamaged()) { + return "Voiture endommagée : impossible de ralentir"; + } + + State next = state.decelerate(); + + // Énoncé : en STOPPED, si on ralentit encore => message "déjà arrêtée" + if (state == State.STOPPED && next == State.STOPPED) { + return "Déjà arrêtée"; + } + + state = next; + return ""; + } + /** * Fait avancer la voiture d'un certain nombre de positions. *

@@ -227,7 +265,7 @@ public class Car { Point point = MAP.getPath(pos); Map.Circuit element = MAP.getElement(point.x, point.y); - if (element.isYRoad() && element.getValue() < jump) { + if (element.isYRoad() && element.getValue() <= jump) { System.out.println(NAME + " a un\taccident"); setDamage(); return; diff --git a/src/Dashboard.java b/src/Dashboard.java index bfd02ee..5e1388a 100644 --- a/src/Dashboard.java +++ b/src/Dashboard.java @@ -54,7 +54,10 @@ public class Dashboard extends GameView { */ public Dashboard(Game game, Car car, String title, int width, int height, int x, int y) { super(game, "Dashboard: " + title, width, height, x, y); + this.car = car; + + // Fond de la fenêtre = couleur de la voiture frame.setBackground(car.getColor()); @@ -64,12 +67,15 @@ public class Dashboard extends GameView { centerPanel.add(infoLabel); centerPanel.add(stateLabel); centerPanel.add(messageLabel); + //pour rendre le panel transparent + centerPanel.setOpaque(false); // ----- Partie boutons ----- JPanel buttonPanel = new JPanel(new GridLayout(1, 3)); buttonPanel.add(decelerateButton); buttonPanel.add(pauseButton); buttonPanel.add(accelerateButton); + setLayout(new BorderLayout()); add(centerPanel, BorderLayout.CENTER);