mirror of
https://github.com/guezoloic/L3-racing-game.git
synced 2026-03-30 11:56:14 +00:00
feat: modification et correction decorator voiture
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user