projet fini achromate marche yesssssssssssss
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
package com.example.flow_free;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.RectF;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
@@ -22,9 +24,10 @@ public class FlowFreeView extends View {
|
||||
private final int[][] board;
|
||||
private final Map<Integer, List<int[]>> paths = new HashMap<>();
|
||||
|
||||
private final Map<Integer, Integer> colorMap = new HashMap<>();//test pour la couleur
|
||||
private final Map<Integer, Integer> colorMap = new HashMap<>();
|
||||
private final Set<Integer> completedColors = new HashSet<>();// liste des chemin fini
|
||||
private boolean win = false;
|
||||
private boolean isAchromate ;
|
||||
|
||||
|
||||
private static final int[] DISTINCT_COLORS = {
|
||||
@@ -35,7 +38,6 @@ public class FlowFreeView extends View {
|
||||
Color.rgb(255, 0, 255), // Fuchsia / Magenta
|
||||
Color.rgb(0, 255, 255), // Cyan
|
||||
Color.rgb(255, 165, 0), // Orange vif
|
||||
|
||||
Color.rgb(128, 0, 0), // Bordeaux
|
||||
Color.rgb(0, 128, 0), // Vert foncé
|
||||
Color.rgb(0, 0, 128), // Bleu foncé
|
||||
@@ -50,11 +52,28 @@ public class FlowFreeView extends View {
|
||||
};
|
||||
|
||||
|
||||
private static final int[] DISTINCT_GRIS = {
|
||||
Color.rgb(0, 0, 0), // Noir
|
||||
Color.rgb(40, 40, 40), // Gris très foncé
|
||||
Color.rgb(80, 80, 80), // Gris foncé
|
||||
Color.rgb(120, 120, 120), // Gris moyen foncé
|
||||
Color.rgb(160, 160, 160), // Gris moyen
|
||||
Color.rgb(200, 200, 200), // Gris moyen clair
|
||||
Color.rgb(220, 220, 220), // Gris clair
|
||||
Color.rgb(240, 240, 240), // Gris très clair
|
||||
Color.rgb(255, 255, 255), // Blanc
|
||||
Color.rgb(25, 25, 25),
|
||||
Color.rgb(55, 55, 55),
|
||||
Color.rgb(95, 95, 95),
|
||||
Color.rgb(135, 135, 135),
|
||||
Color.rgb(175, 175, 175)
|
||||
};
|
||||
|
||||
|
||||
|
||||
private int colorId=0;
|
||||
private int selectedColor = 0;
|
||||
private int cellSize;
|
||||
|
||||
public FlowFreeView(Context context, Puzzle puzzle) {
|
||||
super(context);
|
||||
this.puzzle = puzzle;
|
||||
@@ -66,7 +85,6 @@ public class FlowFreeView extends View {
|
||||
int row1 = pair[1];
|
||||
int col2 = pair[2];
|
||||
int row2 = pair[3];
|
||||
|
||||
// Crée une couleur id unique pour chaque paire (1, 2, 3, ...)
|
||||
colorId = colorId+ 1;
|
||||
board[row1][col1] = colorId;
|
||||
@@ -74,10 +92,7 @@ public class FlowFreeView extends View {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//test
|
||||
private void printBoardToLog() {
|
||||
private void printBoardToLog() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int[] row : board) {
|
||||
for (int cell : row) {
|
||||
@@ -85,9 +100,7 @@ private void printBoardToLog() {
|
||||
}
|
||||
sb.append("\n");
|
||||
}
|
||||
Log.d("DEBUG_FLOW", "Contenu du board :\n" + sb.toString());
|
||||
}
|
||||
//test
|
||||
|
||||
|
||||
@Override//test pour calculer cellsize
|
||||
@@ -95,9 +108,8 @@ private void printBoardToLog() {
|
||||
super.onSizeChanged(w, h, oldw, oldh);
|
||||
if (puzzle != null) {
|
||||
cellSize = Math.min(w, h) / puzzle.getSize();
|
||||
Log.d("DEBUG_FLOW", "cellSize calculé : " + cellSize);
|
||||
}
|
||||
}//fin test cellsize
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -106,18 +118,8 @@ private void printBoardToLog() {
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
Log.d("DEBUG_FLOW", "onDraw() a été appelé !");//debug
|
||||
// --- DEBUG : Affiche le contenu du board dans la console ---
|
||||
StringBuilder boardLog = new StringBuilder("Contenu du board :\n");
|
||||
for (int row = 0; row < puzzle.getSize(); row++) {
|
||||
for (int col = 0; col < puzzle.getSize(); col++) {
|
||||
boardLog.append(String.format("%3d ", board[row][col]));
|
||||
}
|
||||
boardLog.append("\n");
|
||||
}
|
||||
Log.d("DEBUG_FLOW", boardLog.toString());
|
||||
|
||||
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
isAchromate = preferences.getBoolean("achromate_mode", false);
|
||||
paint.setStrokeWidth(4);
|
||||
paint.setStyle(Paint.Style.STROKE);
|
||||
paint.setColor(Color.BLACK);
|
||||
@@ -135,7 +137,7 @@ private void printBoardToLog() {
|
||||
for (int col = 0; col < puzzle.getSize(); col++) {
|
||||
int colorId = board[row][col];
|
||||
if (colorId > 0) { // permet de ne pas dessiner des cercle quand je fais un trait
|
||||
paint.setColor(getColorForId(colorId));
|
||||
paint.setColor(getColorForId(colorId,isAchromate));
|
||||
float cx = col * cellSize + cellSize / 2f;
|
||||
float cy = row * cellSize + cellSize / 2f;
|
||||
canvas.drawCircle(cx, cy, cellSize / 4f, paint);
|
||||
@@ -147,7 +149,7 @@ private void printBoardToLog() {
|
||||
paint.setStrokeWidth(cellSize / 4f);
|
||||
paint.setStyle(Paint.Style.STROKE);
|
||||
for (Map.Entry<Integer, List<int[]>> entry : paths.entrySet()) {
|
||||
paint.setColor(getColorForId(Math.abs(entry.getKey())));
|
||||
paint.setColor(getColorForId(Math.abs(entry.getKey()),isAchromate));
|
||||
List<int[]> path = entry.getValue();
|
||||
for (int i = 0; i < path.size() - 1; i++) {
|
||||
int[] p1 = path.get(i);
|
||||
@@ -227,7 +229,6 @@ private void printBoardToLog() {
|
||||
|
||||
// 2. Vérifie si toutes les paires sont terminées
|
||||
if (completedColors.size() == puzzle.getPairs().size()) {
|
||||
Log.d("DEBUG_FLOW", "🎉 Puzzle résolu !");
|
||||
win = true;
|
||||
invalidate(); // Redessine pour afficher le message
|
||||
}
|
||||
@@ -239,28 +240,18 @@ private void printBoardToLog() {
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
int col = (int) (event.getX() / cellSize);
|
||||
int row = (int) (event.getY() / cellSize);
|
||||
|
||||
if (col < 0 || row < 0 || col >= puzzle.getSize() || row >= puzzle.getSize())
|
||||
return false;
|
||||
|
||||
|
||||
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
|
||||
int colorAtCell = board[row][col];
|
||||
if (colorAtCell > 0) {
|
||||
|
||||
//test
|
||||
clearPath(colorAtCell); // 👈 même fonction de nettoyage
|
||||
selectedColor = colorAtCell;
|
||||
paths.put(selectedColor, new ArrayList<>());
|
||||
paths.get(selectedColor).add(new int[]{row, col});
|
||||
//test
|
||||
|
||||
if (completedColors.contains(colorAtCell)) {// regarde si le chemin qu'on veut tracer est fini
|
||||
// 🔒 Ne pas toucher à un chemin terminé
|
||||
Log.d("DEBUG_FLOW", "Chemin déjà terminé, on ne fait rien.");
|
||||
return true;
|
||||
}
|
||||
selectedColor = colorAtCell;
|
||||
@@ -275,24 +266,6 @@ private void printBoardToLog() {
|
||||
}
|
||||
break;
|
||||
|
||||
/* case MotionEvent.ACTION_MOVE:
|
||||
if (selectedColor != 0) {
|
||||
List<int[]> path = paths.get(selectedColor);
|
||||
int[] last = path.get(path.size() - 1);
|
||||
if (last[0] != row || last[1] != col) {
|
||||
path.add(new int[]{row, col});
|
||||
board[row][col] = selectedColor; // ✅ Met à jour le tableau
|
||||
|
||||
printBoardToLog(); // 🔍 Affiche la grille pendant le tracé
|
||||
}
|
||||
|
||||
}
|
||||
break;*/
|
||||
|
||||
|
||||
|
||||
|
||||
//version chat
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
if (selectedColor != 0) {
|
||||
List<int[]> path = paths.get(selectedColor);
|
||||
@@ -317,7 +290,6 @@ private void printBoardToLog() {
|
||||
// ⚠️ Ne pas revenir au point de départ
|
||||
int[] start = path.get(0);
|
||||
if (row == start[0] && col == start[1]) {
|
||||
Log.d("DEBUG_FLOW", "Tentative de retour au point de départ — refusé.");
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -327,7 +299,6 @@ private void printBoardToLog() {
|
||||
selectedColor = 0;
|
||||
checkWin();
|
||||
invalidate();
|
||||
Log.d("DEBUG_FLOW", "Paire complétée !");
|
||||
}
|
||||
|
||||
// 3️⃣ Reculer sur une case du chemin
|
||||
@@ -338,19 +309,12 @@ private void printBoardToLog() {
|
||||
int[] removed = path.remove(path.size() - 1);
|
||||
board[removed[0]][removed[1]] = 0;
|
||||
invalidate();
|
||||
Log.d("DEBUG_FLOW", "Recul d’une case sur le chemin.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
//version chat
|
||||
|
||||
|
||||
|
||||
|
||||
case MotionEvent.ACTION_UP:
|
||||
selectedColor = 0; // Permet de reprendre à la prochaine touche
|
||||
break;
|
||||
@@ -361,13 +325,24 @@ private void printBoardToLog() {
|
||||
|
||||
|
||||
// Attribue une couleur vive et contrastée à chaque identifiant de point
|
||||
private int getColorForId(int id) {
|
||||
private int getColorForId(int id,boolean achromate) {
|
||||
|
||||
|
||||
if(achromate) {
|
||||
if (!colorMap.containsKey(id)) {
|
||||
int index = colorMap.size() % DISTINCT_GRIS.length;
|
||||
colorMap.put(id, DISTINCT_GRIS[index]);
|
||||
}
|
||||
return colorMap.get(id);
|
||||
}
|
||||
else {
|
||||
if (!colorMap.containsKey(id)) {
|
||||
int index = colorMap.size() % DISTINCT_COLORS.length;
|
||||
colorMap.put(id, DISTINCT_COLORS[index]);
|
||||
}
|
||||
return colorMap.get(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -46,16 +46,8 @@ public class MainActivity extends Activity {
|
||||
puzzleListView.setAdapter(adapter);
|
||||
|
||||
// Click sur un puzzle
|
||||
puzzleListView.setOnItemClickListener((parent, view, position, id) -> {
|
||||
String selectedPuzzle = puzzleList.get(position);
|
||||
if (!selectedPuzzle.endsWith(".xml")) {
|
||||
Toast.makeText(this, "Puzzle invalide", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
Intent intent = new Intent(MainActivity.this, GameActivity.class);
|
||||
intent.putExtra("PUZZLE_FILE", selectedPuzzle);
|
||||
startActivity(intent);
|
||||
});
|
||||
// Utilisation de la nouvelle classe pour la gestion des clics sur la liste des puzzles
|
||||
puzzleListView.setOnItemClickListener(new PuzzleClickListener(this, puzzleList));
|
||||
|
||||
// Bouton paramètres
|
||||
settingsButton.setOnClickListener(new listener(this,SettingsActivity.class));
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.example.flow_free;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PuzzleClickListener implements AdapterView.OnItemClickListener {
|
||||
|
||||
private final Context context;
|
||||
private final List<String> puzzleList;
|
||||
|
||||
public PuzzleClickListener(Context context, List<String> puzzleList) {
|
||||
this.context = context;
|
||||
this.puzzleList = puzzleList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
String selectedPuzzle = puzzleList.get(position);
|
||||
|
||||
if (!selectedPuzzle.endsWith(".xml")) {
|
||||
Toast.makeText(context, "Puzzle invalide", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
Intent intent = new Intent(context, GameActivity.class);
|
||||
intent.putExtra("PUZZLE_FILE", selectedPuzzle);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user