ajustement controleur + finPartieActivity
This commit is contained in:
@@ -4,6 +4,7 @@ import android.app.Activity;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
@@ -23,6 +24,9 @@ public class Controleur {
|
|||||||
private Objectif objectifActuel;
|
private Objectif objectifActuel;
|
||||||
private TextView tvObjectif;
|
private TextView tvObjectif;
|
||||||
private TextView tvNbObjectifs;
|
private TextView tvNbObjectifs;
|
||||||
|
private TextView tvCles;
|
||||||
|
private Button btnReinitialisationObjectif;
|
||||||
|
private View layoutCles;
|
||||||
|
|
||||||
public Controleur(Activity activite, EtatJeu etatJeu, VueGrille vueGrille,
|
public Controleur(Activity activite, EtatJeu etatJeu, VueGrille vueGrille,
|
||||||
long graine, TextView tvScore, TextView tvCoups,
|
long graine, TextView tvScore, TextView tvCoups,
|
||||||
@@ -42,9 +46,18 @@ public class Controleur {
|
|||||||
this.gestionnaireObjectifs = new GestionnaireObjectifs(graine);
|
this.gestionnaireObjectifs = new GestionnaireObjectifs(graine);
|
||||||
this.tvObjectif = activite.findViewById(R.id.tvObjectif);
|
this.tvObjectif = activite.findViewById(R.id.tvObjectif);
|
||||||
this.tvNbObjectifs = activite.findViewById(R.id.tvNbObjectifs);
|
this.tvNbObjectifs = activite.findViewById(R.id.tvNbObjectifs);
|
||||||
|
this.tvCles = activite.findViewById(R.id.tvCles);
|
||||||
|
this.layoutCles = activite.findViewById(R.id.layoutCles);
|
||||||
|
this.btnReinitialisationObjectif = activite.findViewById(R.id.btnReinitialisationObjectif);
|
||||||
|
|
||||||
if (tvObjectif != null) tvObjectif.setVisibility(View.VISIBLE);
|
if (tvObjectif != null) tvObjectif.setVisibility(View.VISIBLE);
|
||||||
if (tvNbObjectifs != null) tvNbObjectifs.setVisibility(View.VISIBLE);
|
if (tvNbObjectifs != null) tvNbObjectifs.setVisibility(View.VISIBLE);
|
||||||
|
if (layoutCles != null) layoutCles.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
// Listener du bouton de réinitialisation
|
||||||
|
if (btnReinitialisationObjectif != null) {
|
||||||
|
btnReinitialisationObjectif.setOnClickListener(v -> reinitialiserObjectif());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -73,6 +86,11 @@ public class Controleur {
|
|||||||
* Centralise la logique pour être appelé par le bouton ET par le tactile.
|
* Centralise la logique pour être appelé par le bouton ET par le tactile.
|
||||||
*/
|
*/
|
||||||
public void gererFinDeCoup() {
|
public void gererFinDeCoup() {
|
||||||
|
|
||||||
|
// 1 clé tous les 5 coups
|
||||||
|
if (hardMode && etatJeu.obtenirNbCoups() % 5 == 0) {
|
||||||
|
gestionnaireObjectifs.ajouterCle();
|
||||||
|
}
|
||||||
// --- Logique Hard Mode
|
// --- Logique Hard Mode
|
||||||
if (hardMode && objectifActuel != null) {
|
if (hardMode && objectifActuel != null) {
|
||||||
// 1. Décrémenter les coups de l'objectif
|
// 1. Décrémenter les coups de l'objectif
|
||||||
@@ -102,38 +120,37 @@ public class Controleur {
|
|||||||
verifierFinDePartie();
|
verifierFinDePartie();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tente de réinitialiser l'objectif en cours en consommant 3 clés.
|
||||||
|
* Affiche un Toast si le joueur n'a pas assez de clés.
|
||||||
|
*/
|
||||||
|
public void reinitialiserObjectif() {
|
||||||
|
if (!hardMode || gestionnaireObjectifs == null) return;
|
||||||
|
|
||||||
|
if (gestionnaireObjectifs.consommerCles()) {
|
||||||
|
objectifActuel = gestionnaireObjectifs.genererObjectif();
|
||||||
|
rafraichirAffichage();
|
||||||
|
} else {
|
||||||
|
Toast.makeText(activite, "Pas assez de clés !", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lancer l'écran de fin.
|
||||||
|
*/
|
||||||
public void verifierFinDePartie() {
|
public void verifierFinDePartie() {
|
||||||
if (etatJeu.estTerminee()) {
|
if (etatJeu.estTerminee()) {
|
||||||
Intent intent = new Intent(activite, FinPartieActivity.class);
|
FinPartieActivity.demarrer(
|
||||||
intent.putExtra("score", etatJeu.obtenirScore());
|
activite,
|
||||||
intent.putExtra("nbCoups", etatJeu.obtenirNbCoups());
|
etatJeu.obtenirScore(),
|
||||||
intent.putExtra("graine", graine);
|
etatJeu.obtenirNbCoups(),
|
||||||
intent.putExtra("objectifsReussis", hardMode ? gestionnaireObjectifs.getNbObjectifsRealises() : 0);
|
graine,
|
||||||
if (hardMode && objectifActuel != null)
|
hardMode ? gestionnaireObjectifs.getNbObjectifsRealises() : 0,
|
||||||
intent.putExtra("objectifDescription", objectifActuel.getDescription());
|
(hardMode && objectifActuel != null) ? objectifActuel.getDescription() : null,
|
||||||
|
etatJeu.obtenirGrille(),
|
||||||
// Passer la grille finale (flatten)
|
etatJeu.obtenirVerrous()
|
||||||
int[][] grille = etatJeu.obtenirGrille();
|
);
|
||||||
int nbLignes = grille.length;
|
|
||||||
int nbCols = grille[0].length;
|
|
||||||
int[] grillePlat = new int[nbLignes * nbCols];
|
|
||||||
for (int l = 0; l < nbLignes; l++)
|
|
||||||
for (int c = 0; c < nbCols; c++)
|
|
||||||
grillePlat[l * nbCols + c] = grille[l][c];
|
|
||||||
intent.putExtra("grille", grillePlat);
|
|
||||||
intent.putExtra("nbLignes", nbLignes);
|
|
||||||
intent.putExtra("nbCols", nbCols);
|
|
||||||
|
|
||||||
// Passer les verrous (flatten)
|
|
||||||
boolean[][] verrous = etatJeu.obtenirVerrous();
|
|
||||||
boolean[] verrouxPlat = new boolean[nbLignes * nbCols];
|
|
||||||
for (int l = 0; l < nbLignes; l++)
|
|
||||||
for (int c = 0; c < nbCols; c++)
|
|
||||||
verrouxPlat[l * nbCols + c] = verrous[l][c];
|
|
||||||
intent.putExtra("verrous", verrouxPlat);
|
|
||||||
|
|
||||||
activite.startActivity(intent);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,9 +163,22 @@ public class Controleur {
|
|||||||
if (hardMode && objectifActuel != null) {
|
if (hardMode && objectifActuel != null) {
|
||||||
if (tvObjectif != null) tvObjectif.setText(objectifActuel.getDescription());
|
if (tvObjectif != null) tvObjectif.setText(objectifActuel.getDescription());
|
||||||
if (tvNbObjectifs != null) tvNbObjectifs.setText("Objectifs réussis : " + gestionnaireObjectifs.getNbObjectifsRealises());
|
if (tvNbObjectifs != null) tvNbObjectifs.setText("Objectifs réussis : " + gestionnaireObjectifs.getNbObjectifsRealises());
|
||||||
|
|
||||||
|
int nbCles = gestionnaireObjectifs.getNbCles();
|
||||||
|
if (tvCles != null) {
|
||||||
|
tvCles.setText("🗝️ Clés : " + nbCles);
|
||||||
|
}
|
||||||
|
if (btnReinitialisationObjectif != null) {
|
||||||
|
// Grisé si 0 clé
|
||||||
|
float alpha;
|
||||||
|
if (nbCles >= 1) {
|
||||||
|
alpha = 1f; // visible
|
||||||
|
} else {
|
||||||
|
alpha = 0.4f; // grisé
|
||||||
|
}
|
||||||
|
btnReinitialisationObjectif.setAlpha(alpha);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sauvegarderEtat(Bundle out) {
|
public void sauvegarderEtat(Bundle out) {
|
||||||
|
|||||||
@@ -8,12 +8,48 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
public class FinPartieActivity extends Activity {
|
public class FinPartieActivity extends Activity {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Méthode statique pour démarrer l'activité avec toutes les données nécessaires.
|
||||||
|
*/
|
||||||
|
public static void demarrer(Activity source, int score, int nbCoups, long graine,
|
||||||
|
int objectifsReussis, String objectifDescription,
|
||||||
|
int[][] grille, boolean[][] verrous) {
|
||||||
|
Intent intent = new Intent(source, FinPartieActivity.class);
|
||||||
|
intent.putExtra("score", score);
|
||||||
|
intent.putExtra("nbCoups", nbCoups);
|
||||||
|
intent.putExtra("graine", graine);
|
||||||
|
intent.putExtra("objectifsReussis", objectifsReussis);
|
||||||
|
intent.putExtra("objectifDescription", objectifDescription);
|
||||||
|
|
||||||
|
// Aplatissement de la grille
|
||||||
|
int nbLignes = grille.length;
|
||||||
|
int nbCols = grille[0].length;
|
||||||
|
int[] grillePlat = new int[nbLignes * nbCols];
|
||||||
|
for (int l = 0; l < nbLignes; l++)
|
||||||
|
for (int c = 0; c < nbCols; c++)
|
||||||
|
grillePlat[l * nbCols + c] = grille[l][c];
|
||||||
|
|
||||||
|
intent.putExtra("grille", grillePlat);
|
||||||
|
intent.putExtra("nbLignes", nbLignes);
|
||||||
|
intent.putExtra("nbCols", nbCols);
|
||||||
|
|
||||||
|
// Aplatissement des verrous
|
||||||
|
boolean[] verrousPlat = new boolean[nbLignes * nbCols];
|
||||||
|
for (int l = 0; l < nbLignes; l++)
|
||||||
|
for (int c = 0; c < nbCols; c++)
|
||||||
|
verrousPlat[l * nbCols + c] = verrous[l][c];
|
||||||
|
|
||||||
|
intent.putExtra("verrous", verrousPlat);
|
||||||
|
|
||||||
|
source.startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_fin_partie);
|
setContentView(R.layout.activity_fin_partie);
|
||||||
|
|
||||||
// Récupérer les données passées par le Controleur
|
// Récupérer les données passées
|
||||||
int score = getIntent().getIntExtra("score", 0);
|
int score = getIntent().getIntExtra("score", 0);
|
||||||
int nbCoups = getIntent().getIntExtra("nbCoups", 0);
|
int nbCoups = getIntent().getIntExtra("nbCoups", 0);
|
||||||
long graine = getIntent().getLongExtra("graine", 0L);
|
long graine = getIntent().getLongExtra("graine", 0L);
|
||||||
@@ -41,7 +77,7 @@ public class FinPartieActivity extends Activity {
|
|||||||
int nbLignes = getIntent().getIntExtra("nbLignes", 6);
|
int nbLignes = getIntent().getIntExtra("nbLignes", 6);
|
||||||
int nbCols = getIntent().getIntExtra("nbCols", 6);
|
int nbCols = getIntent().getIntExtra("nbCols", 6);
|
||||||
int[] grillePlat = getIntent().getIntArrayExtra("grille");
|
int[] grillePlat = getIntent().getIntArrayExtra("grille");
|
||||||
boolean[] verrouxPlat = getIntent().getBooleanArrayExtra("verrous");
|
boolean[] verrousPlat = getIntent().getBooleanArrayExtra("verrous");
|
||||||
|
|
||||||
VueGrille vueGrilleFinale = findViewById(R.id.vueGrilleFinale);
|
VueGrille vueGrilleFinale = findViewById(R.id.vueGrilleFinale);
|
||||||
|
|
||||||
@@ -53,11 +89,11 @@ public class FinPartieActivity extends Activity {
|
|||||||
vueGrilleFinale.definirGrille(grille);
|
vueGrilleFinale.definirGrille(grille);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (verrouxPlat != null && verrouxPlat.length == nbLignes * nbCols) {
|
if (verrousPlat != null && verrousPlat.length == nbLignes * nbCols) {
|
||||||
boolean[][] verrous = new boolean[nbLignes][nbCols];
|
boolean[][] verrous = new boolean[nbLignes][nbCols];
|
||||||
for (int l = 0; l < nbLignes; l++)
|
for (int l = 0; l < nbLignes; l++)
|
||||||
for (int c = 0; c < nbCols; c++)
|
for (int c = 0; c < nbCols; c++)
|
||||||
verrous[l][c] = verrouxPlat[l * nbCols + c];
|
verrous[l][c] = verrousPlat[l * nbCols + c];
|
||||||
vueGrilleFinale.definirVerrous(verrous);
|
vueGrilleFinale.definirVerrous(verrous);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,9 +107,6 @@ public class FinPartieActivity extends Activity {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// -
|
|
||||||
// RETOUR ARRIERE = menu principal
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
Intent intent = new Intent(this, MenuActivity.class);
|
Intent intent = new Intent(this, MenuActivity.class);
|
||||||
|
|||||||
Reference in New Issue
Block a user