feat: modification et correction decorator voiture

This commit is contained in:
2025-12-19 10:42:19 +01:00
parent 6c75a5363f
commit 0e32a17c66
5 changed files with 44 additions and 50 deletions

View File

@@ -36,6 +36,8 @@ public class BasicCar implements Car {
private int movement = 1;
private boolean isConsuming = true;
/**
* Construit une nouvelle voiture.
*
@@ -67,14 +69,12 @@ public class BasicCar implements Car {
state = State.DAMAGED;
}
private boolean decreaseDamage() {
private void decreaseDamage() {
if (state.isDamaged()) {
if (--damageRound <= 0) {
state = state.onDamageEnd();
}
return true;
}
return false;
}
public BasicCar setState(State state) {
@@ -134,11 +134,7 @@ public class BasicCar implements Car {
* @param move nombre de positions à avancer
* @return cette même instance (pour chaînage fluide)
*/
public void move() {
if (decreaseDamage()) {
return;
}
private void move() {
int jump = RANDOM.nextInt(state.MIN, state.MAX);
for (int i = 0; i < jump; i++) {
@@ -184,13 +180,21 @@ public class BasicCar implements Car {
*/
@Override
public boolean apply() {
if (fuel > 0) {
if (state.isDamaged()) {
decreaseDamage();
} else if (fuel > 0) {
move();
consumeFuel();
if (isConsuming)
consumeFuel();
}
return !hasFinished();
}
@Override
public void consumption(boolean active) {
isConsuming = active;
}
@Override
public void reverse(boolean active) {
movement = (active) ? -1 : 1;