From c1bc62b879c8de2efcc9d68d844309ef556a3780 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20GUEZO?= Date: Thu, 30 Oct 2025 16:45:13 +0100 Subject: [PATCH 1/2] feat(State.java): ajout classe State (Livrable 2) --- src/State.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/State.java diff --git a/src/State.java b/src/State.java new file mode 100644 index 0000000..890b920 --- /dev/null +++ b/src/State.java @@ -0,0 +1,19 @@ +public class State +{ + public static enum Status + { + NORMAL; + } + + private static Status current = Status.NORMAL; + + public static Status get() + { + return current; + } + + public static void set(Status status) + { + current = status; + } +} From ef30313a2522481aa1b34504666e426129f3f086 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20GUEZO?= Date: Thu, 30 Oct 2025 17:13:51 +0100 Subject: [PATCH 2/2] fix: nom etat et ajout fuel --- src/Car.java | 13 +++++++++++++ src/State.java | 32 ++++++++++++++++++++++++++------ 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/Car.java b/src/Car.java index 7093a91..c3ff178 100644 --- a/src/Car.java +++ b/src/Car.java @@ -13,6 +13,8 @@ public class Car { /** Nombre total de cases dans une boucle (doit ĂȘtre > 0) */ private final int loop; + /** Nombre de fuel restant */ + private int fuel = 60; /** * Construit une nouvelle voiture. @@ -73,4 +75,15 @@ public class Car { { return loop; } + + public int getFuel() + { + return fuel; + } + + public Car consumeFuel() + { + fuel -= State.get().getConsumption(); + return this; + } } \ No newline at end of file diff --git a/src/State.java b/src/State.java index 890b920..315f069 100644 --- a/src/State.java +++ b/src/State.java @@ -1,19 +1,39 @@ public class State { - public static enum Status + public static enum DriveMode { - NORMAL; +// + NORMAL(2, 1, 6); + + private int carbUsed; + private int[] interval; + + private DriveMode(int carbUsed, int fInterval, int sInterval) + { + this.carbUsed = carbUsed; + interval = new int[] {fInterval, sInterval}; + } + + public int getConsumption() + { + return carbUsed; + } + + public int[] getInterval() + { + return interval; + } } - private static Status current = Status.NORMAL; + private static DriveMode current = DriveMode.NORMAL; - public static Status get() + public static DriveMode get() { return current; } - public static void set(Status status) + public static void set(DriveMode DriveMode) { - current = status; + current = DriveMode; } }