Squashed commit of the following:
commit ab2fbeb8be52dc2886f39b72c158483793185b5c Author: Morph01 <thibaut6969delastreet@gmail.com> Date: Tue May 20 15:18:20 2025 +0200 feat: wav music file rather than mp3 commit e4ea00b4dfbe32a9a03d078a8b77c35bd934f2e6 Author: Morph01 <thibaut6969delastreet@gmail.com> Date: Tue May 20 14:34:34 2025 +0200 refactor: refactor imports commit 68ee1318f8f450f6c9358de8484c17978428949e Author: Morph01 <thibaut6969delastreet@gmail.com> Date: Tue May 20 13:56:35 2025 +0200 feat: add rotation support commit c106cc74e351f40afbf5f03395ea14627f10b29b Author: Morph01 <thibaut6969delastreet@gmail.com> Date: Tue May 20 11:44:48 2025 +0200 fix: upper bound of generated pieces commit 3caa2a69a49424e46078749eab53827df160af6c Author: Morph01 <thibaut6969delastreet@gmail.com> Date: Tue May 20 11:40:37 2025 +0200 Merge branch 'Gwendal' into Thibaut commit be1fd8ddd58df1a0ab02d005ba68da154ae199c7 Author: Morph01 <thibaut6969delastreet@gmail.com> Date: Mon May 19 23:01:43 2025 +0200 refactor: split in init vueGrille initialization of vueGrille rather than in constructor commit 5ec983979b363bf671945757234047ddcc9a333e Author: Morph01 <145839520+Morph01@users.noreply.github.com> Date: Mon May 19 22:47:02 2025 +0200 refactor: better achitecture and next piece preview fixed commit 524d96ef493c6053cfff4958697cea8583927aca Author: Morph01 <145839520+Morph01@users.noreply.github.com> Date: Mon May 19 22:16:42 2025 +0200 Squashed commit of the following: commita8f543114eAuthor: ROGER <gwendal.roger@etu.univ-lyon1.fr> Date: Mon May 19 21:59:38 2025 +0200 ajout d'une fonctionnalité permettant de mettre en pause le Jeu grace à un bouton. Ajout d'un vérouillage du clavier pendant lause commit27862eb3cdAuthor: ROGER <gwendal.roger@etu.univ-lyon1.fr> Date: Fri May 16 17:10:15 2025 +0200 Ajoute de l'arret de la musique en fin de partie + arret propre de l'ordonanceur commit2fec9fc96eAuthor: ROGER <gwendal.roger@etu.univ-lyon1.fr> Date: Fri May 16 16:17:58 2025 +0200 integration du responsive dans l'affichage de la grille commit 671d12f418bb6c5a0ae623e5195d78eebef4e641 Author: Morph01 <145839520+Morph01@users.noreply.github.com> Date: Mon May 19 22:02:16 2025 +0200 fix: piece generation
This commit is contained in:
Binary file not shown.
BIN
app/bin/main/TetrisMusic.wav
Normal file
BIN
app/bin/main/TetrisMusic.wav
Normal file
Binary file not shown.
@@ -23,9 +23,6 @@ dependencies {
|
|||||||
|
|
||||||
// This dependency is used by the application.
|
// This dependency is used by the application.
|
||||||
implementation(libs.guava)
|
implementation(libs.guava)
|
||||||
|
|
||||||
// JLayer pour lire les fichiers MP3
|
|
||||||
implementation("javazoom:jlayer:1.0.1")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply a specific Java toolchain to ease working on different environments.
|
// Apply a specific Java toolchain to ease working on different environments.
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
/*
|
|
||||||
* This source file was generated by the Gradle 'init' task
|
|
||||||
*/
|
|
||||||
package org;
|
package org;
|
||||||
|
|
||||||
import org.Controllers.IO;
|
import org.Controllers.IO;
|
||||||
@@ -31,15 +28,13 @@ 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, jeu);// Création d'un controleur de
|
new TetrisBandeauControleur(vueTetris.getVueBandeauControle(), musique, grille, jeu);// Création d'un
|
||||||
// bandeau avec la musique
|
// controleur de
|
||||||
|
// bandeau avec la
|
||||||
|
// musique
|
||||||
// instanciée
|
// instanciée
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: RESTE A IMPLEMENTER
|
// TODO: RESTE A IMPLEMENTER
|
||||||
// - rotation
|
|
||||||
// - score
|
|
||||||
// - lignes
|
|
||||||
// - menu pour fin de partie
|
|
||||||
// ext possible: conserver un historique de score dans un fichier txt ?
|
// ext possible: conserver un historique de score dans un fichier txt ?
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,7 @@ import java.awt.event.KeyListener;
|
|||||||
|
|
||||||
import org.Models.Direction;
|
import org.Models.Direction;
|
||||||
import org.Models.Jeu;
|
import org.Models.Jeu;
|
||||||
|
import org.Models.Orientation;
|
||||||
|
|
||||||
public class IO implements KeyListener {
|
public class IO implements KeyListener {
|
||||||
|
|
||||||
@@ -35,6 +36,15 @@ public class IO implements KeyListener {
|
|||||||
|
|
||||||
case KeyEvent.VK_SPACE:
|
case KeyEvent.VK_SPACE:
|
||||||
jeu.getGrille().deplacerPiece(Direction.TOUTENBAS);
|
jeu.getGrille().deplacerPiece(Direction.TOUTENBAS);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KeyEvent.VK_R:
|
||||||
|
jeu.getGrille().tournerPiece(Orientation.SENSHORAIRE);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KeyEvent.VK_E:
|
||||||
|
jeu.getGrille().tournerPiece(Orientation.SENSANTIHORAIRE);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ public class TetrisBandeauControleur {
|
|||||||
}
|
}
|
||||||
partieEnPause = !partieEnPause;
|
partieEnPause = !partieEnPause;
|
||||||
grille.setEnPause(partieEnPause);
|
grille.setEnPause(partieEnPause);
|
||||||
|
grille.setEnPause(partieEnPause);
|
||||||
musique.basculePlayPause();
|
musique.basculePlayPause();
|
||||||
vueControle.getPauseButton().setText(partieEnPause ? "PLAY" : "PAUSE");
|
vueControle.getPauseButton().setText(partieEnPause ? "PLAY" : "PAUSE");
|
||||||
System.out.println(partieEnPause ? "Partie en pause" : "Partie en cours");
|
System.out.println(partieEnPause ? "Partie en pause" : "Partie en cours");
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import java.awt.*;
|
|||||||
public class GridLayoutCarre implements LayoutManager {
|
public class GridLayoutCarre implements LayoutManager {
|
||||||
private int lignes;
|
private int lignes;
|
||||||
private int colonnes;
|
private int colonnes;
|
||||||
|
|
||||||
public GridLayoutCarre(int lignes, int colonnes) {
|
public GridLayoutCarre(int lignes, int colonnes) {
|
||||||
this.lignes = lignes;
|
this.lignes = lignes;
|
||||||
this.colonnes = colonnes;
|
this.colonnes = colonnes;
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package org.Models;
|
package org.Models;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uniquement afin de se servir d'une paire de coordonées.
|
||||||
|
*/
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Observable;
|
import java.util.Observable;
|
||||||
@@ -189,20 +193,8 @@ public class Grille extends Observable { // TODO: ?? implements Runnable {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Point caseColoree : motif) {
|
List<Point> nouvellePosition = calculerNouvellePosition(motif, deltaX, deltaY);
|
||||||
int newX = caseColoree.x + deltaX;
|
return positionValide(nouvellePosition);
|
||||||
int newY = caseColoree.y + deltaY;
|
|
||||||
|
|
||||||
if (newX < 0 || newX >= nbColonnes || newY < 0 || newY >= nbLignes) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (grille[newY][newX]) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean[][] getGrille() {
|
public boolean[][] getGrille() {
|
||||||
@@ -234,23 +226,6 @@ public class Grille extends Observable { // TODO: ?? implements Runnable {
|
|||||||
return enPause;
|
return enPause;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public void verifierEtSupprimerLignesSiBesoin() {
|
|
||||||
|
|
||||||
// for (int i = nbLignes - 1; i > 0; i--) {
|
|
||||||
// boolean ligneSupprimable = true;
|
|
||||||
|
|
||||||
// for (int j = 0; j < nbColonnes; j++) {
|
|
||||||
// if (!this.grille[i][j]) {
|
|
||||||
// ligneSupprimable = false;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (ligneSupprimable) {
|
|
||||||
// supprimerLigne(i);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
public void verifierEtSupprimerLignesSiBesoin() {
|
public void verifierEtSupprimerLignesSiBesoin() {
|
||||||
int tmpNbLignesSupprimees = 0;
|
int tmpNbLignesSupprimees = 0;
|
||||||
System.out.println("Debut uppression d'une ligne......");
|
System.out.println("Debut uppression d'une ligne......");
|
||||||
@@ -290,6 +265,22 @@ public class Grille extends Observable { // TODO: ?? implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getScore() {
|
||||||
|
return score;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setScore(int score) {
|
||||||
|
this.score = score;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNbLignesSupprimees() {
|
||||||
|
return nbLignesSupprimees;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNbLignesSupprimees(int nbLignesSupprimees) {
|
||||||
|
this.nbLignesSupprimees = nbLignesSupprimees;
|
||||||
|
}
|
||||||
|
|
||||||
// // TODO : EUHHHHHHHHHH JE CROIS PAS que ça marche comme ça c'est pas en mode
|
// // TODO : EUHHHHHHHHHH JE CROIS PAS que ça marche comme ça c'est pas en mode
|
||||||
// gravité récursive, c'est juste tout descend de n lignes cassées
|
// gravité récursive, c'est juste tout descend de n lignes cassées
|
||||||
// // dès qu'on a fixe la pièce courante on verifie le nombre de lignes a
|
// // dès qu'on a fixe la pièce courante on verifie le nombre de lignes a
|
||||||
@@ -347,18 +338,79 @@ public class Grille extends Observable { // TODO: ?? implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getScore(){
|
public void tournerPiece(Orientation orientation) {
|
||||||
return score;
|
if (peuxTournerPiece(orientation)) {
|
||||||
}
|
boolean[][] motif = pieceCourante.getMotif();
|
||||||
public void setScore(int score) {
|
boolean[][] nouveauMotif;
|
||||||
this.score = score;
|
|
||||||
|
if (orientation == Orientation.SENSHORAIRE) {
|
||||||
|
nouveauMotif = PieceCourante.rotationHoraire(motif);
|
||||||
|
} else {
|
||||||
|
nouveauMotif = PieceCourante.rotationAntiHoraire(motif);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getNbLignesSupprimees() {
|
pieceCourante.setMotif(nouveauMotif);
|
||||||
return nbLignesSupprimees;
|
|
||||||
|
setChanged();
|
||||||
|
notifyObservers();
|
||||||
}
|
}
|
||||||
public void setNbLignesSupprimees(int nbLignesSupprimees) {
|
}
|
||||||
this.nbLignesSupprimees = nbLignesSupprimees;
|
|
||||||
|
public boolean peuxTournerPiece(Orientation orientation) {
|
||||||
|
List<Point> positionApresRotation = calculerPositionApresRotation(orientation);
|
||||||
|
return positionValide(positionApresRotation);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Point> calculerPositionApresRotation(Orientation orientation) {
|
||||||
|
List<Point> nouvellePosition = new ArrayList<>();
|
||||||
|
boolean[][] motifActuel = pieceCourante.getMotif();
|
||||||
|
boolean[][] motifTourne;
|
||||||
|
|
||||||
|
boolean[][] motifCopie = new boolean[motifActuel.length][motifActuel[0].length];
|
||||||
|
for (int i = 0; i < motifActuel.length; i++) {
|
||||||
|
for (int j = 0; j < motifActuel[i].length; j++) {
|
||||||
|
motifCopie[i][j] = motifActuel[i][j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (orientation == Orientation.SENSHORAIRE) {
|
||||||
|
motifTourne = PieceCourante.rotationHoraire(motifCopie);
|
||||||
|
} else {
|
||||||
|
motifTourne = PieceCourante.rotationAntiHoraire(motifCopie);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < motifTourne.length; i++) {
|
||||||
|
for (int j = 0; j < motifTourne[i].length; j++) {
|
||||||
|
if (motifTourne[i][j]) {
|
||||||
|
nouvellePosition.add(new Point(pieceCouranteX + j, pieceCouranteY + i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nouvellePosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean positionValide(List<Point> points) {
|
||||||
|
for (Point point : points) {
|
||||||
|
if (point.x < 0 || point.x >= nbColonnes || point.y < 0 || point.y >= nbLignes) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (grille[point.y][point.x]) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Point> calculerNouvellePosition(List<Point> points, int deltaX, int deltaY) {
|
||||||
|
List<Point> nouvellePosPoints = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Point point : points) {
|
||||||
|
nouvellePosPoints.add(new Point(point.x + deltaX, point.y + deltaY));
|
||||||
|
}
|
||||||
|
|
||||||
|
return nouvellePosPoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reinitialiserGrille() {
|
public void reinitialiserGrille() {
|
||||||
@@ -371,4 +423,5 @@ public class Grille extends Observable { // TODO: ?? implements Runnable {
|
|||||||
setChanged();
|
setChanged();
|
||||||
notifyObservers();
|
notifyObservers();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,16 @@
|
|||||||
package org.Models;
|
package org.Models;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uniquement afin de se servir d'une paire de coordonées.
|
||||||
|
*/
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
|
|
||||||
import java.util.Observable;
|
import java.util.Observable;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import org.Models.Pieces.PieceI;
|
||||||
|
import org.Models.Pieces.PieceJ;
|
||||||
import org.Models.Pieces.PieceI;
|
import org.Models.Pieces.PieceI;
|
||||||
import org.Models.Pieces.PieceJ;
|
import org.Models.Pieces.PieceJ;
|
||||||
import org.Models.Pieces.PieceL;
|
import org.Models.Pieces.PieceL;
|
||||||
@@ -29,10 +36,13 @@ public class Jeu extends Observable implements Runnable {
|
|||||||
System.err.println("init jeu");
|
System.err.println("init jeu");
|
||||||
this.grille = grille;
|
this.grille = grille;
|
||||||
this.musique = musique;
|
this.musique = musique;
|
||||||
|
this.musique = musique;
|
||||||
|
|
||||||
|
System.err.println("init nouvelle piece courante");
|
||||||
System.err.println("init nouvelle piece courante");
|
System.err.println("init nouvelle piece courante");
|
||||||
this.grille.setPieceCourante(getNouvellePiece());
|
this.grille.setPieceCourante(getNouvellePiece());
|
||||||
System.err.println("init nouvelle piece suivante");
|
System.err.println("init nouvelle piece suivante");
|
||||||
|
System.err.println("init nouvelle piece suivante");
|
||||||
this.pieceSuivante = getNouvellePiece();
|
this.pieceSuivante = getNouvellePiece();
|
||||||
|
|
||||||
this.ordonnanceur = new Ordonnanceur(this, 1000);
|
this.ordonnanceur = new Ordonnanceur(this, 1000);
|
||||||
|
|||||||
@@ -1,53 +1,94 @@
|
|||||||
package org.Models;
|
package org.Models;
|
||||||
|
|
||||||
import javazoom.jl.player.Player;
|
import java.io.IOException;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
public class Musique extends Thread {
|
import javax.sound.sampled.AudioInputStream;
|
||||||
private Player player;
|
import javax.sound.sampled.AudioSystem;
|
||||||
private volatile boolean stop = false;
|
import javax.sound.sampled.Clip;
|
||||||
private volatile boolean enPause = false;
|
import javax.sound.sampled.LineEvent;
|
||||||
|
import javax.sound.sampled.LineUnavailableException;
|
||||||
|
import javax.sound.sampled.UnsupportedAudioFileException;
|
||||||
|
|
||||||
public void run() {
|
/**
|
||||||
|
* Classe Musique n'étant pas purement données métier, donc n'aurait normalement
|
||||||
|
* sa place dans le package Models. Il faudrait l'externaliser. Par manque de
|
||||||
|
* temps, suite à notre discussion, nous avons décidé de laisser la musique ici.
|
||||||
|
*/
|
||||||
|
public class Musique {
|
||||||
|
private Clip clip;
|
||||||
|
private long clipPositionPause = 0;
|
||||||
|
private boolean estEnPause = false;
|
||||||
|
private boolean estArrete = false;
|
||||||
|
private boolean estInitialise = false;
|
||||||
|
|
||||||
|
public Musique() {
|
||||||
|
initialiserClip();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initialiserClip() {
|
||||||
try {
|
try {
|
||||||
while (!stop) {
|
InputStream audioSrc = getClass().getResourceAsStream("/TetrisMusic.wav");
|
||||||
if (!enPause) {
|
if (audioSrc == null) {
|
||||||
try (InputStream musique = getClass().getResourceAsStream("/TetrisMusic.mp3")) {
|
System.err.println("Erreur : le fichier TetrisMusic.wav est introuvable.");
|
||||||
if (musique == null) {
|
|
||||||
System.err.println("Erreur : le fichier musique.mp3 est introuvable.");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BufferedInputStream buffer = new BufferedInputStream(musique);
|
|
||||||
this.player = new Player(buffer);
|
AudioInputStream audioStream = AudioSystem.getAudioInputStream(audioSrc);
|
||||||
|
clip = AudioSystem.getClip();
|
||||||
|
clip.open(audioStream);
|
||||||
|
estInitialise = true;
|
||||||
|
|
||||||
|
clip.addLineListener(event -> {
|
||||||
|
if (event.getType() == LineEvent.Type.STOP && !estEnPause && !estArrete) {
|
||||||
|
clip.setFramePosition(0);
|
||||||
|
clip.start();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
System.out.println("Clip audio initialisé avec succès.");
|
||||||
|
} catch (UnsupportedAudioFileException e) {
|
||||||
|
System.err.println("Format audio non supporté : " + e.getMessage());
|
||||||
|
} catch (LineUnavailableException e) {
|
||||||
|
System.err.println("Ligne audio indisponible : " + e.getMessage());
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err.println("Erreur d'E/S lors de la lecture audio : " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void start() {
|
||||||
|
if (estInitialise && !estArrete) {
|
||||||
|
clip.setFramePosition(0);
|
||||||
|
clip.start();
|
||||||
|
estEnPause = false;
|
||||||
System.out.println("Lecture de la musique...");
|
System.out.println("Lecture de la musique...");
|
||||||
player.play();
|
|
||||||
} catch (Exception e) {
|
|
||||||
System.err.println("Erreur lors de la lecture de la musique : " + e.getMessage());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Thread.sleep(1000); // Attendre 1 seconde avant de vérifier à nouveau
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
System.err.println("Musique interrompue : " + e.getMessage());
|
|
||||||
}
|
}
|
||||||
System.out.println("Fin du thread de musique.");
|
System.out.println("Fin du thread de musique.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void basculePlayPause() {
|
public void basculePlayPause() {
|
||||||
enPause = !enPause;
|
if (!estInitialise || estArrete)
|
||||||
if (enPause && player != null) {
|
return;
|
||||||
System.out.println("Musique en pause.");
|
|
||||||
player.close();
|
estEnPause = !estEnPause;
|
||||||
|
|
||||||
|
if (estEnPause) {
|
||||||
|
clipPositionPause = clip.getMicrosecondPosition();
|
||||||
|
clip.stop();
|
||||||
|
System.out.println("Musique en pause à la position " + clipPositionPause + " µs");
|
||||||
|
} else {
|
||||||
|
clip.setMicrosecondPosition(clipPositionPause);
|
||||||
|
clip.start();
|
||||||
|
System.out.println("Musique reprise à la position " + clipPositionPause + " µs");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void arreterMusique() {
|
public void arreterMusique() {
|
||||||
|
if (estInitialise) {
|
||||||
|
estArrete = true;
|
||||||
|
clip.stop();
|
||||||
|
clip.close();
|
||||||
System.out.println("Arrêt de la musique.");
|
System.out.println("Arrêt de la musique.");
|
||||||
stop = true;
|
|
||||||
if (player != null) {
|
|
||||||
player.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
6
app/src/main/java/org/Models/Orientation.java
Normal file
6
app/src/main/java/org/Models/Orientation.java
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
package org.Models;
|
||||||
|
|
||||||
|
public enum Orientation {
|
||||||
|
SENSHORAIRE,
|
||||||
|
SENSANTIHORAIRE,
|
||||||
|
}
|
||||||
@@ -2,4 +2,32 @@ package org.Models;
|
|||||||
|
|
||||||
public interface PieceCourante {
|
public interface PieceCourante {
|
||||||
abstract public boolean[][] getMotif();
|
abstract public boolean[][] getMotif();
|
||||||
|
|
||||||
|
abstract public void setMotif(boolean[][] motif);
|
||||||
|
|
||||||
|
static boolean[][] rotationHoraire(boolean[][] motif) {
|
||||||
|
int taille = motif.length;
|
||||||
|
boolean[][] resultat = new boolean[taille][taille];
|
||||||
|
|
||||||
|
for (int i = 0; i < taille; i++) {
|
||||||
|
for (int j = 0; j < taille; j++) {
|
||||||
|
resultat[j][taille - 1 - i] = motif[i][j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return resultat;
|
||||||
|
}
|
||||||
|
|
||||||
|
static boolean[][] rotationAntiHoraire(boolean[][] motif) {
|
||||||
|
int taille = motif.length;
|
||||||
|
boolean[][] resultat = new boolean[taille][taille];
|
||||||
|
|
||||||
|
for (int i = 0; i < taille; i++) {
|
||||||
|
for (int j = 0; j < taille; j++) {
|
||||||
|
resultat[taille - 1 - j][i] = motif[i][j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return resultat;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,4 +17,9 @@ private boolean[][] motif = new boolean[4][4];
|
|||||||
public boolean[][] getMotif() {
|
public boolean[][] getMotif() {
|
||||||
return motif;
|
return motif;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMotif(boolean[][] motif) {
|
||||||
|
this.motif = motif;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,13 +7,19 @@ public class PieceJ implements PieceCourante {
|
|||||||
private boolean[][] motif = new boolean[3][3];
|
private boolean[][] motif = new boolean[3][3];
|
||||||
|
|
||||||
public PieceJ() {
|
public PieceJ() {
|
||||||
motif[0][2] = true;
|
motif[0][1] = true;
|
||||||
motif[1][2] = true;
|
motif[1][1] = true;
|
||||||
motif[2][2] = true;
|
|
||||||
motif[2][1] = true;
|
motif[2][1] = true;
|
||||||
|
motif[2][0] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean[][] getMotif() {
|
public boolean[][] getMotif() {
|
||||||
return motif;
|
return motif;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMotif(boolean[][] motif) {
|
||||||
|
this.motif = motif;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,14 +7,19 @@ public class PieceL implements PieceCourante {
|
|||||||
private boolean[][] motif = new boolean[3][3];
|
private boolean[][] motif = new boolean[3][3];
|
||||||
|
|
||||||
public PieceL() {
|
public PieceL() {
|
||||||
motif[0][0] = true;
|
motif[0][1] = true;
|
||||||
motif[1][0] = true;
|
motif[1][1] = true;
|
||||||
motif[2][0] = true;
|
|
||||||
motif[2][1] = true;
|
motif[2][1] = true;
|
||||||
|
motif[2][2] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean[][] getMotif() {
|
public boolean[][] getMotif() {
|
||||||
return motif;
|
return motif;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMotif(boolean[][] motif) {
|
||||||
|
this.motif = motif;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import org.Models.PieceCourante;
|
|||||||
public class PieceO implements PieceCourante {
|
public class PieceO implements PieceCourante {
|
||||||
|
|
||||||
private boolean[][] motif = new boolean[4][4];
|
private boolean[][] motif = new boolean[4][4];
|
||||||
|
|
||||||
public PieceO() {
|
public PieceO() {
|
||||||
motif[1][1] = true;
|
motif[1][1] = true;
|
||||||
motif[1][2] = true;
|
motif[1][2] = true;
|
||||||
@@ -16,4 +17,9 @@ private boolean[][] motif = new boolean[4][4];
|
|||||||
public boolean[][] getMotif() {
|
public boolean[][] getMotif() {
|
||||||
return motif;
|
return motif;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMotif(boolean[][] motif) {
|
||||||
|
this.motif = motif;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,4 +17,9 @@ private boolean[][] motif = new boolean[3][3];
|
|||||||
public boolean[][] getMotif() {
|
public boolean[][] getMotif() {
|
||||||
return motif;
|
return motif;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMotif(boolean[][] motif) {
|
||||||
|
this.motif = motif;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,4 +17,9 @@ private boolean[][] motif = new boolean[3][3];
|
|||||||
public boolean[][] getMotif() {
|
public boolean[][] getMotif() {
|
||||||
return motif;
|
return motif;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMotif(boolean[][] motif) {
|
||||||
|
this.motif = motif;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,4 +17,9 @@ private boolean[][] motif = new boolean[3][3];
|
|||||||
public boolean[][] getMotif() {
|
public boolean[][] getMotif() {
|
||||||
return motif;
|
return motif;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMotif(boolean[][] motif) {
|
||||||
|
this.motif = motif;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
58
app/src/main/java/org/Views/GridLayoutCarre.java
Normal file
58
app/src/main/java/org/Views/GridLayoutCarre.java
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
package org.Views;
|
||||||
|
|
||||||
|
import java.awt.Component;
|
||||||
|
import java.awt.Container;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.LayoutManager;
|
||||||
|
|
||||||
|
public class GridLayoutCarre implements LayoutManager {
|
||||||
|
private int lignes;
|
||||||
|
private int colonnes;
|
||||||
|
|
||||||
|
public GridLayoutCarre(int lignes, int colonnes) {
|
||||||
|
this.lignes = lignes;
|
||||||
|
this.colonnes = colonnes;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addLayoutComponent(String name, Component comp) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeLayoutComponent(Component comp) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dimension preferredLayoutSize(Container parent) {
|
||||||
|
return parent.getPreferredSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dimension minimumLayoutSize(Container parent) {
|
||||||
|
return parent.getMinimumSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void layoutContainer(Container parent) {
|
||||||
|
int largeur = parent.getWidth();
|
||||||
|
int hauteur = parent.getHeight();
|
||||||
|
int tailleCase = Math.min(largeur / colonnes, hauteur / lignes);
|
||||||
|
int offSetX = (largeur - tailleCase * colonnes) / 2;
|
||||||
|
int offSetY = (hauteur - tailleCase * lignes) / 2;
|
||||||
|
int index = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < lignes; i++) {
|
||||||
|
for (int j = 0; j < colonnes; j++) {
|
||||||
|
if (index >= parent.getComponentCount()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Component comp = parent.getComponent(index++);
|
||||||
|
int x = offSetX + j * tailleCase;
|
||||||
|
int y = offSetY + i * tailleCase;
|
||||||
|
comp.setBounds(x, y, tailleCase, tailleCase);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,14 +1,24 @@
|
|||||||
package org.Views;
|
package org.Views;
|
||||||
|
|
||||||
import org.Models.GridLayoutCarre;
|
|
||||||
import org.Models.Jeu;
|
import org.Models.Jeu;
|
||||||
import org.Models.PieceCourante;
|
import org.Models.PieceCourante;
|
||||||
|
|
||||||
import javax.swing.*;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.*;
|
import java.awt.Color;
|
||||||
|
import java.awt.Component;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.Insets;
|
||||||
import java.util.Observable;
|
import java.util.Observable;
|
||||||
import java.util.Observer;
|
import java.util.Observer;
|
||||||
|
|
||||||
|
import javax.swing.BorderFactory;
|
||||||
|
import javax.swing.Box;
|
||||||
|
import javax.swing.BoxLayout;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public class VueBandeauControle extends JPanel implements Observer {
|
public class VueBandeauControle extends JPanel implements Observer {
|
||||||
private JLabel scoreLabel;
|
private JLabel scoreLabel;
|
||||||
|
|||||||
@@ -1,15 +1,19 @@
|
|||||||
package org.Views;
|
package org.Views;
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
|
|
||||||
import org.Models.*;
|
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.util.Observable;
|
import java.util.Observable;
|
||||||
import java.util.Observer;
|
import java.util.Observer;
|
||||||
|
|
||||||
|
import javax.swing.BorderFactory;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
|
import org.Models.Grille;
|
||||||
|
import org.Models.Jeu;
|
||||||
|
import org.Models.Ordonnanceur;
|
||||||
|
import org.Models.PieceCourante;
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public class VueGrille extends JPanel implements Observer, Runnable {
|
public class VueGrille extends JPanel implements Observer, Runnable {
|
||||||
private JPanel grillePanel;
|
private JPanel grillePanel;
|
||||||
@@ -29,6 +33,8 @@ public class VueGrille extends JPanel implements Observer, Runnable {
|
|||||||
this.jeu = jeu;
|
this.jeu = jeu;
|
||||||
this.nbLignes = grille.getNbLignes();
|
this.nbLignes = grille.getNbLignes();
|
||||||
this.nbColonnes = grille.getNbColonnes();
|
this.nbColonnes = grille.getNbColonnes();
|
||||||
|
this.nbLignes = grille.getNbLignes();
|
||||||
|
this.nbColonnes = grille.getNbColonnes();
|
||||||
setLayout(new BorderLayout());
|
setLayout(new BorderLayout());
|
||||||
initialiserVueGrille();
|
initialiserVueGrille();
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
package org.Views;
|
package org.Views;
|
||||||
|
|
||||||
import org.Models.*;
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Dimension;
|
||||||
import javax.swing.*;
|
import java.awt.Toolkit;
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.event.ComponentAdapter;
|
import java.awt.event.ComponentAdapter;
|
||||||
import java.awt.event.ComponentEvent;
|
import java.awt.event.ComponentEvent;
|
||||||
|
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
|
||||||
|
import org.Models.Grille;
|
||||||
|
import org.Models.Jeu;
|
||||||
|
|
||||||
public class VueTetris extends JFrame {
|
public class VueTetris extends JFrame {
|
||||||
private static Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
private static Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
||||||
public static double tailleJFrameX = screenSize.getHeight() / 2;
|
public static double tailleJFrameX = screenSize.getHeight() / 2;
|
||||||
@@ -17,6 +21,10 @@ public class VueTetris extends JFrame {
|
|||||||
public VueTetris(Grille grille, Jeu jeu) {
|
public VueTetris(Grille grille, Jeu jeu) {
|
||||||
super("Tetris");
|
super("Tetris");
|
||||||
|
|
||||||
|
this.vueGrille = new VueGrille(grille, jeu);
|
||||||
|
this.vueControle = new VueBandeauControle(jeu);
|
||||||
|
// TetrisBandeauControleur controleur = new
|
||||||
|
// TetrisBandeauControleur(vueControle);
|
||||||
this.vueGrille = new VueGrille(grille, jeu);
|
this.vueGrille = new VueGrille(grille, jeu);
|
||||||
this.vueControle = new VueBandeauControle(jeu);
|
this.vueControle = new VueBandeauControle(jeu);
|
||||||
// TetrisBandeauControleur controleur = new
|
// TetrisBandeauControleur controleur = new
|
||||||
@@ -39,8 +47,17 @@ public class VueTetris extends JFrame {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// listener permettanbt de redimensionner les cases de la grille
|
||||||
|
addComponentListener(new ComponentAdapter() {
|
||||||
|
@Override
|
||||||
|
public void componentResized(ComponentEvent e) {
|
||||||
|
vueGrille.resizeCases();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
vueGrille.resizeCases();
|
vueGrille.resizeCases();
|
||||||
|
vueGrille.resizeCases();
|
||||||
|
|
||||||
vueControle.afficherPieceSuivante(jeu.getPieceSuivante());
|
vueControle.afficherPieceSuivante(jeu.getPieceSuivante());
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
BIN
app/src/main/resources/TetrisMusic.wav
Normal file
BIN
app/src/main/resources/TetrisMusic.wav
Normal file
Binary file not shown.
Reference in New Issue
Block a user