mirror of
https://github.com/guezoloic/L3-racing-game.git
synced 2026-03-30 11:56:14 +00:00
feat: ajout Menu selection
This commit is contained in:
@@ -122,7 +122,7 @@ public class BasicCar implements Car {
|
||||
state = next;
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fait avancer la voiture d'un certain nombre de positions.
|
||||
* <p>
|
||||
@@ -130,73 +130,78 @@ public class BasicCar implements Car {
|
||||
* incrémenté et
|
||||
* la position revient à zéro.
|
||||
* </p>
|
||||
*
|
||||
* @param move nombre de positions à avancer
|
||||
* @return cette même instance (pour chaînage fluide)
|
||||
*/
|
||||
private void move() {
|
||||
int jump = RANDOM.nextInt(state.MIN, state.MAX);
|
||||
|
||||
for (int i = 0; i < jump; i++) {
|
||||
pos = state.move(pos, movement);
|
||||
|
||||
Point point = map.getPath(pos);
|
||||
Circuit element = map.getElement(point.x, point.y);
|
||||
|
||||
if (hasAccident(element, jump)) {
|
||||
setDamage();
|
||||
return;
|
||||
*
|
||||
* @param move nombre de positions à avancer
|
||||
* @return cette même instance (pour chaînage fluide)
|
||||
*/
|
||||
private void move() {
|
||||
int jump = RANDOM.nextInt(state.MIN, state.MAX);
|
||||
|
||||
for (int i = 0; i < jump; i++) {
|
||||
pos = state.move(pos, movement);
|
||||
|
||||
Point point = map.getPath(pos);
|
||||
Circuit element = map.getElement(point.x, point.y);
|
||||
|
||||
if (hasAccident(element, jump)) {
|
||||
setDamage();
|
||||
return;
|
||||
}
|
||||
round = pos / map.getPathSize();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private boolean hasAccident(Circuit element, int jump) {
|
||||
return element.isYRoad() && element.getValue() <= jump;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Consomme du carburant en fonction de l'état du jeu.
|
||||
*
|
||||
* @return cette même instance pour chaînage
|
||||
*/
|
||||
public void consumeFuel() {
|
||||
fuel = state.fuelConsumption(fuel);
|
||||
if (fuel < 0)
|
||||
fuel = 0; // sécurité
|
||||
}
|
||||
*
|
||||
* @return cette même instance pour chaînage
|
||||
*/
|
||||
public void consumeFuel() {
|
||||
fuel = state.fuelConsumption(fuel);
|
||||
if (fuel < 0)
|
||||
fuel = 0; // sécurité
|
||||
}
|
||||
|
||||
public boolean hasFinished() {
|
||||
return 3 < round;
|
||||
}
|
||||
public boolean hasFinished() {
|
||||
return 3 < round;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exécute une "étape" de la voiture : avance d'une position aléatoire et
|
||||
* consomme du carburant.
|
||||
* <p>
|
||||
* La progression est déterminée par un intervalle aléatoire fourni par l'état
|
||||
* du jeu.
|
||||
* </p>
|
||||
*/
|
||||
@Override
|
||||
public boolean apply() {
|
||||
if (state.isDamaged()) {
|
||||
decreaseDamage();
|
||||
} else if (fuel > 0) {
|
||||
move();
|
||||
if (isConsuming)
|
||||
consumeFuel();
|
||||
}
|
||||
return !hasFinished();
|
||||
/**
|
||||
* Exécute une "étape" de la voiture : avance d'une position aléatoire et
|
||||
* consomme du carburant.
|
||||
* <p>
|
||||
* La progression est déterminée par un intervalle aléatoire fourni par l'état
|
||||
* du jeu.
|
||||
* </p>
|
||||
*/
|
||||
@Override
|
||||
public boolean apply() {
|
||||
if (state.isDamaged()) {
|
||||
decreaseDamage();
|
||||
} else if (fuel > 0) {
|
||||
move();
|
||||
if (isConsuming)
|
||||
consumeFuel();
|
||||
}
|
||||
return !hasFinished();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void consumption(boolean active) {
|
||||
isConsuming = active;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void consumption(boolean active) {
|
||||
isConsuming = active;
|
||||
public Car remove() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reverse(boolean active) {
|
||||
@Override
|
||||
public void reverse(boolean active) {
|
||||
movement = (active) ? -1 : 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user