integration du responsive dans l'affichage de la grille
This commit is contained in:
2
.idea/gradle.xml
generated
2
.idea/gradle.xml
generated
@@ -5,7 +5,7 @@
|
|||||||
<option name="linkedExternalProjectsSettings">
|
<option name="linkedExternalProjectsSettings">
|
||||||
<GradleProjectSettings>
|
<GradleProjectSettings>
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
<option name="gradleJvm" value="21" />
|
<option name="gradleJvm" value="#JAVA_HOME" />
|
||||||
<option name="modules">
|
<option name="modules">
|
||||||
<set>
|
<set>
|
||||||
<option value="$PROJECT_DIR$" />
|
<option value="$PROJECT_DIR$" />
|
||||||
|
|||||||
54
app/src/main/java/org/Models/GridLayoutCarre.java
Normal file
54
app/src/main/java/org/Models/GridLayoutCarre.java
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
package org.Models;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
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,5 +1,6 @@
|
|||||||
package org.Views;
|
package org.Views;
|
||||||
|
|
||||||
|
import org.Models.GridLayoutCarre;
|
||||||
import org.Models.PieceCourante;
|
import org.Models.PieceCourante;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
@@ -85,7 +86,11 @@ public class VueBandeauControle extends JPanel {
|
|||||||
|
|
||||||
private void initierNextPiecePanel() {
|
private void initierNextPiecePanel() {
|
||||||
nextPiecePanel.removeAll();
|
nextPiecePanel.removeAll();
|
||||||
nextPiecePanel.setLayout(new GridLayout(4, 4));
|
nextPiecePanel.setLayout(new GridLayoutCarre(4, 4));
|
||||||
|
Dimension tailleCarre = new Dimension(120, 120);
|
||||||
|
nextPiecePanel.setPreferredSize(tailleCarre);
|
||||||
|
nextPiecePanel.setMaximumSize(tailleCarre);
|
||||||
|
nextPiecePanel.setMinimumSize(tailleCarre);
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
for (int j = 0; j < 4; j++) {
|
for (int j = 0; j < 4; j++) {
|
||||||
JPanel caseG = new JPanel();
|
JPanel caseG = new JPanel();
|
||||||
@@ -113,4 +118,6 @@ public class VueBandeauControle extends JPanel {
|
|||||||
nextPiecePanel.revalidate();
|
nextPiecePanel.revalidate();
|
||||||
nextPiecePanel.repaint();
|
nextPiecePanel.repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,8 @@
|
|||||||
package org.Views;
|
package org.Views;
|
||||||
|
|
||||||
import javax.swing.JPanel;
|
import javax.swing.*;
|
||||||
|
|
||||||
import org.Models.Grille;
|
import org.Models.*;
|
||||||
import org.Models.Jeu;
|
|
||||||
import org.Models.Ordonnanceur;
|
|
||||||
import org.Models.PieceCourante;
|
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
@@ -25,19 +22,41 @@ public class VueGrille extends JPanel implements Observer, Runnable {
|
|||||||
|
|
||||||
private boolean afficherFenetreFinPartie = false;
|
private boolean afficherFenetreFinPartie = false;
|
||||||
|
|
||||||
private Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
private int nbLignes;
|
||||||
private double tailleJFrameX = screenSize.getHeight() / 2;
|
private int nbColonnes;
|
||||||
private double tailleJFrameY = screenSize.getHeight();
|
private JPanel[][] casesGrille;
|
||||||
|
|
||||||
|
//private Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
||||||
|
//private double tailleJFrameX = screenSize.getHeight() / 2;
|
||||||
|
//private double tailleJFrameY = screenSize.getHeight();
|
||||||
|
|
||||||
public VueGrille(Grille grille, Jeu jeu) {
|
public VueGrille(Grille grille, Jeu jeu) {
|
||||||
this.grille = grille;
|
this.grille = grille;
|
||||||
this.jeu = jeu;
|
this.jeu = jeu;
|
||||||
|
this.nbLignes = grille.getNbLignes();
|
||||||
|
this.nbColonnes = grille.getNbColonnes();
|
||||||
setLayout(new BorderLayout());
|
setLayout(new BorderLayout());
|
||||||
grillePanel = new JPanel(new GridLayout(grille.getNbLignes(), grille.getNbColonnes()));
|
grillePanel = new JPanel(new GridLayoutCarre(nbLignes,nbColonnes));
|
||||||
setSize((int) tailleJFrameX, (int) tailleJFrameY);
|
add(grillePanel, BorderLayout.CENTER);
|
||||||
System.err.println("taille " + tailleJFrameX + " " + tailleJFrameY);
|
//setSize((int) tailleJFrameX, (int) tailleJFrameY);
|
||||||
add(this.grillePanel, BorderLayout.CENTER);
|
//System.err.println("taille " + tailleJFrameX + " " + tailleJFrameY);
|
||||||
initialiserVueGrille();
|
//add(this.grillePanel, BorderLayout.CENTER);
|
||||||
|
//initialiserVueGrille();
|
||||||
|
casesGrille = new JPanel[nbLignes][nbColonnes];
|
||||||
|
for (int i = 0; i < nbLignes; i++) {
|
||||||
|
for (int j = 0; j < nbColonnes; j++) {
|
||||||
|
JPanel caseG = new JPanel(){
|
||||||
|
@Override
|
||||||
|
public Dimension getPreferredSize(){
|
||||||
|
return super.getPreferredSize();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
caseG.setBackground(Color.WHITE);
|
||||||
|
caseG.setBorder(BorderFactory.createLineBorder(Color.GRAY));
|
||||||
|
casesGrille[i][j] = caseG;
|
||||||
|
grillePanel.add(caseG);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
grille.addObserver(this);
|
grille.addObserver(this);
|
||||||
jeu.addObserver(this);
|
jeu.addObserver(this);
|
||||||
@@ -46,6 +65,30 @@ public class VueGrille extends JPanel implements Observer, Runnable {
|
|||||||
ordonnanceur.start();
|
ordonnanceur.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void resizeCases() {
|
||||||
|
int largeurPanel = grillePanel.getWidth();
|
||||||
|
int hauteurPanel = grillePanel.getHeight();
|
||||||
|
if (largeurPanel==0||hauteurPanel==0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int taille = Math.min(largeurPanel, hauteurPanel);
|
||||||
|
grillePanel.setPreferredSize(new Dimension(taille, taille));
|
||||||
|
grillePanel.setMaximumSize(new Dimension(taille, taille));
|
||||||
|
grillePanel.setMinimumSize(new Dimension(taille, taille));
|
||||||
|
grillePanel.setSize(new Dimension(taille, taille));
|
||||||
|
int tailleCaseX = largeurPanel / nbColonnes;
|
||||||
|
int tailleCaseY = hauteurPanel / nbLignes;
|
||||||
|
int tailleCase = Math.min(tailleCaseX, tailleCaseY);
|
||||||
|
Dimension taillePreferee=new Dimension(tailleCase, tailleCase);
|
||||||
|
for (int i = 0; i < nbLignes; i++) {
|
||||||
|
for (int j = 0; j < nbColonnes; j++) {
|
||||||
|
casesGrille[i][j].setPreferredSize(taillePreferee);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
grillePanel.revalidate();
|
||||||
|
grillePanel.repaint();
|
||||||
|
}
|
||||||
|
|
||||||
private void initialiserVueGrille() {
|
private void initialiserVueGrille() {
|
||||||
for (int i = 0; i < grille.getNbLignes(); i++) {
|
for (int i = 0; i < grille.getNbLignes(); i++) {
|
||||||
for (int j = 0; j < grille.getNbColonnes(); j++) {
|
for (int j = 0; j < grille.getNbColonnes(); j++) {
|
||||||
@@ -57,9 +100,9 @@ public class VueGrille extends JPanel implements Observer, Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void updateGrille() {
|
public synchronized void updateGrille() {
|
||||||
for (int i = 0; i < grille.getNbLignes(); i++) {
|
for (int i = 0; i < nbLignes; i++) {
|
||||||
for (int j = 0; j < grille.getNbColonnes(); j++) {
|
for (int j = 0; j < nbColonnes; j++) {
|
||||||
JPanel caseG = (JPanel) grillePanel.getComponent(i * grille.getNbColonnes() + j);
|
JPanel caseG = casesGrille[i][j];
|
||||||
if (grille.getGrille()[i][j]) {
|
if (grille.getGrille()[i][j]) {
|
||||||
caseG.setBackground(Color.BLUE);
|
caseG.setBackground(Color.BLUE);
|
||||||
} else {
|
} else {
|
||||||
@@ -70,9 +113,9 @@ public class VueGrille extends JPanel implements Observer, Runnable {
|
|||||||
|
|
||||||
// dessiner la pièce courante
|
// dessiner la pièce courante
|
||||||
if (jeu != null) {
|
if (jeu != null) {
|
||||||
PieceCourante piece = this.grille.getPieceCourante();
|
PieceCourante piece = grille.getPieceCourante();
|
||||||
int posX = this.grille.getPieceCouranteX();
|
int posX = grille.getPieceCouranteX();
|
||||||
int posY = this.grille.getPieceCouranteY();
|
int posY = grille.getPieceCouranteY();
|
||||||
|
|
||||||
boolean[][] motif = piece.getMotif();
|
boolean[][] motif = piece.getMotif();
|
||||||
for (int i = 0; i < motif.length; i++) {
|
for (int i = 0; i < motif.length; i++) {
|
||||||
@@ -83,17 +126,15 @@ public class VueGrille extends JPanel implements Observer, Runnable {
|
|||||||
int grilleX = posX + j;
|
int grilleX = posX + j;
|
||||||
int grilleY = posY + i;
|
int grilleY = posY + i;
|
||||||
|
|
||||||
if (grilleY >= 0 && grilleY < grille.getNbLignes() &&
|
if (grilleY >= 0 && grilleY < nbLignes &&
|
||||||
grilleX >= 0 && grilleX < grille.getNbColonnes()) {
|
grilleX >= 0 && grilleX < nbColonnes) {
|
||||||
JPanel caseG = (JPanel) grillePanel
|
JPanel caseG = casesGrille[grilleY][grilleX];
|
||||||
.getComponent(grilleY * grille.getNbColonnes() + grilleX);
|
|
||||||
caseG.setBackground(Color.RED);
|
caseG.setBackground(Color.RED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,11 +5,14 @@ import org.Models.*;
|
|||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.awt.event.ComponentAdapter;
|
||||||
|
import java.awt.event.ComponentEvent;
|
||||||
|
|
||||||
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;
|
||||||
public static double tailleJFrameY = screenSize.getHeight() / 2;
|
public static double tailleJFrameY = screenSize.getHeight() / 2;
|
||||||
|
private VueGrille vueGrille;
|
||||||
|
|
||||||
public VueTetris(Grille grille, Jeu jeu) {
|
public VueTetris(Grille grille, Jeu jeu) {
|
||||||
super("Tetris");
|
super("Tetris");
|
||||||
@@ -26,7 +29,17 @@ public class VueTetris extends JFrame {
|
|||||||
|
|
||||||
setSize((int) tailleJFrameX, (int) tailleJFrameY);
|
setSize((int) tailleJFrameX, (int) tailleJFrameY);
|
||||||
setLocationRelativeTo(null);
|
setLocationRelativeTo(null);
|
||||||
|
|
||||||
|
//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();
|
||||||
|
|
||||||
// Utilisation de la pièce L
|
// Utilisation de la pièce L
|
||||||
vueControle.afficherPieceSuivante(jeu.getPieceSuivante());
|
vueControle.afficherPieceSuivante(jeu.getPieceSuivante());
|
||||||
|
|||||||
79
q
Normal file
79
q
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
[33mcommit 9896013173cddd2fb569433bc3681b6190f954d2[m[33m ([m[1;36mHEAD[m[33m -> [m[1;32mGwendal[m[33m, [m[1;31morigin/main[m[33m, [m[1;31morigin/Thibaut[m[33m, [m[1;31morigin/HEAD[m[33m, [m[1;31morigin/Gwendal[m[33m)[m
|
||||||
|
Merge: eb7a013 9198a69
|
||||||
|
Author: Morph01 <145839520+Morph01@users.noreply.github.com>
|
||||||
|
Date: Thu May 15 18:00:09 2025 +0200
|
||||||
|
|
||||||
|
Merge remote-tracking branch 'origin/Gwendal' into Thibaut
|
||||||
|
|
||||||
|
[33mcommit eb7a01354351d62f095b188489b84a816b2d882d[m
|
||||||
|
Author: Morph01 <145839520+Morph01@users.noreply.github.com>
|
||||||
|
Date: Thu May 15 16:17:50 2025 +0200
|
||||||
|
|
||||||
|
feat: add of an MVC base architecture for Tetris
|
||||||
|
|
||||||
|
[33mcommit 9198a69bc1302376c9c7e3c1154d3ff88fa2213a[m
|
||||||
|
Author: ROGER <gwendal.roger@etu.univ-lyon1.fr>
|
||||||
|
Date: Thu May 15 12:47:11 2025 +0200
|
||||||
|
|
||||||
|
optimisation bouttons controle
|
||||||
|
|
||||||
|
[33mcommit 309eeea534747a70522d6e88779f60906239d793[m
|
||||||
|
Author: ROGER <gwendal.roger@etu.univ-lyon1.fr>
|
||||||
|
Date: Thu May 15 12:36:02 2025 +0200
|
||||||
|
|
||||||
|
ajout d'un compteur de lignes supprimée et d'un bouton pour quitter l'application
|
||||||
|
|
||||||
|
[33mcommit 43037c4174ec4d9e98e904411c9f74ca17aee21a[m
|
||||||
|
Author: ROGER <gwendal.roger@etu.univ-lyon1.fr>
|
||||||
|
Date: Tue May 13 15:16:35 2025 +0200
|
||||||
|
|
||||||
|
Ajout de la visualisation de la prochaine pièce dans vuecontrole
|
||||||
|
|
||||||
|
[33mcommit 6af84d8dda24e9a9155c9ad7144741702bbaa549[m
|
||||||
|
Merge: 9ad9193 275d761
|
||||||
|
Author: ROGER <gwendal.roger@etu.univ-lyon1.fr>
|
||||||
|
Date: Tue May 13 14:37:39 2025 +0200
|
||||||
|
|
||||||
|
Merge remote-tracking branch 'origin/Thibaut' into Gwendal
|
||||||
|
|
||||||
|
[33mcommit 9ad9193244d045a470ecd64b60d4b35da2301432[m
|
||||||
|
Author: ROGER <gwendal.roger@etu.univ-lyon1.fr>
|
||||||
|
Date: Tue May 13 14:36:56 2025 +0200
|
||||||
|
|
||||||
|
ajout rendu pièce suivante
|
||||||
|
|
||||||
|
[33mcommit 275d761f246129253df1ecbc84c42c35f60daacc[m
|
||||||
|
Author: Morph01 <145839520+Morph01@users.noreply.github.com>
|
||||||
|
Date: Tue May 13 14:36:19 2025 +0200
|
||||||
|
|
||||||
|
feat: add Pieces
|
||||||
|
|
||||||
|
[33mcommit f9e3f1d2bba52b83d8bdb909ca2f685fd71a744c[m
|
||||||
|
Author: ROGER <gwendal.roger@etu.univ-lyon1.fr>
|
||||||
|
Date: Tue May 13 14:30:34 2025 +0200
|
||||||
|
|
||||||
|
Ãcréation d'une vue tetris avec bouton paue, score et affichage de la prochaine piece
|
||||||
|
|
||||||
|
[33mcommit 63d5db5d6a80b960acd8bc31900ff1d01ae0a2a2[m
|
||||||
|
Author: ROGER <gwendal.roger@etu.univ-lyon1.fr>
|
||||||
|
Date: Tue May 13 13:00:18 2025 +0200
|
||||||
|
|
||||||
|
ajout de la couleur automatique
|
||||||
|
|
||||||
|
[33mcommit 5a175ea4b487bdcf281e44e7b99629fc6a10848f[m
|
||||||
|
Author: Morph01 <145839520+Morph01@users.noreply.github.com>
|
||||||
|
Date: Tue May 13 12:01:57 2025 +0200
|
||||||
|
|
||||||
|
feat: init VueGrille
|
||||||
|
|
||||||
|
[33mcommit b2649c364bf9bc52d52d609bc617c3ecff92197d[m[33m ([m[1;32mmain[m[33m)[m
|
||||||
|
Author: Morph01 <145839520+Morph01@users.noreply.github.com>
|
||||||
|
Date: Tue May 13 10:38:41 2025 +0200
|
||||||
|
|
||||||
|
feat: first commit
|
||||||
|
|
||||||
|
[33mcommit 47908588e5d785be85631bcd14b437e073c2da36[m
|
||||||
|
Author: Morph01 <thibaut6969delastreet@gmail.com>
|
||||||
|
Date: Tue May 13 08:21:25 2025 +0000
|
||||||
|
|
||||||
|
Initial commit
|
||||||
Reference in New Issue
Block a user