diff --git a/.gradle/7.5/executionHistory/executionHistory.bin b/.gradle/7.5/executionHistory/executionHistory.bin index 660bae8..5bc1eb2 100644 Binary files a/.gradle/7.5/executionHistory/executionHistory.bin and b/.gradle/7.5/executionHistory/executionHistory.bin differ diff --git a/.gradle/7.5/executionHistory/executionHistory.lock b/.gradle/7.5/executionHistory/executionHistory.lock index abb3ff0..7d1aac2 100644 Binary files a/.gradle/7.5/executionHistory/executionHistory.lock and b/.gradle/7.5/executionHistory/executionHistory.lock differ diff --git a/.gradle/7.5/fileHashes/fileHashes.bin b/.gradle/7.5/fileHashes/fileHashes.bin index 9fd8be4..1d59f97 100644 Binary files a/.gradle/7.5/fileHashes/fileHashes.bin and b/.gradle/7.5/fileHashes/fileHashes.bin differ diff --git a/.gradle/7.5/fileHashes/fileHashes.lock b/.gradle/7.5/fileHashes/fileHashes.lock index 63f40ac..15235eb 100644 Binary files a/.gradle/7.5/fileHashes/fileHashes.lock and b/.gradle/7.5/fileHashes/fileHashes.lock differ diff --git a/.gradle/7.5/fileHashes/resourceHashesCache.bin b/.gradle/7.5/fileHashes/resourceHashesCache.bin index 8ecabf2..3b3af3a 100644 Binary files a/.gradle/7.5/fileHashes/resourceHashesCache.bin and b/.gradle/7.5/fileHashes/resourceHashesCache.bin differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 7499d73..be4ad6f 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/app/src/main/java/com/example/mastermind/MasterMindActivity.java b/app/src/main/java/com/example/mastermind/MasterMindActivity.java index d6ad9c3..aee1e2d 100644 --- a/app/src/main/java/com/example/mastermind/MasterMindActivity.java +++ b/app/src/main/java/com/example/mastermind/MasterMindActivity.java @@ -2,8 +2,6 @@ package com.example.mastermind; import android.content.Intent; import android.os.Bundle; -import android.util.Log; -import android.view.View; import android.widget.LinearLayout; import androidx.annotation.Nullable; @@ -13,6 +11,8 @@ import com.example.mastermind.controller.mastermind.MonNextTurnTouch; import com.example.mastermind.controller.mastermind.MonOnTouchListener; import com.example.mastermind.vue.mastermind.UnePiece; +import java.util.ArrayList; + public class MasterMindActivity extends AppCompatActivity { private int[] code; @@ -24,6 +24,11 @@ public class MasterMindActivity extends AppCompatActivity { private LinearLayout correction; private boolean vide; + + private ArrayList> combinaisons; + + private ArrayList> corrections; + @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -33,16 +38,34 @@ public class MasterMindActivity extends AppCompatActivity { this.vide=data.getBooleanExtra("vide", false); this.jeu=this.findViewById(R.id.jeu); this.correction=this.findViewById(R.id.correction); - this.tour=0; - this.findViewById(R.id.tour).setOnTouchListener(new MonNextTurnTouch(this)); - - //on récupere le LinearLayout des pieces du tour - LinearLayout pieces =(LinearLayout) this.jeu.getChildAt(this.tour); - //on ajoute le listener - for(int i=0; i(); + combinaisons.add(new ArrayList<>(0)); + for (int i=0; i<4; i++) + combinaisons.get(0).add(6); + b.putSerializable("combinaisons", combinaisons); + + this.corrections = new ArrayList<>(); + corrections.add(new ArrayList<>(0)); + for (int i=0; i<4; i++) + corrections.get(0).add(6); + b.putSerializable("corrections", corrections); + + this.init(b); + } + + this.findViewById(R.id.tour).setOnTouchListener(new MonNextTurnTouch(this)); } @Override @@ -56,10 +79,15 @@ public class MasterMindActivity extends AppCompatActivity { if(this.tour<9){ //on affiche la correction boolean gagne = this.afficherCorrection((LinearLayout) this.jeu.getChildAt(this.tour)); - //on supprime les listener + //on supprime les listener et sauvegarde la combinaison LinearLayout anciennesPieces =(LinearLayout) this.jeu.getChildAt(this.tour); - - for(int i=0; i combinaison = new ArrayList<>(); + for(int i=0; i correction = new ArrayList<>(); //si on a gagner boolean gagner=true; @@ -101,6 +130,7 @@ public class MasterMindActivity extends AppCompatActivity { if(colorpiece[i] == this.code[i]){ //bien placer bon endroit ((UnePiece)correctionsPieces.getChildAt(i)).setColor(4); + correction.add(4); }else{ gagner=false; boolean nombre=false; @@ -112,14 +142,18 @@ public class MasterMindActivity extends AppCompatActivity { if(nombre){ //mal placer ((UnePiece)correctionsPieces.getChildAt(i)).setColor(5); + correction.add(5); + }else { + //mauvais + correction.add(6); } } } + this.corrections.add(correction); return gagner; } public void finDePartie(boolean trouve){ - Log.d("finDePartie", " finDePartie: "+trouve); Intent fin=new Intent(this, FinDePartieActivity.class); fin.putExtra("trouve", trouve); fin.putExtra("tour", this.tour); @@ -127,4 +161,59 @@ public class MasterMindActivity extends AppCompatActivity { this.startActivity(fin); this.finish(); } + + public void init(Bundle state){ + this.tour= state.getInt("tour"); + ArrayList> combinaisons = (ArrayList>) state.getSerializable("combinaisons"); + ArrayList> corrections = (ArrayList>) state.getSerializable("corrections"); + + for (int i=0; i<=this.tour; i++){ + ArrayList combinaison = combinaisons.get(i); + ArrayList correction = corrections.get(i); + LinearLayout pieces = (LinearLayout) this.jeu.getChildAt(i); + LinearLayout correctionsPieces = (LinearLayout) this.correction.getChildAt(i); + for (int j=0; j<4; j++){ + UnePiece p = (UnePiece) pieces.getChildAt(j); + p.setColor(combinaison.get(j)); + UnePiece c = (UnePiece) correctionsPieces.getChildAt(j); + c.setColor(correction.get(j)); + if (i==this.tour){ + p.setOnTouchListener(new MonOnTouchListener(p, this.vide)); + } + } + } + combinaisons.remove(this.tour); + corrections.remove(this.tour); + this.combinaisons = combinaisons; + this.corrections = corrections; + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + if (outState == null) + outState = new Bundle(); + Bundle b = new Bundle(); + b.putInt("tour", this.tour); + + ArrayList combinaison = new ArrayList<>(); + LinearLayout anciennesPieces =(LinearLayout) this.jeu.getChildAt(this.tour); + for (int i=0; i<4; i++) + combinaison.add(((UnePiece)anciennesPieces.getChildAt(i)).getColor()); + this.combinaisons.add(combinaison); + b.putSerializable("combinaisons", this.combinaisons); + + ArrayList correction = new ArrayList<>(); + for (int i=0; i<4; i++) + correction.add(6); + this.corrections.add(correction); + b.putSerializable("corrections", this.corrections); + outState.putBundle("master_mind", b); + } + + @Override + protected void onRestoreInstanceState(Bundle savedInstanceState) { + super.onRestoreInstanceState(savedInstanceState); + this.init(savedInstanceState.getBundle("master_mind")); + } }