anvencement sur le systeme de condition de victoir et les colisions
@@ -0,0 +1,26 @@
|
||||
package com.example.flow_free;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ExampleInstrumentedTest {
|
||||
@Test
|
||||
public void useAppContext() {
|
||||
// Context of the app under test.
|
||||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
||||
assertEquals("com.example.flow_free", appContext.getPackageName());
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,8 @@ public class FlowFreeView extends View {
|
||||
private final Map<Integer, List<int[]>> paths = new HashMap<>();
|
||||
|
||||
private final Map<Integer, Integer> colorMap = new HashMap<>();//test pour la couleur
|
||||
private final Set<Integer> completedColors = new HashSet<>();// liste des chemin fini
|
||||
|
||||
|
||||
private static final int[] DISTINCT_COLORS = {
|
||||
Color.rgb(255, 0, 0), // Rouge vif
|
||||
@@ -32,8 +34,7 @@ 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(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é
|
||||
@@ -74,7 +75,18 @@ public class FlowFreeView extends View {
|
||||
|
||||
|
||||
|
||||
|
||||
//test
|
||||
private void printBoardToLog() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int[] row : board) {
|
||||
for (int cell : row) {
|
||||
sb.append(String.format("%3d", cell)).append(" ");
|
||||
}
|
||||
sb.append("\n");
|
||||
}
|
||||
Log.d("DEBUG_FLOW", "Contenu du board :\n" + sb.toString());
|
||||
}
|
||||
//test
|
||||
|
||||
|
||||
@Override//test pour calculer cellsize
|
||||
@@ -121,7 +133,7 @@ public class FlowFreeView extends View {
|
||||
for (int row = 0; row < puzzle.getSize(); row++) {
|
||||
for (int col = 0; col < puzzle.getSize(); col++) {
|
||||
int colorId = board[row][col];
|
||||
if (colorId != 0) {
|
||||
if (colorId > 0) { // permet de ne pas dessiner des cercle quand je fais un trait
|
||||
paint.setColor(getColorForId(colorId));
|
||||
float cx = col * cellSize + cellSize / 2f;
|
||||
float cy = row * cellSize + cellSize / 2f;
|
||||
@@ -134,7 +146,7 @@ public class FlowFreeView extends View {
|
||||
paint.setStrokeWidth(cellSize / 4f);
|
||||
paint.setStyle(Paint.Style.STROKE);
|
||||
for (Map.Entry<Integer, List<int[]>> entry : paths.entrySet()) {
|
||||
paint.setColor(getColorForId(entry.getKey()));
|
||||
paint.setColor(getColorForId(Math.abs(entry.getKey())));
|
||||
List<int[]> path = entry.getValue();
|
||||
for (int i = 0; i < path.size() - 1; i++) {
|
||||
int[] p1 = path.get(i);
|
||||
@@ -157,10 +169,18 @@ public class FlowFreeView extends View {
|
||||
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) {
|
||||
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;
|
||||
if (!paths.containsKey(selectedColor)) {
|
||||
paths.put(selectedColor, new ArrayList<>());
|
||||
@@ -173,15 +193,64 @@ public class FlowFreeView extends View {
|
||||
}
|
||||
break;
|
||||
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
/* 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) {
|
||||
if (board[row][col] == 0) { // la case est vide
|
||||
// Vérifie que la case est adjacente à la dernière
|
||||
List<int[]> path = paths.get(selectedColor);
|
||||
int[] last = path.get(path.size() - 1);
|
||||
|
||||
int dr = Math.abs(last[0] - row);
|
||||
int dc = Math.abs(last[1] - col);
|
||||
|
||||
if ((dr == 1 && dc == 0) || (dr == 0 && dc == 1)) {
|
||||
board[row][col] = -selectedColor; // ✅ Remplit avec l’id du point de départ
|
||||
path.add(new int[]{row, col}); // 🔁 On suit le chemin mais un seul id
|
||||
invalidate(); // 🖌️ Redessine la vue
|
||||
}
|
||||
}
|
||||
|
||||
if (board[row][col] == selectedColor) { // la case est la meme que le depart
|
||||
// Vérifie que la case est adjacente à la dernière
|
||||
List<int[]> path = paths.get(selectedColor);
|
||||
int[] last = path.get(path.size() - 1);
|
||||
|
||||
int dr = Math.abs(last[0] - row);
|
||||
int dc = Math.abs(last[1] - col);
|
||||
|
||||
if ((dr == 1 && dc == 0) || (dr == 0 && dc == 1)) {
|
||||
board[row][col] = selectedColor; // ✅ Remplit avec l’id du point de départ
|
||||
path.add(new int[]{row, col}); // 🔁 On suit le chemin mais un seul id
|
||||
completedColors.add(selectedColor);
|
||||
selectedColor = 0;// permet de ne pas travers la paire
|
||||
invalidate(); // 🖌️ Redessine la vue
|
||||
Log.d("DEBUG_FLOW", "Paire " + selectedColor + " complétée !");
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
//version chat
|
||||
|
||||
|
||||
|
||||
|
||||
case MotionEvent.ACTION_UP:
|
||||
selectedColor = 0; // Permet de reprendre à la prochaine touche
|
||||
@@ -12,6 +12,8 @@ public class GameActivity extends Activity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
|
||||
Log.d("DEBUG_FLOW", "GameActivity lancé"); // debug
|
||||
String puzzleFile = getIntent().getStringExtra("PUZZLE_FILE");
|
||||
Puzzle puzzle = PuzzleLoader.loadPuzzle(this, puzzleFile);
|
||||
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 982 B After Width: | Height: | Size: 982 B |
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 5.8 KiB |
|
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |
|
Before Width: | Height: | Size: 7.6 KiB After Width: | Height: | Size: 7.6 KiB |
@@ -0,0 +1,17 @@
|
||||
package com.example.flow_free;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
public class ExampleUnitTest {
|
||||
@Test
|
||||
public void addition_isCorrect() {
|
||||
assertEquals(4, 2 + 2);
|
||||
}
|
||||
}
|
||||