ajout grille (conception et affichage), essai joueur

This commit is contained in:
diane 2023-04-04 10:29:36 +02:00
parent 27a7ffdb77
commit a48c472332
3 changed files with 124 additions and 92 deletions

BIN
images/joueur.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

View File

@ -33,12 +33,12 @@ public class JPanelDessin extends JPanel {
x=0;
y=0;
while (y<height) {
g.setColor(Color.magenta);
g.setColor(new Color(235, 235, 235));
g.drawLine(0, y, width, y);
y= y + height/11;
}
while (x<width) {
g.setColor(Color.magenta);
while (x<=width) {
g.setColor(new Color(235, 235, 235));
g.drawLine(x, 0, x, height);
x= x + width/11;
}

View File

@ -37,6 +37,8 @@ import java.awt.Insets;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.JProgressBar;
import java.awt.CardLayout;
import javax.swing.JLayeredPane;
@ -44,10 +46,10 @@ public class MaJFrame extends JFrame {
private JPanel contentPane;
private static final long serialVersionUID = 7252959164975426293L;
private JPanel panel;
private JPanel panel_1;
private JLabel lblNewLabel;
private JPanel panel_2;
private JPanel panelBoutonJouer;
private JPanel panelEnsemble;
private JLabel lblZombicide;
private JPanel panelInfo;
private JButton btnDeplacer;
private JButton btnTuer;
private JSpinner deplacementX;
@ -55,13 +57,14 @@ public class MaJFrame extends JFrame {
private JLabel lblDepX;
private JLabel lblDepY;
private JLabel lblScore;
private JPanel panel_3;
private JPanel panelScore;
private JLabel lblScoreVie;
private JLabel lblAttaque;
private JProgressBar progressBarVie;
private JProgressBar progressBarAttaque;
private JPanel panel_4;
private JPanelImage panel_5;
private JPanelImage panelMap;
private JPanelDessin panelGrille;
/**
@ -89,20 +92,20 @@ public class MaJFrame extends JFrame {
setTitle("Zombicide");
setBackground(new Color(128, 0, 0));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 715, 551);
setBounds(100, 100, 752, 558);
contentPane = new JPanel();
contentPane.setBackground(new Color(128, 0, 0));
contentPane.setBorder(new EmptyBorder(2, 2, 2, 2));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
//création panel avec bouton
panel = new JPanel();
panel.setBorder(null);
panel.setBackground(new Color(64, 0, 0));
contentPane.add(panel); //, "cell 10 10,grow"
contentPane.add(panel, BorderLayout.NORTH);
panel.setLayout(new BorderLayout(0, 0));
//création panel bouton Jouer
panelBoutonJouer = new JPanel();
panelBoutonJouer.setBorder(null);
panelBoutonJouer.setBackground(new Color(64, 0, 0));
contentPane.add(panelBoutonJouer); //, "cell 10 10,grow"
contentPane.add(panelBoutonJouer, BorderLayout.NORTH);
panelBoutonJouer.setLayout(new BorderLayout(0, 0));
JButton btnJouer = new JButton("JOUER !");
btnJouer.setForeground(new Color(255, 255, 255));
@ -112,51 +115,85 @@ public class MaJFrame extends JFrame {
clicBoutonJouer();
}
});
panel.add(btnJouer);
panelBoutonJouer.add(btnJouer);
//création panel_1 IMAGE
panel_1 = new JPanel();
panel_1.setBorder(null);
contentPane.add(panel_1, BorderLayout.CENTER);
GridBagLayout gbl_panel_1 = new GridBagLayout();
gbl_panel_1.columnWidths = new int[] {620, 75, 0};
gbl_panel_1.rowHeights = new int[]{489, 0};
gbl_panel_1.columnWeights = new double[]{0.0, 0.0, Double.MIN_VALUE};
gbl_panel_1.rowWeights = new double[]{0.0, Double.MIN_VALUE};
panel_1.setLayout(gbl_panel_1);
//création panelEnsemble contient panelMap et panelInofo
panelEnsemble = new JPanel();
panelEnsemble.setBorder(null);
contentPane.add(panelEnsemble, BorderLayout.CENTER);
GridBagLayout gbl_panelEnsemble = new GridBagLayout();
gbl_panelEnsemble.columnWidths = new int[] {620, 75, 0};
gbl_panelEnsemble.rowHeights = new int[]{489, 0};
gbl_panelEnsemble.columnWeights = new double[]{0.0, 0.0};
gbl_panelEnsemble.rowWeights = new double[]{0.0, Double.MIN_VALUE};
panelEnsemble.setLayout(gbl_panelEnsemble);
panel_5 = new JPanelImage("map1.jpg");
FlowLayout flowLayout = (FlowLayout) panel_5.getLayout();
flowLayout.setVgap(0);
flowLayout.setHgap(0);
GridBagConstraints gbc_panel_5 = new GridBagConstraints();
gbc_panel_5.insets = new Insets(0, 0, 0, 5);
gbc_panel_5.fill = GridBagConstraints.BOTH;
gbc_panel_5.gridx = 0;
gbc_panel_5.gridy = 0;
panel_1.add(panel_5, gbc_panel_5);
//création panel Map
panelMap = new JPanelImage("map1.jpg");
GridBagConstraints gbc_panelMap = new GridBagConstraints();
gbc_panelMap.insets = new Insets(0, 0, 0, 5);
gbc_panelMap.fill = GridBagConstraints.BOTH;
gbc_panelMap.gridx = 0;
gbc_panelMap.gridy = 0;
panelEnsemble.add(panelMap, gbc_panelMap);
panelMap.setLayout(new CardLayout(0, 0));
lblNewLabel = new JLabel("ZOMBICIDE");
lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 40));
lblNewLabel.setForeground(new Color(255, 255, 255));
lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
panel_5.add(lblNewLabel);
lblNewLabel.setVisible(true);
//création panel Grille
panelGrille = new JPanelDessin();
panelGrille.setBackground(null);
panelGrille.setForeground(new Color(235, 235, 235));
panelGrille.setOpaque(false);
panelMap.add(panelGrille, "panelGrille");
GridBagLayout gbl_panelGrille = new GridBagLayout();
gbl_panelGrille.columnWidths = new int[] {56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56};
gbl_panelGrille.rowHeights = new int[] {45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45};
gbl_panelGrille.columnWeights = new double[]{0.0};
gbl_panelGrille.rowWeights = new double[]{0.0};
panelGrille.setLayout(gbl_panelGrille);
// création panel_2 Boutons
panel_2 = new JPanel();
panel_2.setBackground(new Color(95, 95, 95));
GridBagConstraints gbc_panel_2 = new GridBagConstraints();
gbc_panel_2.fill = GridBagConstraints.BOTH;
gbc_panel_2.gridx = 1;
gbc_panel_2.gridy = 0;
panel_1.add(panel_2, gbc_panel_2);
GridBagLayout gbl_panel_2 = new GridBagLayout();
gbl_panel_2.columnWidths = new int[] {75};
gbl_panel_2.rowHeights = new int[] {20, 100, 91, 30, 30, 30, 30, 10, 91, 0};
gbl_panel_2.columnWeights = new double[]{1.0};
gbl_panel_2.rowWeights = new double[]{0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
panel_2.setLayout(gbl_panel_2);
// panelGrille = new JPanel();
// panelGrille.setBackground(new Color(192, 192, 192));
// panelGrille.setForeground(new Color(128, 0, 64));
// panelMap.add(panelGrille, "panelGrille");
// GridBagLayout gbl_panelGrille = new GridBagLayout();
// gbl_panelGrille.columnWidths = new int[] {56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56};
// gbl_panelGrille.rowHeights = new int[] {45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45};
// gbl_panelGrille.columnWeights = new double[]{0.0};
// gbl_panelGrille.rowWeights = new double[]{0.0};
// panelGrille.setLayout(gbl_panelGrille);
// //ajout joueur
// GridBagConstraints gbc_panelGrille = new GridBagConstraints();
// gbc_panelGrille.fill = GridBagConstraints.BOTH;
// gbc_panelGrille.gridx = 2;
// gbc_panelGrille.gridy = 4;
// gbc_panelGrille.gridwidth = 1; // Occupy 1 column
// gbc_panelGrille.gridheight = 1; // Occupy 1 row
// gbc_panelGrille.anchor = GridBagConstraints.CENTER;
// panelGrille.add("joueur.png", gbc_panelGrille);
lblZombicide = new JLabel("ZOMBICIDE");
lblZombicide.setFont(new Font("Tahoma", Font.BOLD, 40));
lblZombicide.setForeground(new Color(255, 255, 255));
lblZombicide.setHorizontalAlignment(SwingConstants.CENTER);
panelMap.add(lblZombicide, "lblZombicide");
lblZombicide.setVisible(true);
// création panelInfo
panelInfo = new JPanel();
panelInfo.setBackground(new Color(95, 95, 95));
GridBagConstraints gbc_panelInfo = new GridBagConstraints();
gbc_panelInfo.fill = GridBagConstraints.BOTH;
gbc_panelInfo.gridx = 1;
gbc_panelInfo.gridy = 0;
panelEnsemble.add(panelInfo, gbc_panelInfo);
GridBagLayout gbl_panelInfo = new GridBagLayout();
gbl_panelInfo.columnWidths = new int[] {75};
gbl_panelInfo.rowHeights = new int[] {20, 100, 91, 30, 30, 30, 30, 10, 91, 0};
gbl_panelInfo.columnWeights = new double[]{1.0};
gbl_panelInfo.rowWeights = new double[]{0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
panelInfo.setLayout(gbl_panelInfo);
lblScore = new JLabel("Scores");
lblScore.setForeground(new Color(240, 240, 240));
@ -166,7 +203,7 @@ public class MaJFrame extends JFrame {
gbc_lblScore.insets = new Insets(0, 0, 5, 0);
gbc_lblScore.gridx = 0;
gbc_lblScore.gridy = 0;
panel_2.add(lblScore, gbc_lblScore);
panelInfo.add(lblScore, gbc_lblScore);
btnDeplacer = new JButton("Déplacer");
btnDeplacer.setIcon(null);
@ -175,20 +212,20 @@ public class MaJFrame extends JFrame {
}
});
panel_3 = new JPanel();
panel_3.setBackground(new Color(95, 95, 95));
GridBagConstraints gbc_panel_3 = new GridBagConstraints();
gbc_panel_3.anchor = GridBagConstraints.NORTH;
gbc_panel_3.insets = new Insets(0, 0, 5, 0);
gbc_panel_3.gridx = 0;
gbc_panel_3.gridy = 1;
panel_2.add(panel_3, gbc_panel_3);
GridBagLayout gbl_panel_3 = new GridBagLayout();
gbl_panel_3.columnWidths = new int[] {30, 10};
gbl_panel_3.rowHeights = new int[] {30, 90, 0};
gbl_panel_3.columnWeights = new double[]{1.0, 0.0};
gbl_panel_3.rowWeights = new double[]{0.0, 0.0, 1.0};
panel_3.setLayout(gbl_panel_3);
panelScore = new JPanel();
panelScore.setBackground(new Color(95, 95, 95));
GridBagConstraints gbc_panelScore = new GridBagConstraints();
gbc_panelScore.anchor = GridBagConstraints.NORTH;
gbc_panelScore.insets = new Insets(0, 0, 5, 0);
gbc_panelScore.gridx = 0;
gbc_panelScore.gridy = 1;
panelInfo.add(panelScore, gbc_panelScore);
GridBagLayout gbl_panelScore = new GridBagLayout();
gbl_panelScore.columnWidths = new int[] {30, 10};
gbl_panelScore.rowHeights = new int[] {30, 90, 0};
gbl_panelScore.columnWeights = new double[]{1.0, 0.0};
gbl_panelScore.rowWeights = new double[]{0.0, 0.0, 1.0};
panelScore.setLayout(gbl_panelScore);
lblScoreVie = new JLabel("Vies");
lblScoreVie.setForeground(new Color(240, 240, 240));
@ -198,7 +235,7 @@ public class MaJFrame extends JFrame {
gbc_lblScoreVie.insets = new Insets(0, 0, 5, 5);
gbc_lblScoreVie.gridx = 0;
gbc_lblScoreVie.gridy = 0;
panel_3.add(lblScoreVie, gbc_lblScoreVie);
panelScore.add(lblScoreVie, gbc_lblScoreVie);
lblAttaque = new JLabel("Attaque");
lblAttaque.setForeground(new Color(240, 240, 240));
@ -208,7 +245,7 @@ public class MaJFrame extends JFrame {
gbc_lblAttaque.insets = new Insets(0, 0, 5, 0);
gbc_lblAttaque.gridx = 1;
gbc_lblAttaque.gridy = 0;
panel_3.add(lblAttaque, gbc_lblAttaque);
panelScore.add(lblAttaque, gbc_lblAttaque);
progressBarVie = new JProgressBar();
progressBarVie.setForeground(new Color(0, 255, 0));
@ -220,7 +257,7 @@ public class MaJFrame extends JFrame {
gbc_progressBarVie.insets = new Insets(0, 0, 5, 5);
gbc_progressBarVie.gridx = 0;
gbc_progressBarVie.gridy = 1;
panel_3.add(progressBarVie, gbc_progressBarVie);
panelScore.add(progressBarVie, gbc_progressBarVie);
progressBarAttaque = new JProgressBar();
progressBarAttaque.setForeground(new Color(255, 0, 0));
@ -232,21 +269,15 @@ public class MaJFrame extends JFrame {
gbc_progressBarAttaque.fill = GridBagConstraints.VERTICAL;
gbc_progressBarAttaque.gridx = 1;
gbc_progressBarAttaque.gridy = 1;
panel_3.add(progressBarAttaque, gbc_progressBarAttaque);
panelScore.add(progressBarAttaque, gbc_progressBarAttaque);
panel_4 = new JPanel();
GridBagConstraints gbc_panel_4 = new GridBagConstraints();
gbc_panel_4.insets = new Insets(0, 0, 0, 5);
gbc_panel_4.fill = GridBagConstraints.BOTH;
gbc_panel_4.gridx = 0;
gbc_panel_4.gridy = 2;
panel_3.add(panel_4, gbc_panel_4);
//création boutonDeplacer
GridBagConstraints gbc_btnDeplacer = new GridBagConstraints();
gbc_btnDeplacer.fill = GridBagConstraints.BOTH;
gbc_btnDeplacer.insets = new Insets(0, 0, 5, 0);
gbc_btnDeplacer.gridx = 0;
gbc_btnDeplacer.gridy = 2;
panel_2.add(btnDeplacer, gbc_btnDeplacer);
panelInfo.add(btnDeplacer, gbc_btnDeplacer);
lblDepX = new JLabel("déplacement X");
lblDepX.setForeground(new Color(240, 240, 240));
@ -256,7 +287,7 @@ public class MaJFrame extends JFrame {
gbc_lblDepX.insets = new Insets(0, 0, 5, 0);
gbc_lblDepX.gridx = 0;
gbc_lblDepX.gridy = 3;
panel_2.add(lblDepX, gbc_lblDepX);
panelInfo.add(lblDepX, gbc_lblDepX);
deplacementX = new JSpinner();
deplacementX.setFont(new Font("Tahoma", Font.PLAIN, 10));
@ -265,7 +296,7 @@ public class MaJFrame extends JFrame {
gbc_deplacementX.insets = new Insets(0, 0, 5, 0);
gbc_deplacementX.gridx = 0;
gbc_deplacementX.gridy = 4;
panel_2.add(deplacementX, gbc_deplacementX);
panelInfo.add(deplacementX, gbc_deplacementX);
lblDepY = new JLabel("déplacement Y");
lblDepY.setForeground(new Color(240, 240, 240));
@ -275,7 +306,7 @@ public class MaJFrame extends JFrame {
gbc_lblDepY.insets = new Insets(0, 0, 5, 0);
gbc_lblDepY.gridx = 0;
gbc_lblDepY.gridy = 5;
panel_2.add(lblDepY, gbc_lblDepY);
panelInfo.add(lblDepY, gbc_lblDepY);
deplacementY = new JSpinner();
deplacementY.setFont(new Font("Tahoma", Font.PLAIN, 10));
@ -284,8 +315,9 @@ public class MaJFrame extends JFrame {
gbc_deplacementY.insets = new Insets(0, 0, 5, 0);
gbc_deplacementY.gridx = 0;
gbc_deplacementY.gridy = 6;
panel_2.add(deplacementY, gbc_deplacementY);
panelInfo.add(deplacementY, gbc_deplacementY);
//création boutonTuer
btnTuer = new JButton("Tuer");
btnTuer.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
@ -295,13 +327,13 @@ public class MaJFrame extends JFrame {
gbc_btnTuer.fill = GridBagConstraints.BOTH;
gbc_btnTuer.gridx = 0;
gbc_btnTuer.gridy = 8;
panel_2.add(btnTuer, gbc_btnTuer);
panelInfo.add(btnTuer, gbc_btnTuer);
}
public void clicBoutonJouer() {
lblNewLabel.setVisible(false);
lblZombicide.setVisible(false);
}