Ajout écran fin de partie
This commit is contained in:
parent
b93daedfb9
commit
e0df728757
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -14,6 +14,9 @@
|
||||
<activity
|
||||
android:name=".ChoixDuMotDePasse"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name=".FinDePartieActivity"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name=".SettingActivity"
|
||||
android:exported="false" />
|
||||
|
@ -0,0 +1,48 @@
|
||||
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();
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package com.example.mastermind;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
@ -54,37 +55,42 @@ public class MasterMindActivity extends AppCompatActivity {
|
||||
public void nextTurn(){
|
||||
if(this.tour<9){
|
||||
//on affiche la correction
|
||||
this.afficherCorrection((LinearLayout) this.jeu.getChildAt(this.tour));
|
||||
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);}
|
||||
}
|
||||
//on incremente le tour
|
||||
this.tour++;
|
||||
//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<pieces.getChildCount(); i++){
|
||||
UnePiece p=(UnePiece) pieces.getChildAt(i);
|
||||
p.setOnTouchListener(new MonOnTouchListener(p, this.vide));
|
||||
|
||||
if (gagne){
|
||||
this.finDePartie(true);
|
||||
} else {
|
||||
//on incremente le tour
|
||||
this.tour++;
|
||||
//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<pieces.getChildCount(); i++) {
|
||||
UnePiece p = (UnePiece) pieces.getChildAt(i);
|
||||
p.setOnTouchListener(new MonOnTouchListener(p, this.vide));
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
//on affiche la correction
|
||||
this.afficherCorrection((LinearLayout) this.jeu.getChildAt(this.tour));
|
||||
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.finDePartie();
|
||||
this.finDePartie(gagne);
|
||||
}
|
||||
}
|
||||
|
||||
public void afficherCorrection(LinearLayout pieces){
|
||||
public boolean afficherCorrection(LinearLayout pieces){
|
||||
int[] colorpiece=new int[4];
|
||||
for(int i=0; i<4; i++){
|
||||
colorpiece[i]=((UnePiece)pieces.getChildAt(i)).getColor();
|
||||
@ -111,12 +117,16 @@ public class MasterMindActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
}
|
||||
if(gagner){
|
||||
this.finDePartie();
|
||||
}
|
||||
return gagner;
|
||||
}
|
||||
|
||||
public void finDePartie(){
|
||||
|
||||
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);
|
||||
fin.putExtra("code", this.code);
|
||||
this.startActivity(fin);
|
||||
this.finish();
|
||||
}
|
||||
}
|
||||
|
81
app/src/main/res/layout/activity_fin_de_partie.xml
Normal file
81
app/src/main/res/layout/activity_fin_de_partie.xml
Normal file
@ -0,0 +1,81 @@
|
||||
<?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"
|
||||
android:background="@color/marron"
|
||||
>
|
||||
<TextView
|
||||
android:id="@+id/titre_fin_de_partie"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Fin de partie"
|
||||
android:textColor="@color/black"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="50dp"
|
||||
android:textSize="@dimen/titre"
|
||||
android:layout_centerHorizontal="true"
|
||||
/>
|
||||
<TextView
|
||||
android:id="@+id/texte_gagnant"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Gagnant"
|
||||
android:textColor="@color/black"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="30dp"
|
||||
android:textSize="@dimen/texte"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_below="@+id/titre_fin_de_partie"
|
||||
/>
|
||||
<LinearLayout
|
||||
android:id="@+id/reponse_combinaison"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/texte_gagnant"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="30dp"
|
||||
android:orientation="vertical"
|
||||
>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/reponse_combinaiton_titre"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="La combinaison était :"
|
||||
android:textColor="@color/black"
|
||||
android:layout_gravity="center"
|
||||
android:textSize="@dimen/texte"
|
||||
android:layout_centerHorizontal="true"
|
||||
/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/reponse_combinaison_combinaison"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="10dp"
|
||||
|
||||
>
|
||||
<com.example.mastermind.vue.mastermind.UnePiece android:id="@+id/reponse_code1" android:layout_width="@dimen/pieceM" android:layout_height="@dimen/pieceM" android:layout_margin="@dimen/margeM"/>
|
||||
<com.example.mastermind.vue.mastermind.UnePiece android:id="@+id/reponse_code2" android:layout_width="@dimen/pieceM" android:layout_height="@dimen/pieceM" android:layout_margin="@dimen/margeM"/>
|
||||
<com.example.mastermind.vue.mastermind.UnePiece android:id="@+id/reponse_code3" android:layout_width="@dimen/pieceM" android:layout_height="@dimen/pieceM" android:layout_margin="@dimen/margeM"/>
|
||||
<com.example.mastermind.vue.mastermind.UnePiece android:id="@+id/reponse_code4" android:layout_width="@dimen/pieceM" android:layout_height="@dimen/pieceM" android:layout_margin="@dimen/margeM"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
<TextView
|
||||
android:id="@+id/texte_nombre_coups"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text=""
|
||||
android:textColor="@color/black"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="30dp"
|
||||
android:textSize="@dimen/texte_petit"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_below="@+id/reponse_combinaison"
|
||||
/>
|
||||
|
||||
|
||||
</RelativeLayout>
|
@ -5,4 +5,6 @@
|
||||
<dimen name="correction">15dp</dimen>
|
||||
<dimen name="marge_correction">5dp</dimen>
|
||||
<dimen name="titre">30dp</dimen>
|
||||
<dimen name="texte">20dp</dimen>
|
||||
<dimen name="texte_petit">15dp</dimen>
|
||||
</resources>
|
Loading…
Reference in New Issue
Block a user