mirror of
https://github.com/guezoloic/L3-racing-game.git
synced 2026-03-28 19:13:41 +00:00
feat: ajout couleur comme attribut
This commit is contained in:
17
src/Car.java
17
src/Car.java
@@ -1,3 +1,4 @@
|
||||
import java.awt.Color;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
@@ -10,6 +11,9 @@ public class Car
|
||||
/** Ajout de la classe Random (Evite de le recreer a chaque fois) */
|
||||
private Random rand = new Random();
|
||||
|
||||
/** Couleur de la voiture */
|
||||
private Color color;
|
||||
|
||||
/** Position actuelle dans la boucle (entre 0 et loop inclus) */
|
||||
private int pos = 0;
|
||||
|
||||
@@ -28,9 +32,10 @@ public class Car
|
||||
* @param loop nombre de positions par boucle (doit être > 0)
|
||||
* @throws IllegalArgumentException si {@code loop <= 0}
|
||||
*/
|
||||
public Car(int loop, State state)
|
||||
public Car(int loop, State state, Color color)
|
||||
{
|
||||
this.state = state;
|
||||
this.color = color;
|
||||
|
||||
if (loop <= 0)
|
||||
throw new IllegalArgumentException("loop must be > 0!");
|
||||
@@ -111,4 +116,14 @@ public class Car
|
||||
{
|
||||
return pos;
|
||||
}
|
||||
|
||||
public Color getColor()
|
||||
{
|
||||
return color;
|
||||
}
|
||||
|
||||
public void setColor(Color color)
|
||||
{
|
||||
this.color = color;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user