Skip to content
Snippets Groups Projects
Commit 701421fa authored by SAIDI Hatim's avatar SAIDI Hatim
Browse files

test

parent d324c2b1
Branches
No related tags found
No related merge requests found
package util;
import javafx.scene.paint.Color;
import model.Cell;
import model.ColorGenerator;
import java.util.List;
public class DistinctColorGenerator implements ColorGenerator {
private List<Color> colors;
private Color defaultcolor;
public DistinctColorGenerator(List<Color>colors,Color defaultcolor){
this.colors = colors;
this.defaultcolor = defaultcolor;
}
@Override
public Color nextColor(Cell cell) {
for(int i = 0;i< colors.size()-1;i++){
for (int j= 0;j<cell.getNeighbours().size()-1;j++){
if(colors.get(i)!= cell.getNeighbours().get(j).getColor()){
return colors.get(i);
}
}
}
return defaultcolor;
}
}
package util;
import model.Cell;
import model.ColorGenerator;
import javafx.scene.paint.Color;
import java.util.List;
import java.util.Random;
public class RandomColorGenerator implements ColorGenerator {
private List<Color> colors;
private Random randomGenerator;
public RandomColorGenerator(List<Color> colors, Random randomGenerator){
this.colors = colors;
this.randomGenerator =randomGenerator;
}
@Override
public Color nextColor(Cell cell) {
return colors.get(randomGenerator.nextInt(colors.size()));
}
}
......@@ -12,10 +12,10 @@ public class RandomUtil {
}
public static <T> T randomElement(T[] elements, Random random){
return elements[random.nextInt(elements.length-1)];
return elements[random.nextInt(elements.length)];
}
public static <T> T randomElement(List<T> elements, Random random){
return elements.get(random.nextInt(elements.size()-1));
return elements.get(random.nextInt(elements.size()));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment