enfin des couleur bien distincte
This commit is contained in:
@@ -11,8 +11,10 @@ import android.view.View;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class FlowFreeView extends View {
|
public class FlowFreeView extends View {
|
||||||
private final Puzzle puzzle;
|
private final Puzzle puzzle;
|
||||||
@@ -20,6 +22,34 @@ public class FlowFreeView extends View {
|
|||||||
private final int[][] board;
|
private final int[][] board;
|
||||||
private final Map<Integer, List<int[]>> paths = new HashMap<>();
|
private final Map<Integer, List<int[]>> paths = new HashMap<>();
|
||||||
|
|
||||||
|
private final Map<Integer, Integer> colorMap = new HashMap<>();//test pour la couleur
|
||||||
|
|
||||||
|
private static final int[] DISTINCT_COLORS = {
|
||||||
|
Color.rgb(255, 0, 0), // Rouge vif
|
||||||
|
Color.rgb(0, 0, 255), // Bleu vif
|
||||||
|
Color.rgb(0, 255, 0), // Vert vif
|
||||||
|
Color.rgb(255, 255, 0), // Jaune vif
|
||||||
|
Color.rgb(255, 0, 255), // Fuchsia / Magenta
|
||||||
|
Color.rgb(0, 255, 255), // Cyan
|
||||||
|
Color.rgb(255, 165, 0), // Orange vif
|
||||||
|
Color.rgb(0, 0, 0), // Noir
|
||||||
|
Color.rgb(255, 255, 255), // Blanc (à éviter sur fond blanc, mais utile en mode sombre)
|
||||||
|
Color.rgb(128, 0, 0), // Bordeaux
|
||||||
|
Color.rgb(0, 128, 0), // Vert foncé
|
||||||
|
Color.rgb(0, 0, 128), // Bleu foncé
|
||||||
|
Color.rgb(128, 128, 0), // Olive
|
||||||
|
Color.rgb(128, 0, 128), // Violet foncé
|
||||||
|
Color.rgb(0, 128, 128), // Teal foncé
|
||||||
|
Color.rgb(255, 105, 180), // Rose
|
||||||
|
Color.rgb(139, 69, 19), // Chocolat
|
||||||
|
Color.rgb(255, 20, 147), // Rose vif
|
||||||
|
Color.rgb(173, 255, 47), // Vert citron
|
||||||
|
Color.rgb(75, 0, 130), // Indigo profond
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private int colorId=0;
|
||||||
private int selectedColor = 0;
|
private int selectedColor = 0;
|
||||||
private int cellSize;
|
private int cellSize;
|
||||||
|
|
||||||
@@ -36,11 +66,17 @@ public class FlowFreeView extends View {
|
|||||||
int row2 = pair[3];
|
int row2 = pair[3];
|
||||||
|
|
||||||
// Crée une couleur id unique pour chaque paire (1, 2, 3, ...)
|
// Crée une couleur id unique pour chaque paire (1, 2, 3, ...)
|
||||||
int colorId = col1 * puzzle.getSize() + row1 + 1;
|
colorId = colorId+ 1;
|
||||||
board[row1][col1] = colorId;
|
board[row1][col1] = colorId;
|
||||||
board[row2][col2] = colorId;
|
board[row2][col2] = colorId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override//test pour calculer cellsize
|
@Override//test pour calculer cellsize
|
||||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||||
super.onSizeChanged(w, h, oldw, oldh);
|
super.onSizeChanged(w, h, oldw, oldh);
|
||||||
@@ -50,6 +86,10 @@ public class FlowFreeView extends View {
|
|||||||
}
|
}
|
||||||
}//fin test cellsize
|
}//fin test cellsize
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDraw(Canvas canvas) {
|
protected void onDraw(Canvas canvas) {
|
||||||
super.onDraw(canvas);
|
super.onDraw(canvas);
|
||||||
@@ -152,9 +192,14 @@ public class FlowFreeView extends View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Attribue une couleur vive et contrastée à chaque identifiant de point
|
||||||
private int getColorForId(int id) {
|
private int getColorForId(int id) {
|
||||||
// Associe une couleur différente à chaque id unique
|
if (!colorMap.containsKey(id)) {
|
||||||
int[] colors = {Color.RED, Color.BLUE, Color.GREEN, Color.MAGENTA, Color.YELLOW, Color.CYAN, Color.DKGRAY, Color.rgb(139, 69, 19)}; // Marron inclus
|
int index = colorMap.size() % DISTINCT_COLORS.length;
|
||||||
return colors[(id - 1) % colors.length];
|
colorMap.put(id, DISTINCT_COLORS[index]);
|
||||||
}
|
}
|
||||||
|
return colorMap.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ public class PuzzleParser {
|
|||||||
|
|
||||||
public static Puzzle parsePuzzle(Context context, String filename) {
|
public static Puzzle parsePuzzle(Context context, String filename) {
|
||||||
AssetManager assetManager = context.getAssets();
|
AssetManager assetManager = context.getAssets();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
InputStream inputStream = assetManager.open("puzzles/" + filename);
|
InputStream inputStream = assetManager.open("puzzles/" + filename);
|
||||||
XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
|
XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
|
||||||
@@ -28,6 +27,8 @@ public class PuzzleParser {
|
|||||||
int[] currentPair = new int[4];
|
int[] currentPair = new int[4];
|
||||||
int pointIndex = 0;
|
int pointIndex = 0;
|
||||||
|
|
||||||
|
int currentColorId=0; //test pour coleur
|
||||||
|
|
||||||
int eventType = parser.getEventType();
|
int eventType = parser.getEventType();
|
||||||
while (eventType != XmlPullParser.END_DOCUMENT) {
|
while (eventType != XmlPullParser.END_DOCUMENT) {
|
||||||
if (eventType == XmlPullParser.START_TAG) {
|
if (eventType == XmlPullParser.START_TAG) {
|
||||||
@@ -45,6 +46,8 @@ public class PuzzleParser {
|
|||||||
pointIndex++;
|
pointIndex++;
|
||||||
if (pointIndex == 2) {
|
if (pointIndex == 2) {
|
||||||
pairs.add(new int[]{currentPair[0], currentPair[1], currentPair[2], currentPair[3]});
|
pairs.add(new int[]{currentPair[0], currentPair[1], currentPair[2], currentPair[3]});
|
||||||
|
|
||||||
|
currentColorId++;
|
||||||
currentPair = new int[4];
|
currentPair = new int[4];
|
||||||
pointIndex = 0;
|
pointIndex = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user