mirror of
https://github.com/guezoloic/L3-racing-game.git
synced 2026-03-31 04:11:33 +00:00
feat!: rework de tout le projet
This commit is contained in:
146
src/model/car/State.java
Normal file
146
src/model/car/State.java
Normal file
@@ -0,0 +1,146 @@
|
||||
package model.car;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public enum State {
|
||||
/**
|
||||
* L'état NORMAL du Vehicule avance selon un chiffre au alentour de 1 à 6 cases
|
||||
* par tour. Il consomme 2 unités de carburant à chaque tour. Si l'on
|
||||
* accelere, il passe à l'état BOOST. Si on Rallenti, il passe à l'état LOW.
|
||||
*/
|
||||
NORMAL(2, 1, 6) {
|
||||
public State accelerate() {
|
||||
return BOOST;
|
||||
}
|
||||
|
||||
public State decelerate() {
|
||||
return LOW;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* L'état BOOST du Vehicule avance selon un chiffre au alentour de 5 à 10 cases
|
||||
* par tour. Il consomme 5 unités de carburant à chaque tour. Si l'on
|
||||
* accelere, il reste sur son état et indique un message sur le tableau de bord.
|
||||
* Si on Rallenti, il passe à l'état LOW.
|
||||
*/
|
||||
BOOST(5, 5, 10) {
|
||||
public State accelerate() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public State decelerate() {
|
||||
return NORMAL;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* L'état LOW du Vehicule avance selon un chiffre au alentour de 1 à 3 cases
|
||||
* par tour. Il consomme 1 unités de carburant à chaque tour. Si l'on
|
||||
* accelere, il passe à l'état NORMAL. Si on Rallenti, il passe à l'état
|
||||
* STOPPED.
|
||||
*/
|
||||
LOW(1, 1, 3) {
|
||||
public State accelerate() {
|
||||
return NORMAL;
|
||||
}
|
||||
|
||||
public State decelerate() {
|
||||
return STOPPED;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* L'état STOPPED du Vehicule n'avance pas. Il consomme aucune unités de
|
||||
* carburant à chaque tour. Si l'on
|
||||
* accelere, il passe à l'état LOW. Si on Rallenti, il reste sur son état et
|
||||
* indique un message sur le tableau de bord.
|
||||
*/
|
||||
STOPPED(0, 0, 0) {
|
||||
public State accelerate() {
|
||||
return LOW;
|
||||
}
|
||||
|
||||
public State decelerate() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int move(int pos, int jump) {
|
||||
return pos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fuelConsumption(int fuel) {
|
||||
return fuel;
|
||||
}
|
||||
},
|
||||
/**
|
||||
* L'état STOPPED du Vehicule n'avance pas. Il consomme aucune unités de
|
||||
* carburant à chaque tour. Il reste immobile.
|
||||
*/
|
||||
DAMAGED(0, 0, 0) {
|
||||
public State accelerate() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public State decelerate() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int move(int pos, int jump) {
|
||||
return pos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fuelConsumption(int fuel) {
|
||||
return fuel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDamaged() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public State onDamageEnd() {
|
||||
return LOW;
|
||||
}
|
||||
};
|
||||
// @formatter:on
|
||||
|
||||
public final int FUELCOST;
|
||||
public final int MAX;
|
||||
public final int MIN;
|
||||
|
||||
private State(int fuelCost, int min, int max) {
|
||||
this.FUELCOST = fuelCost;
|
||||
this.MAX = max + 1;
|
||||
this.MIN = min;
|
||||
}
|
||||
|
||||
public List<Integer> getInterval() {
|
||||
return List.of(MIN, MAX);
|
||||
}
|
||||
|
||||
public int fuelConsumption(int fuel) {
|
||||
return fuel - FUELCOST;
|
||||
}
|
||||
|
||||
public int move(int pos, int jump) {
|
||||
return pos + jump;
|
||||
}
|
||||
|
||||
public boolean isDamaged() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public State onDamageEnd() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public abstract State accelerate();
|
||||
|
||||
public abstract State decelerate();
|
||||
}
|
||||
Reference in New Issue
Block a user