diff --git a/.gradle/7.5/executionHistory/executionHistory.bin b/.gradle/7.5/executionHistory/executionHistory.bin index 2ec6332..ab3f6db 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 e570b12..c9252d6 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 87427cf..2eba1ce 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 30330fc..77686ea 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 1426bd1..aeccdab 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 3cb8c53..c2e1e5f 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin index 34bac9e..4d55230 100644 Binary files a/.gradle/buildOutputCleanup/outputFiles.bin and b/.gradle/buildOutputCleanup/outputFiles.bin differ diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5fd120f..7ea4ffe 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -14,9 +14,6 @@ - diff --git a/app/src/main/java/com/example/mastermind/FinDePartieActivity.java b/app/src/main/java/com/example/mastermind/FinDePartieActivity.java deleted file mode 100644 index 0610754..0000000 --- a/app/src/main/java/com/example/mastermind/FinDePartieActivity.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.example.mastermind; - -import android.content.Intent; -import android.os.Bundle; -import android.widget.TextView; - -import androidx.appcompat.app.AppCompatActivity; - -import com.example.mastermind.vue.mastermind.UnePiece; - -public class FinDePartieActivity extends AppCompatActivity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_fin_de_partie); - - boolean trouve = getIntent().getBooleanExtra("trouve", false); - int[] code = getIntent().getIntArrayExtra("code"); - int tours = getIntent().getIntExtra("tour", 0); - - if (trouve){ - ((TextView)findViewById(R.id.texte_gagnant)).setText("Victoire de l'attaquant"); - } else { - ((TextView)findViewById(R.id.texte_gagnant)).setText("Victoire du défenseur"); - } - - ((UnePiece)findViewById(R.id.reponse_code1)).setColor(code[0]); - ((UnePiece)findViewById(R.id.reponse_code2)).setColor(code[1]); - ((UnePiece)findViewById(R.id.reponse_code3)).setColor(code[2]); - ((UnePiece)findViewById(R.id.reponse_code4)).setColor(code[3]); - - if (trouve) { - if (tours == 0) { - ((TextView)findViewById(R.id.texte_nombre_coups)).setText("Le défenseur a trouvé le code en 1 tentative"); - } else { - ((TextView)findViewById(R.id.texte_nombre_coups)).setText("Le défenseur a trouvé le code en " + (tours+1) + " tentatives"); - } - } - } - - @Override - public void onBackPressed() { - Intent menu=new Intent(this, MenuActivity.class); - this.startActivity(menu); - this.finish(); - } -} diff --git a/app/src/main/java/com/example/mastermind/MasterMindActivity.java b/app/src/main/java/com/example/mastermind/MasterMindActivity.java index 3d5b051..d71f0f4 100644 --- a/app/src/main/java/com/example/mastermind/MasterMindActivity.java +++ b/app/src/main/java/com/example/mastermind/MasterMindActivity.java @@ -2,7 +2,10 @@ package com.example.mastermind; import android.content.Intent; import android.os.Bundle; +import android.view.MotionEvent; +import android.view.View; import android.widget.LinearLayout; +import android.widget.TextView; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; @@ -29,6 +32,9 @@ public class MasterMindActivity extends AppCompatActivity { private ArrayList> corrections; + // 0 pour personne, 1 pour attaquant, 2 pour défenseur + private int gagnant; + @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -50,6 +56,8 @@ public class MasterMindActivity extends AppCompatActivity { b.putInt("tour", 0); + b.putInt("gagnant", 0); + this.combinaisons = new ArrayList<>(); combinaisons.add(new ArrayList<>(0)); for (int i=0; i<4; i++) @@ -90,10 +98,10 @@ public class MasterMindActivity extends AppCompatActivity { if (nextable) { if (this.tour < 9) { //on affiche la correction - boolean gagne = this.afficherCorrection((LinearLayout) this.jeu.getChildAt(this.tour)); + this.afficherCorrection((LinearLayout) this.jeu.getChildAt(this.tour)); + //on supprime les listener et sauvegarde la combinaison LinearLayout anciennesPieces = (LinearLayout) this.jeu.getChildAt(this.tour); - ArrayList combinaison = new ArrayList<>(); for (int i = 0; i < anciennesPieces.getChildCount(); i++) { anciennesPieces.getChildAt(i).setOnTouchListener(null); @@ -101,7 +109,7 @@ public class MasterMindActivity extends AppCompatActivity { } this.combinaisons.add(combinaison); - if (gagne) { + if (this.gagnant == 1) { this.finDePartie(true); } else { //on incremente le tour @@ -117,21 +125,28 @@ public class MasterMindActivity extends AppCompatActivity { } else { //on affiche la correction - boolean gagne = this.afficherCorrection((LinearLayout) this.jeu.getChildAt(this.tour)); - //on supprime les listener - if (this.tour > 0) { - LinearLayout anciennesPieces = (LinearLayout) this.jeu.getChildAt(this.tour - 1); - - for (int i = 0; i < anciennesPieces.getChildCount(); i++) { - anciennesPieces.getChildAt(i).setOnTouchListener(null); - } + this.afficherCorrection((LinearLayout) this.jeu.getChildAt(this.tour)); + + //on supprime les listener et sauvegarde la combinaison + LinearLayout anciennesPieces = (LinearLayout) this.jeu.getChildAt(this.tour); + ArrayList combinaison = new ArrayList<>(); + for (int i = 0; i < anciennesPieces.getChildCount(); i++) { + anciennesPieces.getChildAt(i).setOnTouchListener(null); + combinaison.add(((UnePiece) anciennesPieces.getChildAt(i)).getColor()); + } + this.combinaisons.add(combinaison); + + if (this.gagnant == 1) { + this.finDePartie(true); + } else { + this.gagnant = 2; + this.finDePartie(false); } - this.finDePartie(gagne); } } } - public boolean afficherCorrection(LinearLayout pieces){ + public void afficherCorrection(LinearLayout pieces){ int[] colorpiece=new int[4]; for(int i=0; i<4; i++){ colorpiece[i]=((UnePiece)pieces.getChildAt(i)).getColor(); @@ -165,20 +180,45 @@ public class MasterMindActivity extends AppCompatActivity { } } this.corrections.add(correction); - return gagner; + if (gagner){ + this.gagnant=1; + } } public void finDePartie(boolean trouve){ - Intent fin=new Intent(this, FinDePartieActivity.class); - fin.putExtra("trouve", trouve); - fin.putExtra("tour", this.tour); - fin.putExtra("code", this.code); - this.startActivity(fin); - this.finish(); + if (trouve){ + if (this.tour == 0) { + ((TextView) findViewById(R.id.texte_gagnant)).setText("Victoire de l'attaquant en 1 tentative"); + }else + ((TextView) findViewById(R.id.texte_gagnant)).setText("Victoire de l'attaquant en " + (this.tour + 1) + " tentatives"); + } else { + ((TextView)findViewById(R.id.texte_gagnant)).setText("Victoire du défenseur"); + } + + ((UnePiece)findViewById(R.id.reponse_code1)).setColor(this.code[0]); + ((UnePiece)findViewById(R.id.reponse_code2)).setColor(this.code[1]); + ((UnePiece)findViewById(R.id.reponse_code3)).setColor(this.code[2]); + ((UnePiece)findViewById(R.id.reponse_code4)).setColor(this.code[3]); + + findViewById(R.id.cache_reponse).setVisibility(View.INVISIBLE); + + findViewById(R.id.tour).setVisibility(View.INVISIBLE); + findViewById(R.id.tour).setOnTouchListener(null); + + findViewById(R.id.mastermind).setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View view, MotionEvent motionEvent) { + Intent intent = new Intent(MasterMindActivity.this, MenuActivity.class); + MasterMindActivity.this.startActivity(intent); + MasterMindActivity.this.finish(); + return true; + } + }); } public void init(Bundle state){ this.tour= state.getInt("tour"); + this.gagnant= state.getInt("gagnant"); ArrayList> combinaisons = (ArrayList>) state.getSerializable("combinaisons"); ArrayList> corrections = (ArrayList>) state.getSerializable("corrections"); @@ -201,6 +241,11 @@ public class MasterMindActivity extends AppCompatActivity { corrections.remove(this.tour); this.combinaisons = combinaisons; this.corrections = corrections; + + if (this.gagnant==1){ + this.finDePartie(true); + }else if (this.gagnant==2) + this.finDePartie(false); } @Override @@ -210,6 +255,7 @@ public class MasterMindActivity extends AppCompatActivity { outState = new Bundle(); Bundle b = new Bundle(); b.putInt("tour", this.tour); + b.putInt("gagnant", this.gagnant); ArrayList combinaison = new ArrayList<>(); LinearLayout anciennesPieces =(LinearLayout) this.jeu.getChildAt(this.tour); diff --git a/app/src/main/res/drawable/rounded_corners.xml b/app/src/main/res/drawable/rounded_corners.xml new file mode 100644 index 0000000..88d52d1 --- /dev/null +++ b/app/src/main/res/drawable/rounded_corners.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_choix_du_mot_de_passe.xml b/app/src/main/res/layout/activity_choix_du_mot_de_passe.xml index 8595f8c..2d8d862 100644 --- a/app/src/main/res/layout/activity_choix_du_mot_de_passe.xml +++ b/app/src/main/res/layout/activity_choix_du_mot_de_passe.xml @@ -54,14 +54,17 @@ android:id="@+id/bouton_valider_code" android:layout_width="0dp" android:layout_height="wrap_content" - android:layout_margin="@dimen/margeM" - android:text="Valider" - android:textColor="@color/white" - android:textAlignment="center" - android:textSize="@dimen/margeM" - android:background="@color/black" android:layout_alignParentLeft="true" - android:layout_alignParentRight="true"/> + android:layout_alignParentRight="true" + android:layout_marginStart="@dimen/margeM" + android:layout_marginTop="@dimen/margeM" + android:layout_marginEnd="@dimen/margeM" + android:layout_marginBottom="@dimen/margeM" + android:background="@color/black" + android:text="Valider" + android:textAlignment="center" + android:textColor="@color/white" + android:textSize="@dimen/texte" /> diff --git a/app/src/main/res/layout/activity_fin_de_partie.xml b/app/src/main/res/layout/activity_fin_de_partie.xml deleted file mode 100644 index 190787b..0000000 --- a/app/src/main/res/layout/activity_fin_de_partie.xml +++ /dev/null @@ -1,81 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/activity_master_mind.xml b/app/src/main/res/layout/activity_master_mind.xml index c342b6b..a2cba02 100644 --- a/app/src/main/res/layout/activity_master_mind.xml +++ b/app/src/main/res/layout/activity_master_mind.xml @@ -6,187 +6,267 @@ android:layout_height="match_parent" android:background="@color/marron" android:gravity="center_vertical" + android:id="@+id/mastermind" > + + + + + + + + + + + + +