From 5f4f03a40ab4ef2e66dbf5d8023293ede59588e3 Mon Sep 17 00:00:00 2001 From: Lyanis Souidi Date: Thu, 27 Apr 2023 19:10:09 +0200 Subject: [PATCH] Changement de couleurs --- .idea/runConfigurations/Labyrinthe.xml | 10 +++ src/Boutons.java | 85 -------------------------- src/GameController.java | 43 ------------- src/GridController.java | 6 +- src/GridView.java | 10 +-- src/HomeView.java | 85 ++++++++++++++++++++++++-- 6 files changed, 98 insertions(+), 141 deletions(-) create mode 100644 .idea/runConfigurations/Labyrinthe.xml delete mode 100644 src/Boutons.java delete mode 100644 src/GameController.java diff --git a/.idea/runConfigurations/Labyrinthe.xml b/.idea/runConfigurations/Labyrinthe.xml new file mode 100644 index 0000000..833a181 --- /dev/null +++ b/.idea/runConfigurations/Labyrinthe.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/src/Boutons.java b/src/Boutons.java deleted file mode 100644 index 323ea0a..0000000 --- a/src/Boutons.java +++ /dev/null @@ -1,85 +0,0 @@ -import java.awt.*; -import javax.swing.*; -import java.io.File; - -public class Boutons extends JPanel { - public static JButton ChoisirGrille(JFrame window) { - JPanel panel = new JPanel(); - JButton choisirGrille = new JButton("Générer une grille"); - choisirGrille.setPreferredSize(new Dimension(250, 50)); - choisirGrille.setFont(new Font("Arial", Font.BOLD, 20)); - choisirGrille.setBackground(Color.GRAY); - - choisirGrille.addActionListener(e -> { - String strTaille = JOptionPane.showInputDialog(panel, "Entrez la taille de la grille :", "Taille de la grille", JOptionPane.PLAIN_MESSAGE); - if (strTaille != null && !strTaille.isEmpty()) { - if (!Character.isDigit(strTaille.charAt(0))) { - JOptionPane.showMessageDialog(panel, "Le premier caractère doit être un chiffre ou nombre.", "Erreur", JOptionPane.ERROR_MESSAGE); - return; - } - try { - int taille = Integer.parseInt(strTaille); - if (taille > 3 && taille < 21) { - // stocker la taille de la grille choisie - /*this.tailleGrille = taille;*/ - // afficher la taille choisir dans la console - System.out.println("Les dimensions de la grille : " + taille + "x" + taille); - // Afficher la boîte de dialogue pour le choix du remplissage de la grille - String[] options = {"Remplir aléatoirement", "Partir d'une grille vide"}; - int choix = JOptionPane.showOptionDialog(panel, "Choisissez comment remplir la grille :", "Remplissage de la grille", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]); - GridController grille = new GridController(new Grid(taille), new GridView()); - switch (choix) { - case 0: - // afficher la grille aléatoirement - grille.random(); - window.add(grille.getView()); - window.validate(); - break; - case 1: - window.add(grille.getView()); - window.validate(); - break; - default: - // gérer le cas où aucun choix n'a été fait - JOptionPane.showMessageDialog(panel, "Aucun choix n'a été fait.", "Attention", JOptionPane.WARNING_MESSAGE); - return; - } - - } else { - String errorMessage = "La taille doit être au moins de 4."; - if (taille >= 21) { - errorMessage = "La taille ne doit pas dépasser 20."; - } - JOptionPane.showMessageDialog(panel, errorMessage, "Erreur", JOptionPane.ERROR_MESSAGE); - } - } catch (NumberFormatException ex) { - JOptionPane.showMessageDialog(panel, "Tapez " + strTaille.charAt(0) + " pour une grille " + strTaille.charAt(0) +"x"+ strTaille.charAt(0) +".", "Erreur", JOptionPane.ERROR_MESSAGE); - - - } - } - }); - - return choisirGrille; - } - - public static JButton ImporterGrille(JFrame window) { - JPanel panel = new JPanel(); - JButton importerGrille = new JButton("Importer une grille"); - importerGrille.setPreferredSize(new Dimension(250, 50)); - importerGrille.setFont(new Font("Arial", Font.BOLD, 20)); - importerGrille.setBackground(Color.GRAY); - - importerGrille.addActionListener(e -> { - JFileChooser fileChooser = new JFileChooser(); - fileChooser.setDialogTitle("Selectionnez le fichier ou se trouve votre grille"); - int choix = fileChooser.showOpenDialog(panel); - if (choix == JFileChooser.APPROVE_OPTION) { - File fichier = fileChooser.getSelectedFile(); - // TODO: charger la grille depuis le fichier - } - }); - - return importerGrille; - } -} diff --git a/src/GameController.java b/src/GameController.java deleted file mode 100644 index 4ebdb69..0000000 --- a/src/GameController.java +++ /dev/null @@ -1,43 +0,0 @@ -import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; - -public class GameController implements KeyListener { - private int x; - private int y; - - public GameController(int x, int y) { - this.x = x; - this.y = y; - } - - @Override - public void keyTyped(KeyEvent e) { - } - - @Override - public void keyPressed(KeyEvent e) { - int keyCode = e.getKeyCode(); - - if (keyCode == KeyEvent.VK_UP) { - y--; - } else if (keyCode == KeyEvent.VK_DOWN) { - y++; - } else if (keyCode == KeyEvent.VK_LEFT) { - x--; - } else if (keyCode == KeyEvent.VK_RIGHT) { - x++; - } - } - - @Override - public void keyReleased(KeyEvent e) { - } - - public int getX() { - return x; - } - - public int getY() { - return y; - } -} diff --git a/src/GridController.java b/src/GridController.java index 3b59ca0..5689ceb 100644 --- a/src/GridController.java +++ b/src/GridController.java @@ -24,7 +24,7 @@ public class GridController { TheseeController theseeController = new TheseeController(this.model.getThesee(), this.view); this.view.setPreferredSize(new Dimension(700, 500)); - this.view.setBackground(Color.WHITE); + this.view.setBackground(new Color(193, 190, 180)); this.view.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { @@ -123,8 +123,4 @@ public class GridController { System.out.println(e.getMessage()); } } - - public GridView getView() { - return this.view; - } } diff --git a/src/GridView.java b/src/GridView.java index 469a30d..bcefb17 100644 --- a/src/GridView.java +++ b/src/GridView.java @@ -3,6 +3,7 @@ import java.awt.*; import java.awt.event.MouseEvent; public class GridView extends JPanel { + private Window window; private Grid model; private int gridSize; private int gridStartX; @@ -15,8 +16,9 @@ public class GridView extends JPanel { /** * Manages the display of the grid */ - public GridView() { + public GridView(Window window) { super(); + this.window = window; } public void setGrid(Grid model) { @@ -46,8 +48,8 @@ public class GridView extends JPanel { for (int i = 0; i < this.model.getSize(); i++) { for (int j = 0; j < this.model.getSize(); j++) { try { - if (this.model.getSquare(i, j).isWall()) g.setColor(Color.BLACK); - else g.setColor(Color.WHITE); + if (this.model.getSquare(i, j).isWall()) g.setColor(new Color(122, 68, 25)); + else g.setColor(new Color(77, 170, 87)); g.fillRect(this.gridStartX + (this.squareSize * j), this.gridStartY + (this.squareSize * i), this.squareSize, this.squareSize); g.setColor(Color.BLACK); @@ -69,7 +71,7 @@ public class GridView extends JPanel { } // Draw horizontal lines - g.setColor(Color.BLACK); + g.setColor(new Color(73, 88, 103)); for (int i = 0; i < this.model.getSize()+1; i++) { g.drawLine(this.gridStartX, this.gridStartY + (this.squareSize * i), this.gridStartX + (this.squareSize * this.model.getSize()), this.gridStartY + (this.squareSize * i)); } diff --git a/src/HomeView.java b/src/HomeView.java index 592af28..725d5ec 100644 --- a/src/HomeView.java +++ b/src/HomeView.java @@ -1,17 +1,18 @@ import javax.swing.*; import java.awt.*; +import java.io.File; public class HomeView extends JPanel { - private JFrame window; + private Window window; - public HomeView(JFrame window) { + public HomeView(Window window) { this.window = window; JLabel texte = getTitre(); //Récupération des boutons créés dans la classe Boutons - JButton choisirGrille = Boutons.ChoisirGrille(this.window); - JButton importerGrille = Boutons.ImporterGrille(this.window); + JButton choisirGrille = choisirGrille(this.window); + JButton importerGrille = importerGrille(this.window); // Création du panel pour le texte JPanel panelTexte = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0)); @@ -37,6 +38,82 @@ public class HomeView extends JPanel { return texte; } + private static JButton choisirGrille(Window window) { + JPanel panel = new JPanel(); + JButton choisirGrille = new JButton("Générer une grille"); + choisirGrille.setPreferredSize(new Dimension(250, 50)); + choisirGrille.setFont(new Font("Arial", Font.BOLD, 20)); + choisirGrille.setBackground(Color.GRAY); + + choisirGrille.addActionListener(e -> { + String strTaille = JOptionPane.showInputDialog(panel, "Entrez la taille de la grille :", "Taille de la grille", JOptionPane.PLAIN_MESSAGE); + if (strTaille != null && !strTaille.isEmpty()) { + if (!Character.isDigit(strTaille.charAt(0))) { + JOptionPane.showMessageDialog(panel, "Le premier caractère doit être un chiffre ou nombre.", "Erreur", JOptionPane.ERROR_MESSAGE); + return; + } + try { + int taille = Integer.parseInt(strTaille); + if (taille > 3 && taille < 21) { + String[] options = {"Remplir aléatoirement", "Partir d'une grille vide"}; + int choix = JOptionPane.showOptionDialog(panel, "Choisissez comment remplir la grille :", "Remplissage de la grille", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]); + GridView gridView = new GridView(window); + GridController grille = new GridController(new Grid(taille), gridView); + switch (choix) { + case 0: + // afficher la grille aléatoirement + grille.random(); + window.setContentPane(gridView); + window.validate(); + break; + case 1: + window.setContentPane(gridView); + window.validate(); + break; + default: + // gérer le cas où aucun choix n'a été fait + JOptionPane.showMessageDialog(panel, "Aucun choix n'a été fait.", "Attention", JOptionPane.WARNING_MESSAGE); + return; + } + + } else { + String errorMessage = "La taille doit être au moins de 4."; + if (taille >= 21) { + errorMessage = "La taille ne doit pas dépasser 20."; + } + JOptionPane.showMessageDialog(panel, errorMessage, "Erreur", JOptionPane.ERROR_MESSAGE); + } + } catch (NumberFormatException ex) { + JOptionPane.showMessageDialog(panel, "Tapez " + strTaille.charAt(0) + " pour une grille " + strTaille.charAt(0) +"x"+ strTaille.charAt(0) +".", "Erreur", JOptionPane.ERROR_MESSAGE); + + + } + } + }); + + return choisirGrille; + } + + private static JButton importerGrille(JFrame window) { + JPanel panel = new JPanel(); + JButton importerGrille = new JButton("Importer une grille"); + importerGrille.setPreferredSize(new Dimension(250, 50)); + importerGrille.setFont(new Font("Arial", Font.BOLD, 20)); + importerGrille.setBackground(Color.GRAY); + + importerGrille.addActionListener(e -> { + JFileChooser fileChooser = new JFileChooser(); + fileChooser.setDialogTitle("Selectionnez le fichier ou se trouve votre grille"); + int choix = fileChooser.showOpenDialog(panel); + if (choix == JFileChooser.APPROVE_OPTION) { + File fichier = fileChooser.getSelectedFile(); + // TODO: charger la grille depuis le fichier + } + }); + + return importerGrille; + } + @Override public void paintComponent(Graphics g) { super.paintComponent(g);