bientot la fin
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
<application
|
<application
|
||||||
android:allowBackup="true">
|
android:allowBackup="true">
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MenuActivity"
|
||||||
android:exported="true">
|
android:exported="true">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
@@ -13,5 +13,7 @@
|
|||||||
</activity>
|
</activity>
|
||||||
<activity android:name=".GameActivity"/>
|
<activity android:name=".GameActivity"/>
|
||||||
<activity android:name=".SettingsActivity"/>
|
<activity android:name=".SettingsActivity"/>
|
||||||
|
<activity android:name=".MainActivity"/>
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ public class FlowFreeView extends View {
|
|||||||
|
|
||||||
private final Map<Integer, Integer> colorMap = new HashMap<>();//test pour la couleur
|
private final Map<Integer, Integer> colorMap = new HashMap<>();//test pour la couleur
|
||||||
private final Set<Integer> completedColors = new HashSet<>();// liste des chemin fini
|
private final Set<Integer> completedColors = new HashSet<>();// liste des chemin fini
|
||||||
|
private boolean win = false;
|
||||||
|
|
||||||
|
|
||||||
private static final int[] DISTINCT_COLORS = {
|
private static final int[] DISTINCT_COLORS = {
|
||||||
@@ -158,8 +159,54 @@ private void printBoardToLog() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//dessine quand c'est victoir
|
||||||
|
if (win) {
|
||||||
|
paint.setColor(Color.BLACK);
|
||||||
|
paint.setTextSize(80);
|
||||||
|
paint.setTextAlign(Paint.Align.CENTER);
|
||||||
|
canvas.drawText("🎉 Bravo !", getWidth() / 2f, getHeight() / 2f, paint);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//test
|
||||||
|
private void clearPath(int color) {
|
||||||
|
// Supprime visuellement le chemin
|
||||||
|
for (int r = 0; r < board.length; r++) {
|
||||||
|
for (int c = 0; c < board[r].length; c++) {
|
||||||
|
if (board[r][c] == -color) {
|
||||||
|
board[r][c] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Supprime le chemin logique
|
||||||
|
paths.remove(color);
|
||||||
|
completedColors.remove(color);
|
||||||
|
invalidate(); // Redessine
|
||||||
|
}
|
||||||
|
//test
|
||||||
|
//verrifie condition victoir
|
||||||
|
private void checkWin() {
|
||||||
|
// 1. Vérifie si le tableau est complètement rempli
|
||||||
|
for (int r = 0; r < board.length; r++) {
|
||||||
|
for (int c = 0; c < board[r].length; c++) {
|
||||||
|
if (board[r][c] == 0) {
|
||||||
|
return; // Case vide : pas encore gagné
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouchEvent(MotionEvent event) {
|
public boolean onTouchEvent(MotionEvent event) {
|
||||||
@@ -175,7 +222,15 @@ private void printBoardToLog() {
|
|||||||
case MotionEvent.ACTION_DOWN:
|
case MotionEvent.ACTION_DOWN:
|
||||||
|
|
||||||
int colorAtCell = board[row][col];
|
int colorAtCell = board[row][col];
|
||||||
if (colorAtCell != 0) {
|
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
|
if (completedColors.contains(colorAtCell)) {// regarde si le chemin qu'on veut tracer est fini
|
||||||
// 🔒 Ne pas toucher à un chemin terminé
|
// 🔒 Ne pas toucher à un chemin terminé
|
||||||
Log.d("DEBUG_FLOW", "Chemin déjà terminé, on ne fait rien.");
|
Log.d("DEBUG_FLOW", "Chemin déjà terminé, on ne fait rien.");
|
||||||
@@ -236,11 +291,21 @@ private void printBoardToLog() {
|
|||||||
int dr = Math.abs(last[0] - row);
|
int dr = Math.abs(last[0] - row);
|
||||||
int dc = Math.abs(last[1] - col);
|
int dc = Math.abs(last[1] - col);
|
||||||
|
|
||||||
|
|
||||||
|
//permet de ne pas revenir a upoint de depart
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
// test
|
||||||
|
|
||||||
if ((dr == 1 && dc == 0) || (dr == 0 && dc == 1)) {
|
if ((dr == 1 && dc == 0) || (dr == 0 && dc == 1)) {
|
||||||
board[row][col] = selectedColor; // ✅ Remplit avec l’id du point de départ
|
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
|
path.add(new int[]{row, col}); // 🔁 On suit le chemin mais un seul id
|
||||||
completedColors.add(selectedColor);
|
completedColors.add(selectedColor);
|
||||||
selectedColor = 0;// permet de ne pas travers la paire
|
selectedColor = 0;// permet de ne pas travers la paire
|
||||||
|
checkWin();
|
||||||
invalidate(); // 🖌️ Redessine la vue
|
invalidate(); // 🖌️ Redessine la vue
|
||||||
Log.d("DEBUG_FLOW", "Paire " + selectedColor + " complétée !");
|
Log.d("DEBUG_FLOW", "Paire " + selectedColor + " complétée !");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package com.example.flow_free;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.MotionEvent;
|
||||||
|
import android.widget.Button;
|
||||||
|
|
||||||
|
public class MenuActivity extends Activity {
|
||||||
|
|
||||||
|
private Button Bjouer;
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_menu);
|
||||||
|
Bjouer = findViewById(R.id.Bjouer);
|
||||||
|
Bjouer.setOnClickListener(view -> {
|
||||||
|
Intent intent = new Intent(MenuActivity.this, MainActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/texte"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="20dp"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:textSize="33sp"
|
||||||
|
android:text="Flow_Free" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/Bjouer"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:layout_centerInParent="true"
|
||||||
|
android:layout_marginTop="12dp"
|
||||||
|
android:text="Jouer" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/button2"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@id/Bjouer"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:layout_marginTop="12dp"
|
||||||
|
android:text="Règles" />
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
Reference in New Issue
Block a user