Ãcréation d'une vue tetris avec bouton paue, score et affichage de la prochaine piece
This commit is contained in:
@@ -4,16 +4,17 @@
|
||||
package org;
|
||||
|
||||
import org.Models.Grille;
|
||||
import org.Views.VueControle;
|
||||
import org.Views.VueGrille;
|
||||
import org.Views.VueTetris;
|
||||
|
||||
public class App {
|
||||
public String getGreeting() {
|
||||
return "Hello World!";
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(new App().getGreeting());
|
||||
Grille grille = new Grille(10, 10);
|
||||
VueGrille vueGrille = new VueGrille(grille);
|
||||
//VueGrille vueGrille = new VueGrille(grille);
|
||||
VueTetris vueTetris = new VueTetris(grille);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
54
app/src/main/java/org/Views/VueControle.java
Normal file
54
app/src/main/java/org/Views/VueControle.java
Normal file
@@ -0,0 +1,54 @@
|
||||
package org.Views;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class VueControle extends JPanel {
|
||||
private JLabel scoreLabel;
|
||||
private JPanel nextPiecePanel;
|
||||
private JButton pauseButton;
|
||||
|
||||
public VueControle() {
|
||||
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
|
||||
setBackground(Color.gray);
|
||||
setPreferredSize(new Dimension(200, 600));
|
||||
|
||||
//SCORE
|
||||
scoreLabel = new JLabel("Score: 0");
|
||||
scoreLabel.setForeground(Color.white);
|
||||
scoreLabel.setFont(new Font("Arial", Font.PLAIN, 16));
|
||||
scoreLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||
|
||||
//NEXT PIECE
|
||||
nextPiecePanel = new JPanel();
|
||||
nextPiecePanel.setPreferredSize(new Dimension(100, 100));
|
||||
nextPiecePanel.setMaximumSize(new Dimension(100, 100));
|
||||
nextPiecePanel.setBackground(Color.LIGHT_GRAY);
|
||||
nextPiecePanel.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||
|
||||
//PAUSE BUTTON
|
||||
pauseButton = new JButton("Pause");
|
||||
pauseButton.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||
|
||||
add(Box.createVerticalStrut(20)); // Add some space at the top
|
||||
add(scoreLabel);
|
||||
add(Box.createVerticalStrut(20)); // Add some space between score and next piece
|
||||
add(nextPiecePanel);
|
||||
add(Box.createVerticalStrut(20)); // Add some space between next piece and button
|
||||
add(pauseButton);
|
||||
|
||||
//setVisible(true);
|
||||
}
|
||||
|
||||
public void setScore(int score) {
|
||||
scoreLabel.setText("Score: " + score);
|
||||
}
|
||||
|
||||
public JButton getPauseButton() {
|
||||
return pauseButton;
|
||||
}
|
||||
|
||||
public JPanel getNextPiecePanel() {
|
||||
return nextPiecePanel;
|
||||
}
|
||||
}
|
||||
@@ -7,19 +7,20 @@ import javax.swing.border.Border;
|
||||
|
||||
import org.Models.Grille;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.*;
|
||||
|
||||
public class VueGrille extends JFrame {
|
||||
public class VueGrille extends JPanel {
|
||||
private JPanel grillePanel;
|
||||
private int tailleJPanel = 1000;
|
||||
private Grille grille;
|
||||
|
||||
public VueGrille(Grille grille) {
|
||||
this.grille = grille;
|
||||
setLayout(new BorderLayout());
|
||||
grillePanel = new JPanel(new GridLayout(grille.getNbLignes(), grille.getNbColonnes()));
|
||||
setSize(tailleJPanel, tailleJPanel);
|
||||
setContentPane(grillePanel);
|
||||
//setSize(tailleJPanel, tailleJPanel);
|
||||
add(grillePanel, BorderLayout.CENTER);
|
||||
//setContentPane(grillePanel);
|
||||
initialiserVueGrille();
|
||||
}
|
||||
|
||||
@@ -33,10 +34,10 @@ public class VueGrille extends JFrame {
|
||||
grillePanel.add(caseG);
|
||||
}
|
||||
}
|
||||
setVisible(true);
|
||||
//setVisible(true);
|
||||
|
||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
setTitle("TETRIS");
|
||||
//setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
//setTitle("TETRIS");
|
||||
|
||||
}
|
||||
|
||||
|
||||
27
app/src/main/java/org/Views/VueTetris.java
Normal file
27
app/src/main/java/org/Views/VueTetris.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package org.Views;
|
||||
|
||||
import org.Models.Grille;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class VueTetris extends JFrame {
|
||||
public VueTetris (Grille grille){
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
VueGrille vueGrille = new VueGrille(grille);
|
||||
VueControle vueControle = new VueControle();
|
||||
|
||||
//Fenetre principale
|
||||
JFrame fenetrePrincipale = new JFrame("Tetris");
|
||||
fenetrePrincipale.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
fenetrePrincipale.setLayout(new BorderLayout());
|
||||
|
||||
fenetrePrincipale.add(vueGrille, BorderLayout.CENTER);
|
||||
fenetrePrincipale.add(vueControle, BorderLayout.EAST);
|
||||
|
||||
fenetrePrincipale.setSize(1000, 800);
|
||||
fenetrePrincipale.setLocationRelativeTo(null);
|
||||
fenetrePrincipale.setVisible(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user