Skip to content
Snippets Groups Projects
Commit fe63ef3b authored by EL GAOUAL Zaid's avatar EL GAOUAL Zaid
Browse files

ColorGenerator

parent 815b510c
No related branches found
No related tags found
No related merge requests found
......@@ -5,7 +5,7 @@ import javafx.scene.paint.Color;
public class UniformColorGenerator implements ColorGenerator{
private Color color;
public UniformColorGenerator(Color color){
this.color=color;
this.color=color;
}
public Color nextColor(Cell cell) {
return this.color;
......
......@@ -2,14 +2,31 @@ package model;
import javafx.scene.paint.Color;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
public class UniformExceptOneGenerator implements ColorGenerator {
public Color uniformColor;
public Color exceptionColor;
public int chosen=0;
public UniformExceptOneGenerator(Color uniformColor, Color exceptionColor) {
this.uniformColor=uniformColor;
this.exceptionColor=exceptionColor;
}
@Override
public Color nextColor(Cell cell) {
return null;
if (chosen == 0) {
List<Color> colors = Arrays.asList(uniformColor, exceptionColor);
Random rand = new Random();
Color randomColor = colors.get(rand.nextInt(colors.size()));
if (randomColor == exceptionColor) {
chosen += 1;
}
return randomColor;
} else {
return uniformColor;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment