fix: piece generation

This commit is contained in:
Morph01
2025-05-19 22:02:16 +02:00
committed by Morph01
parent a8f543114e
commit 85aafa8240
14 changed files with 205 additions and 41 deletions

View File

@@ -0,0 +1,13 @@
arguments=--init-script /home/morph/.config/Code/User/globalStorage/redhat.java/1.42.0/config_linux/org.eclipse.osgi/58/0/.cp/gradle/init/init.gradle --init-script /home/morph/.config/Code/User/globalStorage/redhat.java/1.42.0/config_linux/org.eclipse.osgi/58/0/.cp/gradle/protobuf/init.gradle
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=/home/morph/.sdkman/candidates/java/23-tem
jvm.arguments=
offline.mode=false
override.workspace.settings=true
show.console.view=true
show.executions.view=true

View File

@@ -0,0 +1,13 @@
arguments=--init-script /home/morph/.cache/jdtls/config/org.eclipse.osgi/248/0/.cp/gradle/init/init.gradle
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(LOCAL_INSTALLATION(/home/morph/.sdkman/candidates/gradle/current))
connection.project.dir=..
eclipse.preferences.version=1
gradle.user.home=
java.home=/usr/lib/jvm/java-21-openjdk
jvm.arguments=
offline.mode=false
override.workspace.settings=true
show.console.view=true
show.executions.view=true

View File

@@ -0,0 +1,4 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21
org.eclipse.jdt.core.compiler.compliance=21
org.eclipse.jdt.core.compiler.source=21

View File

@@ -21,6 +21,7 @@ public class Grille extends Observable { // TODO: ?? implements Runnable {
this.nbColonnes = nbColonnes; this.nbColonnes = nbColonnes;
this.grille = new boolean[nbLignes][nbColonnes]; this.grille = new boolean[nbLignes][nbColonnes];
initGrille(); initGrille();
this.grille[nbLignes - 1][nbColonnes - 1] = true;
} }
public void initGrille() { public void initGrille() {
@@ -70,22 +71,22 @@ public class Grille extends Observable { // TODO: ?? implements Runnable {
switch (direction) { switch (direction) {
case BAS: case BAS:
if (peuxBouger(direction)) { if (peuxBouger(direction, this.motifPieceCouranteColoriee())) {
deplacerPieceBas(); deplacerPieceBas();
} }
break; break;
case GAUCHE: case GAUCHE:
if (peuxBouger(direction)) { if (peuxBouger(direction, this.motifPieceCouranteColoriee())) {
deplacerPieceGauche(); deplacerPieceGauche();
} }
break; break;
case DROITE: case DROITE:
if (peuxBouger(direction)) { if (peuxBouger(direction, this.motifPieceCouranteColoriee())) {
deplacerPieceDroite(); deplacerPieceDroite();
} }
break; break;
case TOUTENBAS: case TOUTENBAS:
if (peuxBouger(direction)) { if (peuxBouger(direction, this.motifPieceCouranteColoriee())) {
deplacerPieceToutEnBas(); deplacerPieceToutEnBas();
} }
default: default:
@@ -115,7 +116,7 @@ public class Grille extends Observable { // TODO: ?? implements Runnable {
} }
private void deplacerPieceToutEnBas() { private void deplacerPieceToutEnBas() {
while (peuxBouger(Direction.BAS)) { while (peuxBouger(Direction.BAS, this.motifPieceCouranteColoriee())) {
deplacerPieceBas(); deplacerPieceBas();
} }
} }
@@ -166,7 +167,7 @@ public class Grille extends Observable { // TODO: ?? implements Runnable {
return casesColores; return casesColores;
} }
public boolean peuxBouger(Direction direction) { public boolean peuxBouger(Direction direction, List<Point> motif) {
int deltaX = 0; int deltaX = 0;
int deltaY = 0; int deltaY = 0;
@@ -186,8 +187,7 @@ public class Grille extends Observable { // TODO: ?? implements Runnable {
break; break;
} }
List<Point> motifPieceColoree = motifPieceCouranteColoriee(); for (Point caseColoree : motif) {
for (Point caseColoree : motifPieceColoree) {
int newX = caseColoree.x + deltaX; int newX = caseColoree.x + deltaX;
int newY = caseColoree.y + deltaY; int newY = caseColoree.y + deltaY;
@@ -211,10 +211,13 @@ public class Grille extends Observable { // TODO: ?? implements Runnable {
for (Point caseColoree : motifPieceCouranteColoriee()) { for (Point caseColoree : motifPieceCouranteColoriee()) {
setCase(caseColoree.y, caseColoree.x, true); setCase(caseColoree.y, caseColoree.x, true);
} }
System.err.println("post fixage de piece");
verifierEtSupprimerLignesSiBesoin();
} }
public boolean doitFixerPiece() { public boolean doitFixerPiece() {
if (!peuxBouger(Direction.BAS)) { if (!peuxBouger(Direction.BAS, this.motifPieceCouranteColoriee())) {
return true; return true;
} }
@@ -230,4 +233,96 @@ public class Grille extends Observable { // TODO: ?? implements Runnable {
} }
// 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() {
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;
break;
}
}
if (ligneSupprimable) {
supprimerLigne(i);
i++;
}
}
}
// // 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
// // dès qu'on a fixe la pièce courante on verifie le nombre de lignes a
// supprimes
// // dans la grille
// // ->
// // faire tomber JUSQU'EN bas la ligne X au dessus des n lines supprimes
// // PAR CONTRE faire tomber de n lignes toutes les lignes au dessus de X.
// while (peuxBouger(Direction.BAS, getLignePoints(i))) {
// System.err.println("testtttttttttt descnete");
// descendreLigne(i - 1);
// }
// // for (int j = i - 2; j > 0; j--) {
// // descendreLigne(j);
// // }
// }
public void supprimerLigne(int i) {
for (int ligne = i; ligne > 0; ligne--) {
for (int j = 0; j < nbColonnes; j++) {
this.setCase(ligne, j, this.getCase(ligne - 1, j));
}
}
for (int j = 0; j < nbColonnes; j++) {
this.setCase(0, j, false);
}
setChanged();
notifyObservers();
}
public List<Point> getLignePoints(int i) {
List<Point> coordonnesCase = new ArrayList<>();
for (int j = 0; j < nbColonnes; j++) {
coordonnesCase.add(new Point(j, i));
}
return coordonnesCase;
}
public void descendreLigne(int i) {
for (int j = 0; j < nbColonnes; j++) {
List<Point> coordonnesCase = new ArrayList<>();
coordonnesCase.add(new Point(j, i));
if (this.grille[i][j]) {
this.setCase(i + 1, j, true);
}
this.setCase(i, j, false);
}
}
} }

View File

@@ -2,8 +2,15 @@ package org.Models;
import java.awt.Point; import java.awt.Point;
import java.util.Observable; import java.util.Observable;
import java.util.Random;
import org.Models.Pieces.PieceI;
import org.Models.Pieces.PieceJ;
import org.Models.Pieces.PieceL; import org.Models.Pieces.PieceL;
import org.Models.Pieces.PieceO;
import org.Models.Pieces.PieceS;
import org.Models.Pieces.PieceT;
import org.Models.Pieces.PieceZ;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class Jeu extends Observable implements Runnable { public class Jeu extends Observable implements Runnable {
@@ -15,16 +22,16 @@ public class Jeu extends Observable implements Runnable {
private int pieceSuivanteX; private int pieceSuivanteX;
private int pieceSuivanteY; private int pieceSuivanteY;
// TODO : remove test variable
public int test = 0;
public boolean jeuEnCours = true; public boolean jeuEnCours = true;
public Jeu(Grille grille, Musique musique) { public Jeu(Grille grille, Musique musique) {
System.err.println("init jeu");
this.grille = grille; this.grille = grille;
this.musique = musique; this.musique = musique;
System.err.println("init nouvelle piece courante");
this.grille.setPieceCourante(getNouvellePiece()); this.grille.setPieceCourante(getNouvellePiece());
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);
@@ -32,10 +39,46 @@ public class Jeu extends Observable implements Runnable {
} }
private PieceCourante getNouvellePiece() { private PieceCourante getNouvellePiece() {
this.pieceSuivante = new PieceL(); Random random = new Random();
this.pieceSuivanteX = 3; int randomiiii = random.nextInt(6);
this.pieceSuivanteY = 0; System.err.println("randomiiiii : " + randomiiii);
return pieceSuivante;
PieceCourante nouvellePiece;
switch (randomiiii) {
case 0:
nouvellePiece = new PieceI();
System.err.println("piece I");
break;
case 1:
nouvellePiece = new PieceL();
System.err.println("piece L");
break;
case 2:
nouvellePiece = new PieceJ();
System.err.println("piece J");
break;
case 3:
nouvellePiece = new PieceO();
System.err.println("piece O");
break;
case 4:
nouvellePiece = new PieceS();
System.err.println("piece S");
break;
case 5:
nouvellePiece = new PieceT();
System.err.println("piece T");
break;
case 6:
nouvellePiece = new PieceZ();
System.err.println("piece Z");
break;
default:
nouvellePiece = new PieceL();
break;
}
return nouvellePiece;
} }
public PieceCourante getPieceSuivante() { public PieceCourante getPieceSuivante() {
@@ -91,7 +134,8 @@ public class Jeu extends Observable implements Runnable {
this.grille.deplacerPiece(Direction.BAS); this.grille.deplacerPiece(Direction.BAS);
} else { } else {
this.grille.fixerPiece(); this.grille.fixerPiece();
this.grille.setPieceCourante(getNouvellePiece()); this.grille.setPieceCourante(pieceSuivante);
this.pieceSuivante = getNouvellePiece();
} }
setChanged(); setChanged();

View File

@@ -1,6 +1,5 @@
package org.Models; package org.Models;
public interface PieceCourante { public interface PieceCourante {
boolean[][] motif = new boolean[4][4];
abstract public boolean[][] getMotif(); abstract public boolean[][] getMotif();
} }

View File

@@ -1,18 +0,0 @@
package org.Models.Pieces;
import org.Models.PieceCourante;
public class PieceCarre implements PieceCourante {
public PieceCarre() {
motif[1][1] = true;
motif[1][2] = true;
motif[2][1] = true;
motif[2][2] = true;
}
@Override
public boolean[][] getMotif() {
return motif;
}
}

View File

@@ -4,6 +4,8 @@ import org.Models.PieceCourante;
public class PieceI implements PieceCourante { public class PieceI implements PieceCourante {
private boolean[][] motif = new boolean[4][4];
public PieceI() { public PieceI() {
motif[0][1] = true; motif[0][1] = true;
motif[1][1] = true; motif[1][1] = true;

View File

@@ -4,6 +4,8 @@ import org.Models.PieceCourante;
public class PieceJ implements PieceCourante { public class PieceJ implements PieceCourante {
private boolean[][] motif = new boolean[3][3];
public PieceJ() { public PieceJ() {
motif[0][2] = true; motif[0][2] = true;
motif[1][2] = true; motif[1][2] = true;

View File

@@ -4,12 +4,14 @@ import org.Models.PieceCourante;
public class PieceL implements PieceCourante { public class PieceL implements PieceCourante {
private boolean[][] motif = new boolean[3][3];
public PieceL(){ public PieceL(){
motif[0][0] = true;
motif[1][0] = true; motif[1][0] = true;
motif[2][0] = true; motif[2][0] = true;
motif[3][0] = true; motif[2][1] = true;
motif[3][1] = true; motif[2][2] = true;
motif[3][2] = true;
} }
@Override @Override

View File

@@ -3,11 +3,13 @@ package org.Models.Pieces;
import org.Models.PieceCourante; import org.Models.PieceCourante;
public class PieceO implements PieceCourante { public class PieceO implements PieceCourante {
private boolean[][] motif = new boolean[4][4];
public PieceO() { public PieceO() {
motif[0][1] = true;
motif[0][2] = true;
motif[1][1] = true; motif[1][1] = true;
motif[1][2] = true; motif[1][2] = true;
motif[2][1] = true;
motif[2][2] = true;
} }
@Override @Override

View File

@@ -4,6 +4,8 @@ import org.Models.PieceCourante;
public class PieceS implements PieceCourante { public class PieceS implements PieceCourante {
private boolean[][] motif = new boolean[3][3];
public PieceS() { public PieceS() {
motif[0][1] = true; motif[0][1] = true;
motif[1][1] = true; motif[1][1] = true;

View File

@@ -4,6 +4,8 @@ import org.Models.PieceCourante;
public class PieceT implements PieceCourante { public class PieceT implements PieceCourante {
private boolean[][] motif = new boolean[3][3];
public PieceT() { public PieceT() {
motif[0][1] = true; motif[0][1] = true;
motif[1][1] = true; motif[1][1] = true;

View File

@@ -4,6 +4,8 @@ import org.Models.PieceCourante;
public class PieceZ implements PieceCourante { public class PieceZ implements PieceCourante {
private boolean[][] motif = new boolean[3][3];
public PieceZ() { public PieceZ() {
motif[0][2] = true; motif[0][2] = true;
motif[1][2] = true; motif[1][2] = true;