ajout de la couleur automatique

This commit is contained in:
ROGER
2025-05-13 13:00:18 +02:00
parent 5a175ea4b4
commit 63d5db5d6a
4 changed files with 31 additions and 1 deletions

2
.idea/gradle.xml generated
View File

@@ -1,9 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings"> <component name="GradleSettings">
<option name="linkedExternalProjectsSettings"> <option name="linkedExternalProjectsSettings">
<GradleProjectSettings> <GradleProjectSettings>
<option name="externalProjectPath" value="$PROJECT_DIR$" /> <option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="#JAVA_HOME" />
<option name="modules"> <option name="modules">
<set> <set>
<option value="$PROJECT_DIR$" /> <option value="$PROJECT_DIR$" />

2
.idea/misc.xml generated
View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" /> <component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" project-jdk-name="23" project-jdk-type="JavaSDK" /> <component name="ProjectRootManager" version="2" languageLevel="JDK_21" project-jdk-name="ms-21" project-jdk-type="JavaSDK" />
</project> </project>

View File

@@ -9,6 +9,15 @@ public class Grille {
this.nbLignes = nbLignes; this.nbLignes = nbLignes;
this.nbColonnes = nbColonnes; this.nbColonnes = nbColonnes;
this.grille = new boolean[nbLignes][nbColonnes]; this.grille = new boolean[nbLignes][nbColonnes];
initGrille();
}
public void initGrille() {
for (int i = 0; i < nbLignes; i++) {
for (int j = 0; j < nbColonnes; j++) {
this.grille[i][j] = false;
}
}
} }
public int getNbLignes() { public int getNbLignes() {
@@ -18,4 +27,8 @@ public class Grille {
public int getNbColonnes() { public int getNbColonnes() {
return nbColonnes; return nbColonnes;
} }
public boolean[][] getGrille() {
return grille;
}
} }

View File

@@ -37,5 +37,20 @@ public class VueGrille extends JFrame {
setDefaultCloseOperation(EXIT_ON_CLOSE); setDefaultCloseOperation(EXIT_ON_CLOSE);
setTitle("TETRIS"); setTitle("TETRIS");
}
//fonction qui parcour la grille et colore les cases en fonction de la veleur booléenne
public void setCouleurGrille() {
for (int i = 0; i < grille.getNbLignes(); i++) {
for (int j = 0; j < grille.getNbColonnes(); j++) {
JPanel caseG = (JPanel) grillePanel.getComponent(i * grille.getNbColonnes() + j);
if (grille.getGrille()[i][j]) {
caseG.setBackground(Color.RED);
} else {
caseG.setBackground(Color.WHITE);
}
}
}
} }
} }