refactor: better achitecture and next piece preview fixed
This commit is contained in:
@@ -4,9 +4,6 @@ import org.Models.Grille;
|
||||
import org.Models.Musique;
|
||||
import org.Views.VueBandeauControle;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class TetrisBandeauControleur {
|
||||
private boolean partieEnPause = false;
|
||||
private boolean partieTerminee = false;
|
||||
|
||||
@@ -21,7 +21,6 @@ public class Grille extends Observable { // TODO: ?? implements Runnable {
|
||||
this.nbColonnes = nbColonnes;
|
||||
this.grille = new boolean[nbLignes][nbColonnes];
|
||||
initGrille();
|
||||
this.grille[nbLignes - 1][nbColonnes - 1] = true;
|
||||
}
|
||||
|
||||
public void initGrille() {
|
||||
|
||||
@@ -4,7 +4,6 @@ public class Ordonnanceur extends Thread {
|
||||
|
||||
Runnable runnable;
|
||||
long pause;
|
||||
private boolean estActif = true;
|
||||
|
||||
public Ordonnanceur(Runnable runnable, long pause) {
|
||||
this.runnable = runnable;
|
||||
@@ -12,7 +11,6 @@ public class Ordonnanceur extends Thread {
|
||||
}
|
||||
|
||||
public void stopOrdonnanceur() {
|
||||
estActif = false;
|
||||
interrupt();
|
||||
}
|
||||
|
||||
|
||||
@@ -2,20 +2,26 @@ package org.Views;
|
||||
|
||||
import org.Models.GridLayoutCarre;
|
||||
import org.Models.GridLayoutCarre;
|
||||
import org.Models.Jeu;
|
||||
import org.Models.PieceCourante;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
|
||||
public class VueBandeauControle extends JPanel {
|
||||
@SuppressWarnings("deprecation")
|
||||
public class VueBandeauControle extends JPanel implements Observer {
|
||||
private JLabel scoreLabel;
|
||||
private JPanel nextPiecePanel;
|
||||
private JButton pauseButton;
|
||||
private JPanel[][] caseNextPiece = new JPanel[4][4];
|
||||
private JLabel nbLigneLabel;
|
||||
private JButton quitterButton;
|
||||
private Jeu jeu;
|
||||
|
||||
public VueBandeauControle() {
|
||||
public VueBandeauControle(Jeu jeu) {
|
||||
this.jeu = jeu;
|
||||
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
|
||||
setBackground(Color.gray);
|
||||
// setPreferredSize();
|
||||
@@ -65,6 +71,7 @@ public class VueBandeauControle extends JPanel {
|
||||
add(boutonsPanel);
|
||||
|
||||
// setVisible(true);
|
||||
jeu.addObserver(this);
|
||||
}
|
||||
|
||||
public void setScore(int score) {
|
||||
@@ -104,18 +111,31 @@ public class VueBandeauControle extends JPanel {
|
||||
}
|
||||
|
||||
public void afficherPieceSuivante(PieceCourante piece) {
|
||||
boolean[][] motif = piece.getMotif();
|
||||
for (int i = 0; i < 4; i++) {
|
||||
for (int j = 0; j < 4; j++) {
|
||||
if (motif[i][j]) {
|
||||
caseNextPiece[i][j].setBackground(Color.RED);
|
||||
} else {
|
||||
caseNextPiece[i][j].setBackground(Color.WHITE);
|
||||
}
|
||||
}
|
||||
|
||||
boolean[][] motif = piece.getMotif();
|
||||
for (int i = 0; i < motif.length; i++) {
|
||||
for (int j = 0; j < motif[i].length; j++) {
|
||||
if (motif[i][j]) {
|
||||
caseNextPiece[i][j].setBackground(Color.RED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nextPiecePanel.revalidate();
|
||||
nextPiecePanel.repaint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Observable o, Object arg) {
|
||||
if (o instanceof Jeu) {
|
||||
afficherPieceSuivante(jeu.getPieceSuivante());
|
||||
|
||||
// TODO : setScore ??
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,8 +8,6 @@ import org.Models.*;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.Toolkit;
|
||||
import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.Views;
|
||||
|
||||
import org.Controllers.TetrisBandeauControleur;
|
||||
import org.Models.*;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -23,7 +22,7 @@ public class VueTetris extends JFrame {
|
||||
super("Tetris");
|
||||
|
||||
this.vueGrille = new VueGrille(grille, jeu);
|
||||
this.vueControle = new VueBandeauControle();
|
||||
this.vueControle = new VueBandeauControle(jeu);
|
||||
// TetrisBandeauControleur controleur = new
|
||||
// TetrisBandeauControleur(vueControle);
|
||||
|
||||
@@ -47,7 +46,6 @@ public class VueTetris extends JFrame {
|
||||
setVisible(true);
|
||||
vueGrille.resizeCases();
|
||||
|
||||
// Utilisation de la pièce L
|
||||
vueControle.afficherPieceSuivante(jeu.getPieceSuivante());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user