refactor: split in init vueGrille initialization of vueGrille rather than in constructor
This commit is contained in:
@@ -31,10 +31,15 @@ public class App {
|
|||||||
IO io = new IO(jeu);
|
IO io = new IO(jeu);
|
||||||
vueTetris.addKeyListener(io);
|
vueTetris.addKeyListener(io);
|
||||||
|
|
||||||
new TetrisBandeauControleur(vueTetris.getVueBandeauControle(), musique, grille);// Création d'un
|
new TetrisBandeauControleur(vueTetris.getVueBandeauControle(), musique, grille);// Création d'un controleur de
|
||||||
// controleur de
|
// bandeau avec la musique
|
||||||
// bandeau avec la
|
|
||||||
// musique
|
|
||||||
// instanciée
|
// instanciée
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: RESTE A IMPLEMENTER
|
||||||
|
// - rotation
|
||||||
|
// - score
|
||||||
|
// - lignes
|
||||||
|
// - menu pour fin de partie
|
||||||
|
// ext possible: conserver un historique de score dans un fichier txt ?
|
||||||
}
|
}
|
||||||
@@ -31,23 +31,7 @@ public class VueGrille extends JPanel implements Observer, Runnable {
|
|||||||
this.nbLignes = grille.getNbLignes();
|
this.nbLignes = grille.getNbLignes();
|
||||||
this.nbColonnes = grille.getNbColonnes();
|
this.nbColonnes = grille.getNbColonnes();
|
||||||
setLayout(new BorderLayout());
|
setLayout(new BorderLayout());
|
||||||
grillePanel = new JPanel(new GridLayoutCarre(nbLignes, nbColonnes)); // pour que les cases soient carrés
|
initialiserVueGrille();
|
||||||
add(grillePanel, BorderLayout.CENTER);
|
|
||||||
casesGrille = new JPanel[nbLignes][nbColonnes];
|
|
||||||
for (int i = 0; i < nbLignes; i++) {
|
|
||||||
for (int j = 0; j < nbColonnes; j++) {
|
|
||||||
JPanel caseG = new JPanel() {
|
|
||||||
@Override
|
|
||||||
public Dimension getPreferredSize() {
|
|
||||||
return super.getPreferredSize();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
caseG.setBackground(Color.WHITE);
|
|
||||||
caseG.setBorder(BorderFactory.createLineBorder(Color.GRAY));
|
|
||||||
casesGrille[i][j] = caseG;
|
|
||||||
grillePanel.add(caseG);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
grille.addObserver(this);
|
grille.addObserver(this);
|
||||||
jeu.addObserver(this);
|
jeu.addObserver(this);
|
||||||
@@ -81,10 +65,20 @@ public class VueGrille extends JPanel implements Observer, Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initialiserVueGrille() {
|
private void initialiserVueGrille() {
|
||||||
for (int i = 0; i < grille.getNbLignes(); i++) {
|
grillePanel = new JPanel(new GridLayoutCarre(nbLignes, nbColonnes)); // pour que les cases soient carrés
|
||||||
for (int j = 0; j < grille.getNbColonnes(); j++) {
|
add(grillePanel, BorderLayout.CENTER);
|
||||||
JPanel caseG = new JPanel();
|
casesGrille = new JPanel[nbLignes][nbColonnes];
|
||||||
|
for (int i = 0; i < nbLignes; i++) {
|
||||||
|
for (int j = 0; j < nbColonnes; j++) {
|
||||||
|
JPanel caseG = new JPanel() {
|
||||||
|
@Override
|
||||||
|
public Dimension getPreferredSize() {
|
||||||
|
return super.getPreferredSize();
|
||||||
|
}
|
||||||
|
};
|
||||||
caseG.setBackground(Color.WHITE);
|
caseG.setBackground(Color.WHITE);
|
||||||
|
caseG.setBorder(BorderFactory.createLineBorder(Color.GRAY));
|
||||||
|
casesGrille[i][j] = caseG;
|
||||||
grillePanel.add(caseG);
|
grillePanel.add(caseG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user