diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index b3f7692..7bfbbb9 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -1,36 +1,36 @@ - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/sae/chuzzle/Controleur.java b/src/main/java/sae/chuzzle/Controleur.java new file mode 100644 index 0000000..90d85a2 --- /dev/null +++ b/src/main/java/sae/chuzzle/Controleur.java @@ -0,0 +1,109 @@ +package sae.chuzzle; + +import android.app.Activity; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.RadioButton; +import android.widget.Spinner; +import android.widget.TextView; +import android.widget.Toast; + +public class Controleur { + + private final Activity activite; + private final EtatJeu etatJeu; + private final VueGrille vueGrille; + + private final TextView tvScore; + private final TextView tvCoups; + private final RadioButton rbLigne; + private final RadioButton rbDroite; + private final Spinner spinnerIndex; + private final Button btnJouer; + + // - + // CONSTRUCTEUR + + + public Controleur(Activity activite, EtatJeu etatJeu, VueGrille vueGrille, + TextView tvScore, TextView tvCoups, + RadioButton rbLigne, RadioButton rbDroite, + Spinner spinnerIndex, Button btnJouer) { + + this.activite = activite; + this.etatJeu = etatJeu; + this.vueGrille = vueGrille; + this.tvScore = tvScore; + this.tvCoups = tvCoups; + this.rbLigne = rbLigne; + this.rbDroite = rbDroite; + this.spinnerIndex = spinnerIndex; + this.btnJouer = btnJouer; + + initialiserSpinner(); + rafraichirAffichage(); + } + + // - + // INITIALISATION + + + private void initialiserSpinner() { + String[] indices = {"0", "1", "2", "3", "4", "5"}; + ArrayAdapter adaptateur = new ArrayAdapter<>( + activite, + android.R.layout.simple_spinner_item, + indices + ); + adaptateur.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + spinnerIndex.setAdapter(adaptateur); + } + + // - + // GESTION DU COUP + + + public void gererCoupJoueur() { + boolean estLigne = rbLigne.isChecked(); + int index = spinnerIndex.getSelectedItemPosition(); + + int sens; + if (rbDroite.isChecked()) { + sens = +1; + } else { + sens = -1; + } + + boolean accepte = etatJeu.appliquerCoup(estLigne, index, sens); + + if (!accepte) { + Toast.makeText(activite, "Coup invalide !", Toast.LENGTH_SHORT).show(); + } + + if(accepte){ + Toast.makeText(activite, "Coup valide !", Toast.LENGTH_SHORT).show(); + } + + rafraichirAffichage(); + + if (etatJeu.estTerminee()) { + Toast.makeText( + activite, + "Partie terminee ! Score : " + etatJeu.obtenirScore(), + Toast.LENGTH_LONG + ).show(); + btnJouer.setEnabled(false); + } + } + + // - + // MISE A JOUR DE LA VUE + + + public void rafraichirAffichage() { + tvScore.setText("Score : " + etatJeu.obtenirScore()); + tvCoups.setText("Coups : " + etatJeu.obtenirNbCoups()); + vueGrille.definirGrille(etatJeu.obtenirGrille()); + vueGrille.definirVerrous(etatJeu.obtenirVerrous()); + } +} \ No newline at end of file diff --git a/src/main/java/sae/chuzzle/EtatJeu.java b/src/main/java/sae/chuzzle/EtatJeu.java index 838f8be..b4ada67 100644 --- a/src/main/java/sae/chuzzle/EtatJeu.java +++ b/src/main/java/sae/chuzzle/EtatJeu.java @@ -1,483 +1,483 @@ -package sae.chuzzle; - -import java.util.ArrayList; -import java.util.List; -import java.util.Random; - -public class EtatJeu { - - public static final int NB_LIGNES = 6; - public static final int NB_COLONNES = 6; - public static final int NB_TYPES = 7; - - private final int[][] grille = new int[NB_LIGNES][NB_COLONNES]; - private final boolean[][] verrous = new boolean[NB_LIGNES][NB_COLONNES]; - private final Random aleatoire; - - private int score = 0; - private int nbCoups = 0; - private boolean partieTerminee = false; - private boolean hardMode = false; - - // ========================================================= - // CONSTRUCTEURS - // ========================================================= - - public EtatJeu() { - aleatoire = new Random(); - initialiserGrilleSansTriples(); - } - - public EtatJeu(long graine, boolean hardMode) { - aleatoire = new Random(graine); - this.hardMode = hardMode; - initialiserGrilleSansTriples(); - } - - // ========================================================= - // GETTERS - // ========================================================= - - public int obtenirScore() { - return score; - } - - public int obtenirNbCoups() { - return nbCoups; - } - - public boolean estTerminee() { - return partieTerminee; - } - - public int obtenirCase(int ligne, int colonne) { - return grille[ligne][colonne]; - } - - public int[][] obtenirGrille() { - int[][] copie = new int[NB_LIGNES][NB_COLONNES]; - - for (int l = 0; l < NB_LIGNES; l++) { - System.arraycopy(grille[l], 0, copie[l], 0, NB_COLONNES); - } - - return copie; - } - - public boolean[][] obtenirVerrous() { - boolean[][] copie = new boolean[NB_LIGNES][NB_COLONNES]; - - for (int l = 0; l < NB_LIGNES; l++) { - System.arraycopy(verrous[l], 0, copie[l], 0, NB_COLONNES); - } - - return copie; - } - - // ========================================================= - // INITIALISATION SANS TRIPLES - // ========================================================= - - private void initialiserGrilleSansTriples() { - for (int ligne = 0; ligne < NB_LIGNES; ligne++) { - for (int colonne = 0; colonne < NB_COLONNES; colonne++) { - - int valeur; - do { - valeur = aleatoire.nextInt(NB_TYPES); - } while (creeTriple(ligne, colonne, valeur)); - - grille[ligne][colonne] = valeur; - } - } - } - - private boolean creeTriple(int ligne, int colonne, int valeur) { - - if (colonne >= 2) { - if (grille[ligne][colonne - 1] == valeur && - grille[ligne][colonne - 2] == valeur) { - return true; - } - } - - if (ligne >= 2) { - if (grille[ligne - 1][colonne] == valeur && - grille[ligne - 2][colonne] == valeur) { - return true; - } - } - - return false; - } - - // ========================================================= - // DECALAGE CIRCULAIRE - // ========================================================= - - public void decalerLigne(int ligne, int sens) { - int s = ((sens % NB_COLONNES) + NB_COLONNES) % NB_COLONNES; - - for (int etape = 0; etape < s; etape++) { - int tmp = grille[ligne][NB_COLONNES - 1]; - - for (int c = NB_COLONNES - 1; c > 0; c--) { - grille[ligne][c] = grille[ligne][c - 1]; - } - - grille[ligne][0] = tmp; - } - } - - public void decalerColonne(int colonne, int sens) { - int s = ((sens % NB_LIGNES) + NB_LIGNES) % NB_LIGNES; - - for (int etape = 0; etape < s; etape++) { - int tmp = grille[NB_LIGNES - 1][colonne]; - - for (int l = NB_LIGNES - 1; l > 0; l--) { - grille[l][colonne] = grille[l - 1][colonne]; - } - - grille[0][colonne] = tmp; - } - } - - // ========================================================= - // APPLIQUER UN COUP - // ========================================================= - - public boolean appliquerCoup(boolean estLigne, int index, int sens) { - if (partieTerminee) { - return false; - } - - if (hardMode && estBloque(estLigne, index)) { - return false; - } - - int[][] sauvegarde = copierGrille(); - - if (estLigne) { - decalerLigne(index, sens); - } else { - decalerColonne(index, sens); - } - - if (trouverSeries().isEmpty()) { - restaurerGrille(sauvegarde); - return false; - } - - nbCoups++; - score += resoudreEtRemplir(); - - if (hardMode) { - ajouterVerrou(); - } - - if (!aUnCoupValide()) { - partieTerminee = true; - } - - return true; - } - - // ========================================================= - // TROUVER LES SERIES - // ========================================================= - - public List trouverSeries() { - boolean[][] aSupprimer = new boolean[NB_LIGNES][NB_COLONNES]; - - for (int l = 0; l < NB_LIGNES; l++) { - int c = 0; - - while (c < NB_COLONNES) { - int type = grille[l][c]; - int fin = c + 1; - - while (fin < NB_COLONNES && grille[l][fin] == type) { - fin++; - } - - if (fin - c >= 3) { - for (int k = c; k < fin; k++) { - aSupprimer[l][k] = true; - } - } - - c = fin; - } - } - - for (int col = 0; col < NB_COLONNES; col++) { - int l = 0; - - while (l < NB_LIGNES) { - int type = grille[l][col]; - int fin = l + 1; - - while (fin < NB_LIGNES && grille[fin][col] == type) { - fin++; - } - - if (fin - l >= 3) { - for (int k = l; k < fin; k++) { - aSupprimer[k][col] = true; - } - } - - l = fin; - } - } - - List positions = new ArrayList<>(); - - for (int l = 0; l < NB_LIGNES; l++) { - for (int col = 0; col < NB_COLONNES; col++) { - if (aSupprimer[l][col]) { - positions.add(new int[]{l, col}); - } - } - } - - return positions; - } - - // ========================================================= - // RESOLUTION AVEC CASCADE - // ========================================================= - - public int resoudreEtRemplir() { - int pointsTotal = 0; - int vague = 0; - - List series = trouverSeries(); - - while (!series.isEmpty()) { - - int pointsBase = calculerPointsBase(series); - double multiplicateur = 1.0 + vague * 0.5; - pointsTotal += (int) (pointsBase * multiplicateur); - - boolean[][] aSupprimer = new boolean[NB_LIGNES][NB_COLONNES]; - - for (int[] pos : series) { - aSupprimer[pos[0]][pos[1]] = true; - } - - // Libérer les verrous des cases supprimées - libererVerrous(aSupprimer); - - for (int col = 0; col < NB_COLONNES; col++) { - - List survivants = new ArrayList<>(); - - for (int l = NB_LIGNES - 1; l >= 0; l--) { - if (!aSupprimer[l][col]) { - survivants.add(grille[l][col]); - } - } - - int li = NB_LIGNES - 1; - - for (int val : survivants) { - grille[li][col] = val; - li--; - } - - while (li >= 0) { - grille[li][col] = aleatoire.nextInt(NB_TYPES); - li--; - } - } - - vague++; - series = trouverSeries(); - } - - return pointsTotal; - } - - private int calculerPointsBase(List series) { - boolean[][] masque = new boolean[NB_LIGNES][NB_COLONNES]; - - for (int[] pos : series) { - masque[pos[0]][pos[1]] = true; - } - - int total = 0; - - for (int l = 0; l < NB_LIGNES; l++) { - int c = 0; - - while (c < NB_COLONNES) { - if (masque[l][c]) { - int fin = c + 1; - - while (fin < NB_COLONNES && masque[l][fin]) { - fin++; - } - - total += pointsPourLongueur(fin - c); - c = fin; - } else { - c++; - } - } - } - - for (int col = 0; col < NB_COLONNES; col++) { - int l = 0; - - while (l < NB_LIGNES) { - if (masque[l][col]) { - int fin = l + 1; - - while (fin < NB_LIGNES && masque[fin][col]) { - fin++; - } - - total += pointsPourLongueur(fin - l); - l = fin; - } else { - l++; - } - } - } - - return total; - } - - private int pointsPourLongueur(int longueur) { - if (longueur == 3) { - return 8; - } else if (longueur == 4) { - return 16; - } else if (longueur == 5) { - return 32; - } else { - return 64; - } - } - - // ========================================================= - // VERROUS (hard mode) - // ========================================================= - - private boolean estBloque(boolean estLigne, int index) { - if (estLigne) { - for (int col = 0; col < NB_COLONNES; col++) { - if (verrous[index][col]) { - return true; - } - } - } else { - for (int lig = 0; lig < NB_LIGNES; lig++) { - if (verrous[lig][index]) { - return true; - } - } - } - - return false; - } - - private void ajouterVerrou() { - int intervalle = Math.max(1, 5 - nbCoups / 10); - - if (nbCoups % intervalle != 0) { - return; - } - - List casesLibres = new ArrayList<>(); - - for (int l = 0; l < NB_LIGNES; l++) { - for (int col = 0; col < NB_COLONNES; col++) { - if (!verrous[l][col]) { - casesLibres.add(new int[]{l, col}); - } - } - } - - if (casesLibres.isEmpty()) { - return; - } - - int[] caseChoisie = casesLibres.get(aleatoire.nextInt(casesLibres.size())); - verrous[caseChoisie[0]][caseChoisie[1]] = true; - } - - private void libererVerrous(boolean[][] aSupprimer) { - for (int l = 0; l < NB_LIGNES; l++) { - for (int col = 0; col < NB_COLONNES; col++) { - if (aSupprimer[l][col]) { - verrous[l][col] = false; - } - } - } - } - - // ========================================================= - // DETECTION FIN DE PARTIE - // ========================================================= - - public boolean aUnCoupValide() { - for (int i = 0; i < NB_LIGNES; i++) { - if (coupCreeSerie(true, i, +1)) { - return true; - } - if (coupCreeSerie(true, i, -1)) { - return true; - } - } - - for (int j = 0; j < NB_COLONNES; j++) { - if (coupCreeSerie(false, j, +1)) { - return true; - } - if (coupCreeSerie(false, j, -1)) { - return true; - } - } - - return false; - } - - private boolean coupCreeSerie(boolean estLigne, int index, int sens) { - int[][] sauvegarde = copierGrille(); - - if (estLigne) { - decalerLigne(index, sens); - } else { - decalerColonne(index, sens); - } - - boolean resultat = !trouverSeries().isEmpty(); - - restaurerGrille(sauvegarde); - - return resultat; - } - - // ========================================================= - // UTILITAIRES PRIVES - // ========================================================= - - private int[][] copierGrille() { - int[][] copie = new int[NB_LIGNES][NB_COLONNES]; - - for (int l = 0; l < NB_LIGNES; l++) { - System.arraycopy(grille[l], 0, copie[l], 0, NB_COLONNES); - } - - return copie; - } - - private void restaurerGrille(int[][] sauvegarde) { - for (int l = 0; l < NB_LIGNES; l++) { - System.arraycopy(sauvegarde[l], 0, grille[l], 0, NB_COLONNES); - } - } +package sae.chuzzle; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +public class EtatJeu { + + public static final int NB_LIGNES = 6; + public static final int NB_COLONNES = 6; + public static final int NB_TYPES = 7; + + private final int[][] grille = new int[NB_LIGNES][NB_COLONNES]; + private final boolean[][] verrous = new boolean[NB_LIGNES][NB_COLONNES]; + private final Random aleatoire; + + private int score = 0; + private int nbCoups = 0; + private boolean partieTerminee = false; + private boolean hardMode = false; + + //- + // CONSTRUCTEURS + + + public EtatJeu() { + aleatoire = new Random(); + initialiserGrilleSansTriples(); + } + + public EtatJeu(long graine, boolean hardMode) { + aleatoire = new Random(graine); + this.hardMode = hardMode; + initialiserGrilleSansTriples(); + } + + // - + // GETTERS + + + public int obtenirScore() { + return score; + } + + public int obtenirNbCoups() { + return nbCoups; + } + + public boolean estTerminee() { + return partieTerminee; + } + + public int obtenirCase(int ligne, int colonne) { + return grille[ligne][colonne]; + } + + public int[][] obtenirGrille() { + int[][] copie = new int[NB_LIGNES][NB_COLONNES]; + + for (int l = 0; l < NB_LIGNES; l++) { + System.arraycopy(grille[l], 0, copie[l], 0, NB_COLONNES); + } + + return copie; + } + + public boolean[][] obtenirVerrous() { + boolean[][] copie = new boolean[NB_LIGNES][NB_COLONNES]; + + for (int l = 0; l < NB_LIGNES; l++) { + System.arraycopy(verrous[l], 0, copie[l], 0, NB_COLONNES); + } + + return copie; + } + + // - + // INITIALISATION SANS TRIPLES + // + + private void initialiserGrilleSansTriples() { + for (int ligne = 0; ligne < NB_LIGNES; ligne++) { + for (int colonne = 0; colonne < NB_COLONNES; colonne++) { + + int valeur; + do { + valeur = aleatoire.nextInt(NB_TYPES); + } while (creeTriple(ligne, colonne, valeur)); + + grille[ligne][colonne] = valeur; + } + } + } + + private boolean creeTriple(int ligne, int colonne, int valeur) { + + if (colonne >= 2) { + if (grille[ligne][colonne - 1] == valeur && + grille[ligne][colonne - 2] == valeur) { + return true; + } + } + + if (ligne >= 2) { + if (grille[ligne - 1][colonne] == valeur && + grille[ligne - 2][colonne] == valeur) { + return true; + } + } + + return false; + } + + // - + // DECALAGE CIRCULAIRE + + + public void decalerLigne(int ligne, int sens) { + int s = ((sens % NB_COLONNES) + NB_COLONNES) % NB_COLONNES; + + for (int etape = 0; etape < s; etape++) { + int tmp = grille[ligne][NB_COLONNES - 1]; + + for (int c = NB_COLONNES - 1; c > 0; c--) { + grille[ligne][c] = grille[ligne][c - 1]; + } + + grille[ligne][0] = tmp; + } + } + + public void decalerColonne(int colonne, int sens) { + int s = ((sens % NB_LIGNES) + NB_LIGNES) % NB_LIGNES; + + for (int etape = 0; etape < s; etape++) { + int tmp = grille[NB_LIGNES - 1][colonne]; + + for (int l = NB_LIGNES - 1; l > 0; l--) { + grille[l][colonne] = grille[l - 1][colonne]; + } + + grille[0][colonne] = tmp; + } + } + + // - + // APPLIQUER UN COUP + + + public boolean appliquerCoup(boolean estLigne, int index, int sens) { + if (partieTerminee) { + return false; + } + + if (hardMode && estBloque(estLigne, index)) { + return false; + } + + int[][] sauvegarde = copierGrille(); + + if (estLigne) { + decalerLigne(index, sens); + } else { + decalerColonne(index, sens); + } + + if (trouverSeries().isEmpty()) { + restaurerGrille(sauvegarde); + return false; + } + + nbCoups++; + score += resoudreEtRemplir(); + + if (hardMode) { + ajouterVerrou(); + } + + if (!aUnCoupValide()) { + partieTerminee = true; + } + + return true; + } + + // - + // TROUVER LES SERIES + + + public List trouverSeries() { + boolean[][] aSupprimer = new boolean[NB_LIGNES][NB_COLONNES]; + + for (int l = 0; l < NB_LIGNES; l++) { + int c = 0; + + while (c < NB_COLONNES) { + int type = grille[l][c]; + int fin = c + 1; + + while (fin < NB_COLONNES && grille[l][fin] == type) { + fin++; + } + + if (fin - c >= 3) { + for (int k = c; k < fin; k++) { + aSupprimer[l][k] = true; + } + } + + c = fin; + } + } + + for (int col = 0; col < NB_COLONNES; col++) { + int l = 0; + + while (l < NB_LIGNES) { + int type = grille[l][col]; + int fin = l + 1; + + while (fin < NB_LIGNES && grille[fin][col] == type) { + fin++; + } + + if (fin - l >= 3) { + for (int k = l; k < fin; k++) { + aSupprimer[k][col] = true; + } + } + + l = fin; + } + } + + List positions = new ArrayList<>(); + + for (int l = 0; l < NB_LIGNES; l++) { + for (int col = 0; col < NB_COLONNES; col++) { + if (aSupprimer[l][col]) { + positions.add(new int[]{l, col}); + } + } + } + + return positions; + } + + // - + // RESOLUTION AVEC CASCADE + + + public int resoudreEtRemplir() { + int pointsTotal = 0; + int vague = 0; + + List series = trouverSeries(); + + while (!series.isEmpty()) { + + int pointsBase = calculerPointsBase(series); + double multiplicateur = 1.0 + vague * 0.5; + pointsTotal += (int) (pointsBase * multiplicateur); + + boolean[][] aSupprimer = new boolean[NB_LIGNES][NB_COLONNES]; + + for (int[] pos : series) { + aSupprimer[pos[0]][pos[1]] = true; + } + + // Libérer les verrous des cases supprimées + libererVerrous(aSupprimer); + + for (int col = 0; col < NB_COLONNES; col++) { + + List survivants = new ArrayList<>(); + + for (int l = NB_LIGNES - 1; l >= 0; l--) { + if (!aSupprimer[l][col]) { + survivants.add(grille[l][col]); + } + } + + int li = NB_LIGNES - 1; + + for (int val : survivants) { + grille[li][col] = val; + li--; + } + + while (li >= 0) { + grille[li][col] = aleatoire.nextInt(NB_TYPES); + li--; + } + } + + vague++; + series = trouverSeries(); + } + + return pointsTotal; + } + + private int calculerPointsBase(List series) { + boolean[][] masque = new boolean[NB_LIGNES][NB_COLONNES]; + + for (int[] pos : series) { + masque[pos[0]][pos[1]] = true; + } + + int total = 0; + + for (int l = 0; l < NB_LIGNES; l++) { + int c = 0; + + while (c < NB_COLONNES) { + if (masque[l][c]) { + int fin = c + 1; + + while (fin < NB_COLONNES && masque[l][fin]) { + fin++; + } + + total += pointsPourLongueur(fin - c); + c = fin; + } else { + c++; + } + } + } + + for (int col = 0; col < NB_COLONNES; col++) { + int l = 0; + + while (l < NB_LIGNES) { + if (masque[l][col]) { + int fin = l + 1; + + while (fin < NB_LIGNES && masque[fin][col]) { + fin++; + } + + total += pointsPourLongueur(fin - l); + l = fin; + } else { + l++; + } + } + } + + return total; + } + + private int pointsPourLongueur(int longueur) { + if (longueur == 3) { + return 8; + } else if (longueur == 4) { + return 16; + } else if (longueur == 5) { + return 32; + } else { + return 64; + } + } + + // - + // VERROUS (hard mode) + + + private boolean estBloque(boolean estLigne, int index) { + if (estLigne) { + for (int col = 0; col < NB_COLONNES; col++) { + if (verrous[index][col]) { + return true; + } + } + } else { + for (int lig = 0; lig < NB_LIGNES; lig++) { + if (verrous[lig][index]) { + return true; + } + } + } + + return false; + } + + private void ajouterVerrou() { + int intervalle = Math.max(1, 5 - nbCoups / 10); + + if (nbCoups % intervalle != 0) { + return; + } + + List casesLibres = new ArrayList<>(); + + for (int l = 0; l < NB_LIGNES; l++) { + for (int col = 0; col < NB_COLONNES; col++) { + if (!verrous[l][col]) { + casesLibres.add(new int[]{l, col}); + } + } + } + + if (casesLibres.isEmpty()) { + return; + } + + int[] caseChoisie = casesLibres.get(aleatoire.nextInt(casesLibres.size())); + verrous[caseChoisie[0]][caseChoisie[1]] = true; + } + + private void libererVerrous(boolean[][] aSupprimer) { + for (int l = 0; l < NB_LIGNES; l++) { + for (int col = 0; col < NB_COLONNES; col++) { + if (aSupprimer[l][col]) { + verrous[l][col] = false; + } + } + } + } + + // - + // DETECTION FIN DE PARTIE + + + public boolean aUnCoupValide() { + for (int i = 0; i < NB_LIGNES; i++) { + if (coupCreeSerie(true, i, +1)) { + return true; + } + if (coupCreeSerie(true, i, -1)) { + return true; + } + } + + for (int j = 0; j < NB_COLONNES; j++) { + if (coupCreeSerie(false, j, +1)) { + return true; + } + if (coupCreeSerie(false, j, -1)) { + return true; + } + } + + return false; + } + + private boolean coupCreeSerie(boolean estLigne, int index, int sens) { + int[][] sauvegarde = copierGrille(); + + if (estLigne) { + decalerLigne(index, sens); + } else { + decalerColonne(index, sens); + } + + boolean resultat = !trouverSeries().isEmpty(); + + restaurerGrille(sauvegarde); + + return resultat; + } + + // - + // UTILITAIRES PRIVES + + + private int[][] copierGrille() { + int[][] copie = new int[NB_LIGNES][NB_COLONNES]; + + for (int l = 0; l < NB_LIGNES; l++) { + System.arraycopy(grille[l], 0, copie[l], 0, NB_COLONNES); + } + + return copie; + } + + private void restaurerGrille(int[][] sauvegarde) { + for (int l = 0; l < NB_LIGNES; l++) { + System.arraycopy(sauvegarde[l], 0, grille[l], 0, NB_COLONNES); + } + } } \ No newline at end of file diff --git a/src/main/java/sae/chuzzle/MainActivity.java b/src/main/java/sae/chuzzle/MainActivity.java index a5e5f21..3269e09 100644 --- a/src/main/java/sae/chuzzle/MainActivity.java +++ b/src/main/java/sae/chuzzle/MainActivity.java @@ -1,124 +1,57 @@ -package sae.chuzzle; - -import android.app.Activity; -import android.os.Bundle; -import android.view.View; -import android.widget.ArrayAdapter; -import android.widget.Button; -import android.widget.RadioButton; -import android.widget.Spinner; -import android.widget.TextView; -import android.widget.Toast; - -import sae.chuzzle.EtatJeu; -import sae.chuzzle.VueGrille; - -public class MainActivity extends Activity implements View.OnClickListener { - - private EtatJeu etatJeu; - private VueGrille vueGrille; - private TextView tvScore; - private TextView tvCoups; - private RadioButton rbLigne; - private RadioButton rbDroite; - private Spinner spinnerIndex; - private Button btnJouer; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - - // - Lire la graine et les options - long graine = getIntent().getLongExtra("graine", System.currentTimeMillis()); - boolean daltonien = getSharedPreferences("chuzzle_prefs", MODE_PRIVATE) - .getBoolean("daltonien", false); - boolean hardMode = getSharedPreferences("chuzzle_prefs", MODE_PRIVATE) - .getBoolean("hard_mode", false); - - // - Modèle - etatJeu = new EtatJeu(graine, hardMode); - - // - Récupérer les vues depuis le XML - tvScore = findViewById(R.id.tvScore); - tvCoups = findViewById(R.id.tvCoups); - vueGrille = findViewById(R.id.vueGrille); - rbLigne = findViewById(R.id.rbLigne); - rbDroite = findViewById(R.id.rbDroite); - spinnerIndex = findViewById(R.id.spinnerIndex); - btnJouer = findViewById(R.id.btnJouer); - - // - Configurer la vue - vueGrille.definirGrille(etatJeu.obtenirGrille()); - vueGrille.definirVerrous(etatJeu.obtenirVerrous()); - vueGrille.definirModeDaltonien(daltonien); - - // - Configurer le spinner - String[] indices = {"0", "1", "2", "3", "4", "5"}; - ArrayAdapter adaptateur = new ArrayAdapter<>( - this, - android.R.layout.simple_spinner_item, - indices - ); - adaptateur.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - spinnerIndex.setAdapter(adaptateur); - - // --- Bouton jouer --- - btnJouer.setOnClickListener(this); - } - - - // GESTION DES CLICS - - - @Override - public void onClick(View v) { - if (v == btnJouer) { - gererCoupJoueur(); - } - } - - - // COORDINATION - - - private void gererCoupJoueur() { - boolean estLigne = rbLigne.isChecked(); - int index = spinnerIndex.getSelectedItemPosition(); - - int sens; - if (rbDroite.isChecked()) { - sens = +1; - } else { - sens = -1; - } - - boolean accepte = etatJeu.appliquerCoup(estLigne, index, sens); - - if (!accepte) { - Toast.makeText( - this, - "Coup invalide : aucune serie creee !", - Toast.LENGTH_SHORT - ).show(); - } - - rafraichirAffichage(); - - if (etatJeu.estTerminee()) { - Toast.makeText( - this, - "Partie terminee ! Score final : " + etatJeu.obtenirScore(), - Toast.LENGTH_LONG - ).show(); - btnJouer.setEnabled(false); - } - } - - private void rafraichirAffichage() { - tvScore.setText("Score : " + etatJeu.obtenirScore()); - tvCoups.setText("Coups : " + etatJeu.obtenirNbCoups()); - vueGrille.definirGrille(etatJeu.obtenirGrille()); - vueGrille.definirVerrous(etatJeu.obtenirVerrous()); - } +package sae.chuzzle; + +import android.app.Activity; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.RadioButton; +import android.widget.Spinner; +import android.widget.TextView; + +public class MainActivity extends Activity implements View.OnClickListener { + + private Controleur controleur; + private Button btnJouer; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + // --- Modèle --- + long graine = getIntent().getLongExtra("graine", System.currentTimeMillis()); + boolean hardMode = getSharedPreferences("chuzzle_prefs", MODE_PRIVATE) + .getBoolean("hard_mode", false); + boolean daltonien = getSharedPreferences("chuzzle_prefs", MODE_PRIVATE) + .getBoolean("daltonien", false); + + EtatJeu etatJeu = new EtatJeu(graine, hardMode); + + // --- Vue --- + VueGrille vueGrille = findViewById(R.id.vueGrille); + vueGrille.definirModeDaltonien(daltonien); + + // --- Controleur --- + btnJouer = findViewById(R.id.btnJouer); + btnJouer.setOnClickListener(this); + + controleur = new Controleur( + this, + etatJeu, + vueGrille, + (TextView) findViewById(R.id.tvScore), + (TextView) findViewById(R.id.tvCoups), + (RadioButton) findViewById(R.id.rbLigne), + (RadioButton) findViewById(R.id.rbDroite), + (Spinner) findViewById(R.id.spinnerIndex), + btnJouer + ); + } + + @Override + public void onClick(View v) { + if (v == btnJouer) { + controleur.gererCoupJoueur(); + } + } } \ No newline at end of file diff --git a/src/main/java/sae/chuzzle/MenuActivity.java b/src/main/java/sae/chuzzle/MenuActivity.java index c1ac3e8..ecc5092 100644 --- a/src/main/java/sae/chuzzle/MenuActivity.java +++ b/src/main/java/sae/chuzzle/MenuActivity.java @@ -1,44 +1,44 @@ -package sae.chuzzle; - -import android.app.Activity; -import android.content.Intent; -import android.os.Bundle; -import android.view.View; -import android.widget.Button; - -public class MenuActivity extends Activity implements View.OnClickListener { - - private Button btnNouvellePartie; - private Button btnPartieGraine; - private Button btnOptions; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_menu); - - btnNouvellePartie = findViewById(R.id.btnNouvellePartie); - btnPartieGraine = findViewById(R.id.btnPartieGraine); - btnOptions = findViewById(R.id.btnOptions); - - btnNouvellePartie.setOnClickListener(this); - btnPartieGraine.setOnClickListener(this); - btnOptions.setOnClickListener(this); - } - - @Override - public void onClick(View v) { - if (v == btnNouvellePartie) { - long graine = System.currentTimeMillis(); - Intent intent = new Intent(this, MainActivity.class); - intent.putExtra("graine", graine); - startActivity(intent); - } else if (v == btnPartieGraine) { - Intent intent = new Intent(this, SeedActivity.class); - startActivity(intent); - } else if (v == btnOptions) { - Intent intent = new Intent(this, OptionsActivity.class); - startActivity(intent); - } - } +package sae.chuzzle; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; + +public class MenuActivity extends Activity implements View.OnClickListener { + + private Button btnNouvellePartie; + private Button btnPartieGraine; + private Button btnOptions; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_menu); + + btnNouvellePartie = findViewById(R.id.btnNouvellePartie); + btnPartieGraine = findViewById(R.id.btnPartieGraine); + btnOptions = findViewById(R.id.btnOptions); + + btnNouvellePartie.setOnClickListener(this); + btnPartieGraine.setOnClickListener(this); + btnOptions.setOnClickListener(this); + } + + @Override + public void onClick(View v) { + if (v == btnNouvellePartie) { + long graine = System.currentTimeMillis(); + Intent intent = new Intent(this, MainActivity.class); + intent.putExtra("graine", graine); + startActivity(intent); + } else if (v == btnPartieGraine) { + Intent intent = new Intent(this, SeedActivity.class); + startActivity(intent); + } else if (v == btnOptions) { + Intent intent = new Intent(this, OptionsActivity.class); + startActivity(intent); + } + } } \ No newline at end of file diff --git a/src/main/java/sae/chuzzle/OptionsActivity.java b/src/main/java/sae/chuzzle/OptionsActivity.java index 8d082cc..bfa73b1 100644 --- a/src/main/java/sae/chuzzle/OptionsActivity.java +++ b/src/main/java/sae/chuzzle/OptionsActivity.java @@ -1,41 +1,41 @@ -package sae.chuzzle; - -import android.app.Activity; -import android.content.SharedPreferences; -import android.os.Bundle; -import android.widget.CompoundButton; -import android.widget.Switch; - -public class OptionsActivity extends Activity - implements CompoundButton.OnCheckedChangeListener { - - private SharedPreferences prefs; - private Switch switchDaltonien; - private Switch switchHard; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_options); - - prefs = getSharedPreferences("chuzzle_prefs", MODE_PRIVATE); - - switchDaltonien = findViewById(R.id.switchDaltonien); - switchHard = findViewById(R.id.switchHard); - - switchDaltonien.setChecked(prefs.getBoolean("daltonien", false)); - switchHard.setChecked(prefs.getBoolean("hard_mode", false)); - - switchDaltonien.setOnCheckedChangeListener(this); - switchHard.setOnCheckedChangeListener(this); - } - - @Override - public void onCheckedChanged(CompoundButton bouton, boolean estCoche) { - if (bouton == switchDaltonien) { - prefs.edit().putBoolean("daltonien", estCoche).apply(); - } else if (bouton == switchHard) { - prefs.edit().putBoolean("hard_mode", estCoche).apply(); - } - } +package sae.chuzzle; + +import android.app.Activity; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.widget.CheckBox; +import android.widget.CompoundButton; + +public class OptionsActivity extends Activity + implements CompoundButton.OnCheckedChangeListener { + + private SharedPreferences prefs; + private CheckBox checkDaltonien; + private CheckBox checkHard; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_options); + + prefs = getSharedPreferences("chuzzle_prefs", MODE_PRIVATE); + + checkDaltonien = findViewById(R.id.switchDaltonien); + checkHard = findViewById(R.id.switchHard); + + checkDaltonien.setChecked(prefs.getBoolean("daltonien", false)); + checkHard.setChecked(prefs.getBoolean("hard_mode", false)); + + checkDaltonien.setOnCheckedChangeListener(this); + checkHard.setOnCheckedChangeListener(this); + } + + @Override + public void onCheckedChanged(CompoundButton bouton, boolean estCoche) { + if (bouton == checkDaltonien) { + prefs.edit().putBoolean("daltonien", estCoche).apply(); + } else if (bouton == checkHard) { + prefs.edit().putBoolean("hard_mode", estCoche).apply(); + } + } } \ No newline at end of file diff --git a/src/main/java/sae/chuzzle/SeedActivity.java b/src/main/java/sae/chuzzle/SeedActivity.java index 50534b3..f6e3ca0 100644 --- a/src/main/java/sae/chuzzle/SeedActivity.java +++ b/src/main/java/sae/chuzzle/SeedActivity.java @@ -1,59 +1,58 @@ -package sae.chuzzle; - -import android.app.Activity; -import android.content.Intent; -import android.os.Bundle; -import android.view.View; -import android.widget.Button; -import android.widget.EditText; -import android.widget.Toast; - - -public class SeedActivity extends Activity implements View.OnClickListener { - - private EditText etGraine; - private Button btnJouer; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_seed); - - etGraine = findViewById(R.id.etGraine); - btnJouer = findViewById(R.id.btnJouer); - - btnJouer.setOnClickListener(this); - } - - @Override - public void onClick(View v) { - if (v == btnJouer) { - lancerPartieAvecGraine(); - } - } - - private void lancerPartieAvecGraine() { - String texte = etGraine.getText().toString().trim(); - - if (texte.isEmpty()) { - Toast.makeText( - this, - "Veuillez entrer une graine.", - Toast.LENGTH_SHORT - ).show(); - return; - } - - long graine; - - try { - graine = Long.parseLong(texte); - } catch (NumberFormatException e) { - graine = texte.hashCode(); - } - - Intent intent = new Intent(this, MainActivity.class); - intent.putExtra("graine", graine); - startActivity(intent); - } +package sae.chuzzle; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +public class SeedActivity extends Activity implements View.OnClickListener { + + private EditText etGraine; + private Button btnJouer; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_seed); + + etGraine = findViewById(R.id.etGraine); + btnJouer = findViewById(R.id.btnJouer); + + btnJouer.setOnClickListener(this); + } + + @Override + public void onClick(View v) { + if (v == btnJouer) { + lancerPartieAvecGraine(); + } + } + + private void lancerPartieAvecGraine() { + String texte = etGraine.getText().toString().trim(); + + if (texte.isEmpty()) { + Toast.makeText( + this, + "Veuillez entrer une graine.", + Toast.LENGTH_SHORT + ).show(); + return; + } + + long graine; + + try { + graine = Long.parseLong(texte); + } catch (NumberFormatException e) { + graine = texte.hashCode(); + } + + Intent intent = new Intent(this, MainActivity.class); + intent.putExtra("graine", graine); + startActivity(intent); + } } \ No newline at end of file diff --git a/src/main/java/sae/chuzzle/VueGrille.java b/src/main/java/sae/chuzzle/VueGrille.java index 7e9ef85..24805d7 100644 --- a/src/main/java/sae/chuzzle/VueGrille.java +++ b/src/main/java/sae/chuzzle/VueGrille.java @@ -1,146 +1,158 @@ -package sae.chuzzle; - -import android.content.Context; -import android.graphics.Canvas; -import android.graphics.Paint; -import android.view.View; - -import androidx.annotation.NonNull; - -public class VueGrille extends View { - private boolean[][] verrous = new boolean[NB_LIGNES][NB_COLONNES]; - - private static final int NB_LIGNES = 6; - private static final int NB_COLONNES = 6; - private static final int NB_TYPES = 7; - - // Symboles pour le mode daltonien, un par type - private static final String[] SYMBOLES = {"●", "■", "▲", "✚", "★", "♦", "✿"}; - - // La VueGrille ne reçoit qu'un tableau int[][] brut, pas un EtatJeu - private int[][] grille = new int[NB_LIGNES][NB_COLONNES]; - private boolean modeDaltonien = false; - - private final Paint pinceauCase = new Paint(); - private final Paint pinceauSymbole = new Paint(); - - // ========================================================= - // CONSTRUCTEUR - // ========================================================= - - public VueGrille(Context contexte) { - super(contexte); - - pinceauCase.setAntiAlias(true); - pinceauCase.setStyle(Paint.Style.FILL); - - pinceauSymbole.setAntiAlias(true); - pinceauSymbole.setColor(0xFF000000); - pinceauSymbole.setTextAlign(Paint.Align.CENTER); - } - - // ========================================================= - // API PUBLIQUE (appelée par MainActivity uniquement) - // ========================================================= - - /** - * Reçoit une copie de la grille depuis MainActivity. - * VueGrille ne sait pas d'où viennent ces données, - * elle sait juste les dessiner. - */ - public void definirGrille(int[][] nouvelleGrille) { - for (int l = 0; l < NB_LIGNES; l++) { - System.arraycopy(nouvelleGrille[l], 0, grille[l], 0, NB_COLONNES); - } - invalidate(); - } - - public void definirModeDaltonien(boolean actif) { - this.modeDaltonien = actif; - invalidate(); - } - - // ========================================================= - // DESSIN - // ========================================================= - - @Override - protected void onDraw(@NonNull Canvas canvas) { - super.onDraw(canvas); - - int largeur = getWidth(); - int hauteur = getHeight(); - - float tailleCase = Math.min( - largeur / (float) NB_COLONNES, - hauteur / (float) NB_LIGNES - ); - - float margeGauche = (largeur - tailleCase * NB_COLONNES) / 2f; - float margeHaut = (hauteur - tailleCase * NB_LIGNES) / 2f; - - pinceauSymbole.setTextSize(tailleCase * 0.4f); - - for (int ligne = 0; ligne < NB_LIGNES; ligne++) { - for (int colonne = 0; colonne < NB_COLONNES; colonne++) { - - int type = grille[ligne][colonne]; - - float x1 = margeGauche + colonne * tailleCase + 6; - float y1 = margeHaut + ligne * tailleCase + 6; - float x2 = margeGauche + (colonne + 1) * tailleCase - 6; - float y2 = margeHaut + (ligne + 1) * tailleCase - 6; - - // Dessiner la case colorée - // Dessiner la case colorée - definirCouleur(type); - canvas.drawRoundRect(x1, y1, x2, y2, 20, 20, pinceauCase); - -// Assombrir la case si elle est verrouillée - if (verrous[ligne][colonne]) { - pinceauCase.setARGB(120, 0, 0, 0); - canvas.drawRoundRect(x1, y1, x2, y2, 20, 20, pinceauCase); - } - -// Dessiner le symbole daltonien - if (modeDaltonien) { - float cx = (x1 + x2) / 2f; - float cy = (y1 + y2) / 2f - - (pinceauSymbole.descent() + pinceauSymbole.ascent()) / 2f; - canvas.drawText(SYMBOLES[type % NB_TYPES], cx, cy, pinceauSymbole); - } - -// Dessiner le cadenas par-dessus si verrouillée - if (verrous[ligne][colonne]) { - float cx = (x1 + x2) / 2f; - float cy = (y1 + y2) / 2f - - (pinceauSymbole.descent() + pinceauSymbole.ascent()) / 2f; - canvas.drawText("🔒", cx, cy, pinceauSymbole); - } - } - } - } - - // ========================================================= - // UTILITAIRE PRIVE - // ========================================================= - - private void definirCouleur(int type) { - switch (type % NB_TYPES) { - case 0: pinceauCase.setARGB(255, 200, 200, 200); break; - case 1: pinceauCase.setARGB(255, 255, 105, 180); break; - case 2: pinceauCase.setARGB(255, 90, 230, 200); break; - case 3: pinceauCase.setARGB(255, 100, 170, 255); break; - case 4: pinceauCase.setARGB(255, 255, 220, 90); break; - case 5: pinceauCase.setARGB(255, 255, 140, 90); break; - case 6: pinceauCase.setARGB(255, 255, 90, 90); break; - } - } - public void definirVerrous(boolean[][] nouveauxVerrous) { - for (int l = 0; l < NB_LIGNES; l++) { - System.arraycopy(nouveauxVerrous[l], 0, verrous[l], 0, NB_COLONNES); - } - invalidate(); - } - +package sae.chuzzle; + +import android.content.Context; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.util.AttributeSet; +import android.view.View; + +import androidx.annotation.NonNull; + +public class VueGrille extends View { + private boolean[][] verrous = new boolean[NB_LIGNES][NB_COLONNES]; + + private static final int NB_LIGNES = 6; + private static final int NB_COLONNES = 6; + private static final int NB_TYPES = 7; + + // Symboles pour le mode daltonien, un par type + private static final String[] SYMBOLES = {"●", "■", "▲", "✚", "★", "♦", "✿"}; + + // La VueGrille ne reçoit qu'un tableau int[][] brut, pas un EtatJeu + private int[][] grille = new int[NB_LIGNES][NB_COLONNES]; + private boolean modeDaltonien = false; + + private final Paint pinceauCase = new Paint(); + private final Paint pinceauSymbole = new Paint(); + + // ========================================================= + // CONSTRUCTEUR + // ========================================================= + + public VueGrille(Context contexte) { + super(contexte); + + pinceauCase.setAntiAlias(true); + pinceauCase.setStyle(Paint.Style.FILL); + + pinceauSymbole.setAntiAlias(true); + pinceauSymbole.setColor(0xFF000000); + pinceauSymbole.setTextAlign(Paint.Align.CENTER); + } + + public VueGrille(Context context, AttributeSet attrs) { + super(context, attrs); + + pinceauCase.setAntiAlias(true); + pinceauCase.setStyle(Paint.Style.FILL); + + pinceauSymbole.setAntiAlias(true); + pinceauSymbole.setColor(0xFF000000); + pinceauSymbole.setTextAlign(Paint.Align.CENTER); + } + + + // API PUBLIQUE (appelée par MainActivity uniquement) + + + /** + * Reçoit une copie de la grille depuis MainActivity. + * VueGrille ne sait pas d'où viennent ces données, + * elle sait juste les dessiner. + */ + public void definirGrille(int[][] nouvelleGrille) { + for (int l = 0; l < NB_LIGNES; l++) { + System.arraycopy(nouvelleGrille[l], 0, grille[l], 0, NB_COLONNES); + } + invalidate(); + } + + public void definirModeDaltonien(boolean actif) { + this.modeDaltonien = actif; + invalidate(); + } + + // - + // DESSIN + + + @Override + protected void onDraw(@NonNull Canvas canvas) { + super.onDraw(canvas); + + int largeur = getWidth(); + int hauteur = getHeight(); + + float tailleCase = Math.min( + largeur / (float) NB_COLONNES, + hauteur / (float) NB_LIGNES + ); + + float margeGauche = (largeur - tailleCase * NB_COLONNES) / 2f; + float margeHaut = (hauteur - tailleCase * NB_LIGNES) / 2f; + + pinceauSymbole.setTextSize(tailleCase * 0.4f); + + for (int ligne = 0; ligne < NB_LIGNES; ligne++) { + for (int colonne = 0; colonne < NB_COLONNES; colonne++) { + + int type = grille[ligne][colonne]; + + float x1 = margeGauche + colonne * tailleCase + 6; + float y1 = margeHaut + ligne * tailleCase + 6; + float x2 = margeGauche + (colonne + 1) * tailleCase - 6; + float y2 = margeHaut + (ligne + 1) * tailleCase - 6; + + // Dessiner la case colorée + // Dessiner la case colorée + definirCouleur(type); + canvas.drawRoundRect(x1, y1, x2, y2, 20, 20, pinceauCase); + +// Assombrir la case si elle est verrouillée + if (verrous[ligne][colonne]) { + pinceauCase.setARGB(120, 0, 0, 0); + canvas.drawRoundRect(x1, y1, x2, y2, 20, 20, pinceauCase); + } + +// Dessiner le symbole daltonien + if (modeDaltonien) { + float cx = (x1 + x2) / 2f; + float cy = (y1 + y2) / 2f + - (pinceauSymbole.descent() + pinceauSymbole.ascent()) / 2f; + canvas.drawText(SYMBOLES[type % NB_TYPES], cx, cy, pinceauSymbole); + } + +// Dessiner le cadenas par-dessus si verrouillée + if (verrous[ligne][colonne]) { + float cx = (x1 + x2) / 2f; + float cy = (y1 + y2) / 2f + - (pinceauSymbole.descent() + pinceauSymbole.ascent()) / 2f; + canvas.drawText("🔒", cx, cy, pinceauSymbole); + } + } + } + } + + // - + // UTILITAIRE PRIVE + + + private void definirCouleur(int type) { + switch (type % NB_TYPES) { + case 0: pinceauCase.setARGB(255, 200, 200, 200); break; + case 1: pinceauCase.setARGB(255, 255, 105, 180); break; + case 2: pinceauCase.setARGB(255, 90, 230, 200); break; + case 3: pinceauCase.setARGB(255, 100, 170, 255); break; + case 4: pinceauCase.setARGB(255, 255, 220, 90); break; + case 5: pinceauCase.setARGB(255, 255, 140, 90); break; + case 6: pinceauCase.setARGB(255, 255, 90, 90); break; + } + } + public void definirVerrous(boolean[][] nouveauxVerrous) { + for (int l = 0; l < NB_LIGNES; l++) { + System.arraycopy(nouveauxVerrous[l], 0, verrous[l], 0, NB_COLONNES); + } + invalidate(); + } + } \ No newline at end of file diff --git a/src/main/res/drawable/ic_launcher_foreground.xml b/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/res/layout/activity_main.xml b/src/main/res/layout/activity_main.xml index 2092eaa..0ba5036 100644 --- a/src/main/res/layout/activity_main.xml +++ b/src/main/res/layout/activity_main.xml @@ -1,86 +1,86 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - -