feat: add of an MVC base architecture for Tetris

This commit is contained in:
Morph01
2025-05-15 16:17:50 +02:00
parent 275d761f24
commit eb7a013543
11 changed files with 553 additions and 40 deletions

View File

@@ -1,5 +1,92 @@
package org.Models;
public class Jeu {
import java.awt.Point;
import java.util.Observable;
import org.Models.Pieces.PieceCarre;
import org.Models.Pieces.PieceL;
@SuppressWarnings("deprecation")
public class Jeu extends Observable implements Runnable {
private Grille grille;
private Ordonnanceur ordonnanceur;
private PieceCourante pieceSuivante;
private int pieceSuivanteX;
private int pieceSuivanteY;
// TODO : remove test variable
public int test = 0;
public boolean jeuEnCours = true;
public Jeu(Grille grille) {
this.grille = grille;
this.grille.setPieceCourante(getNouvellePiece());
this.pieceSuivante = getNouvellePiece();
this.ordonnanceur = new Ordonnanceur(this, 1000);
this.ordonnanceur.start();
}
private PieceCourante getNouvellePiece() {
this.pieceSuivante = new PieceL();
this.pieceSuivanteX = 3;
this.pieceSuivanteY = 0;
return pieceSuivante;
}
public PieceCourante getPieceSuivante() {
return pieceSuivante;
}
public int getPieceSuivanteX() {
return pieceSuivanteX;
}
public int getPieceSuivanteY() {
return pieceSuivanteY;
}
public Grille getGrille() {
return grille;
}
public boolean estFinPartie() {
for (Point caseColoree : this.grille.motifPieceCouranteColoriee()) {
if (this.grille.getCase(caseColoree.y, caseColoree.x)) {
return true;
}
}
return false;
}
public void finPartie() {
this.jeuEnCours = false;
ordonnanceur.interrupt();
setChanged();
notifyObservers();
}
@Override
public void run() {
// TODO: game logic here
if (estFinPartie()) {
finPartie();
return;
}
if (!this.grille.doitFixerPiece()) {
this.grille.deplacerPiece(Direction.BAS);
} else {
this.grille.fixerPiece();
this.grille.setPieceCourante(getNouvellePiece());
}
setChanged();
notifyObservers();
}
}