From 2ef6863791f39739d2ce0b274e3ac284a47f9c2b Mon Sep 17 00:00:00 2001 From: chaignea Date: Sat, 8 Apr 2023 18:05:50 +0200 Subject: [PATCH] =?UTF-8?q?Ajout=20sauvegarde=20=C3=A9tat=20Partie=20Maste?= =?UTF-8?q?r=20Mind?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../7.5/executionHistory/executionHistory.bin | Bin 1182076 -> 1182076 bytes .../executionHistory/executionHistory.lock | Bin 17 -> 17 bytes .gradle/7.5/fileHashes/fileHashes.bin | Bin 73565 -> 73565 bytes .gradle/7.5/fileHashes/fileHashes.lock | Bin 17 -> 17 bytes .../7.5/fileHashes/resourceHashesCache.bin | Bin 20605 -> 20843 bytes .../buildOutputCleanup.lock | Bin 17 -> 17 bytes .../mastermind/MasterMindActivity.java | 119 +++++++++++++++--- 7 files changed, 104 insertions(+), 15 deletions(-) diff --git a/.gradle/7.5/executionHistory/executionHistory.bin b/.gradle/7.5/executionHistory/executionHistory.bin index 660bae89fb2e6ae9a9ebe3d0e2bd9abc8f61bfe9..5bc1eb29fbd598b834ab26a8a398d2bfabba585e 100644 GIT binary patch delta 1188 zcmew}$>Yx?j|~n*N+sE8WrZfWm8E4##bw!fiCMX(McJt(S(zpbV8D54yS*}RC)4KF zC0T4jS41Q|PMvQkdBe74=N4n-!;EVu8#anhpHR&!w0T1HK2D(|Vef69UPnINZ+t6c zt<#lbjO(T+dU9!P?rLpg6R2<#DNbu;c%Sr+|MmZxuNOBf^n@_!ma1RBJiYdzoSfO| z$#2-IHqX8IqUW2zm!4P5%nSlk-tib-3V*Es>3L-B)-td7=7oLj3;P&>moT7U^L9@UE;dGiGleB-!F_^1)?|L1{KUEV?RLXdK4r%3&Nukfm<3ZJBP*S5 zS+;jvd(;raQhnw0WW^rM?Eyu+9E=hP8+P5Rx+7#Yr*z8^$!SGN&AUN9JSH){pqST} zb>_Wi-QT9GW%Kz>Prl1%#MJ?o{lU&ScY5J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;OUkv5~Vs0Sj*?uvY_r_F$q0Znl-LZ#P zd%9i)ufg;=J-j;Gfh-=T?Qw5-br}WF18O=jgeA8FQ`d6F?a}XfJy`|NJwE;84L-@~ z3-Wk{w?Fv8JDUZ=2h$%G@>xu8aOSn%{_iKR1B(QD5}wor^2-59P-G}j5Mfhrz&-|%$zccM1@4{WJ`g8WTvH*RtjO&2?*=f$+ zB1Ti1{eP@DGX0+jUy9T>yY@Nl7Z<;lIb0&J>*vL3OM!-eGgy1&G}H8lew-51R}1qA uNP}$rX7GgxXv$xQBNN|GFJa}43fP}KQ;4s9zbFXv1F^vN{i1?DkN;!b+77hEk`7$6(vDb$u>ic za+~bfB|O4s(&*? zjTHOjjUB?1%~l*&_-M>hXNf3g93+^T&TjY5QWK?rcab(RGaL)@|nUF5lN3z z=Nn4iux;77#aQ_;SY_o#A&5%u2a`Ql-BL&r_TKjCb>!3i#GxztE>+gllRxV{=U~Eqe*r(0_20W)GUtDra!D8WD zJGm{#bk1iuJpH^=?Ic){_zMAuBB9L9rDpZ-Z)tT+NSe>poCB?pOr$5A~BcTvg zyeg9&yM!m(EEi!8I1)2Cc==@8fFrpOIrc&zt!E4*G=W$Vga!N=v(F1^FYtEyc82lQ z)B~IlJ3lG_C4oSYbMnRx;mKwzjw|foZ2pklJA<*4pD9o~PD}@C?M#Tm5AP`@cIr!7BwP5!K=&jL|-R0yJy=fGsoRksv&#;D#kU08qcahixsk8xTz z#NJO3H4OX>o1Ir5%2wc1a8MV&z3$A{y}ZeaZp-&Vj5_@ttgNc>$K;PO!qY9p8Qquz z&ZK80vGQ#^gMIAfi{H@o&Z?H3onmN{G^uTRlwho9Viy1KW&33*#x52BUp$)t diff --git a/.gradle/7.5/fileHashes/fileHashes.lock b/.gradle/7.5/fileHashes/fileHashes.lock index 63f40ac1ee10f08d8ea5db20657fb77d87784478..15235ebb42abad4f68561dd6965897aa946e57d3 100644 GIT binary patch literal 17 VcmZQBSfRUsf03Rh0~oNf0{|wf0{s90 literal 17 VcmZQBSfRUsf03Rh0~oMO0RSg81Bn0t diff --git a/.gradle/7.5/fileHashes/resourceHashesCache.bin b/.gradle/7.5/fileHashes/resourceHashesCache.bin index 8ecabf2fb9645c700c880ec8cc75ab4f2ae9925e..3b3af3a2a43dd3b615e86ccec1baee196374e146 100644 GIT binary patch delta 424 zcmeynfbsPr#tkMCjINVSB~}Pbx9{kDb$Ib91~3TpoP1T{fxw{ybG@E@xMu|s40ybG zt)u{>z&*bF$1|6-pMWZ5oxD{lL*vaRgL1{}x}{L12meFCr@Wjic=kOck|T zg18Ets+L9Vm_GBxwGZZ)D&DS9c#(SLjL7cyXY;j0dL7&xonwOkqh{aG&6hHJKkLKXER83sM093gUzj delta 58 zcmV-A0LB07q5=J&0kAX}0X~y87^su=7}&Gr83+NB1shuu`oCivq4Ba2&FF-IsgCw diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 7499d73aa24ef7185038c572c73c70a9ddc57c78..be4ad6f7b33d410eef4908ab2b84307cab2f5711 100644 GIT binary patch literal 17 VcmZP$F`c)6-~Z@+3}C=*1^_u*1pxp6 literal 17 VcmZP$F`c)6-~Z@+3}C=@1pqns1)cx^ 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")); + } }