mirror of
https://github.com/guezoloic/L3-racing-game.git
synced 2026-03-28 11:03:41 +00:00
fix: nom etat et ajout fuel
This commit is contained in:
13
src/Car.java
13
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;
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,39 @@
|
||||
public class State
|
||||
{
|
||||
public static enum Status
|
||||
public static enum DriveMode
|
||||
{
|
||||
NORMAL;
|
||||
// <CARBURANT PERDU> <PREMIER INTERVAL> <SECOND INTERVAL>
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user