mirror of
https://github.com/guezoloic/L3-racing-game.git
synced 2026-03-30 11:56:14 +00:00
feat!: refonte du projet, bug niveau initialisation
This commit is contained in:
@@ -30,7 +30,7 @@ public class BasicCar implements Car {
|
||||
/** Nombre de tours complétés */
|
||||
private int round = 0;
|
||||
/** Nombre de cases dans une boucle (doit être > 0) */
|
||||
private final Map MAP;
|
||||
private Map map;
|
||||
/** Carburant restant */
|
||||
private int fuel = 60;
|
||||
|
||||
@@ -46,7 +46,12 @@ public class BasicCar implements Car {
|
||||
public BasicCar(String name, Color color, Map map) {
|
||||
this.NAME = name;
|
||||
this.COLOR = color;
|
||||
this.MAP = map;
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
public BasicCar(String name, Color color) {
|
||||
this.NAME = name;
|
||||
this.COLOR = color;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,40 +82,6 @@ public class BasicCar implements Car {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return la position actuelle dans la boucle
|
||||
*/
|
||||
public int getPosition() {
|
||||
return pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return le score de la voiture, calculé comme :
|
||||
* (nombre de tours + progression du tour) × 100
|
||||
*/
|
||||
public int getScore() {
|
||||
return (int) ((round + (float) pos / MAP.getPathSize()) * 100);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return le nombre de tours complétés
|
||||
*/
|
||||
public int getRound() {
|
||||
return round;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return le carburant restant
|
||||
*/
|
||||
public int getFuel() {
|
||||
return fuel;
|
||||
}
|
||||
|
||||
/** Retourne l'état courant de la voiture. */
|
||||
public State getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clique sur "Accelerer" : change d'état et retourne un message (si
|
||||
* nécessaire).
|
||||
@@ -175,15 +146,15 @@ public class BasicCar implements Car {
|
||||
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);
|
||||
Point point = map.getPath(pos);
|
||||
Circuit element = map.getElement(point.x, point.y);
|
||||
|
||||
if (hasAccident(element, jump)) {
|
||||
System.out.println(NAME + " a un\taccident");
|
||||
setDamage();
|
||||
return;
|
||||
}
|
||||
round = pos / MAP.getPathSize();
|
||||
round = pos / map.getPathSize();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,6 +174,10 @@ public class BasicCar implements Car {
|
||||
fuel = 0; // sécurité
|
||||
}
|
||||
|
||||
public boolean hasFinished() {
|
||||
return 3 < round;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exécute une "étape" de la voiture : avance d'une position aléatoire et
|
||||
* consomme du carburant.
|
||||
@@ -212,11 +187,11 @@ public class BasicCar implements Car {
|
||||
* </p>
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
public boolean apply() {
|
||||
if (fuel > 0) {
|
||||
move();
|
||||
consumeFuel();
|
||||
}
|
||||
return !hasFinished();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -225,12 +200,39 @@ public class BasicCar implements Car {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return la position actuelle (synonyme de getPosition)
|
||||
* @return la position actuelle dans la boucle
|
||||
*/
|
||||
public int getPos() {
|
||||
public int getPosition() {
|
||||
return pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return le score de la voiture, calculé comme :
|
||||
* (nombre de tours + progression du tour) × 100
|
||||
*/
|
||||
public int getScore() {
|
||||
return (int) ((round + (float) pos / map.getPathSize()) * 100);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return le nombre de tours complétés
|
||||
*/
|
||||
public int getRound() {
|
||||
return round;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return le carburant restant
|
||||
*/
|
||||
public int getFuel() {
|
||||
return fuel;
|
||||
}
|
||||
|
||||
/** Retourne l'état courant de la voiture. */
|
||||
public State getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return la couleur de la voiture
|
||||
*/
|
||||
@@ -244,4 +246,9 @@ public class BasicCar implements Car {
|
||||
public String getName() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMap(Map map) {
|
||||
this.map = map;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user