Changement de couleurs
This commit is contained in:
parent
e9651316bf
commit
5f4f03a40a
10
.idea/runConfigurations/Labyrinthe.xml
Normal file
10
.idea/runConfigurations/Labyrinthe.xml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="Labyrinthe" type="Application" factoryName="Application">
|
||||||
|
<option name="MAIN_CLASS_NAME" value="Main" />
|
||||||
|
<module name="SAE21_2022" />
|
||||||
|
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/src" />
|
||||||
|
<method v="2">
|
||||||
|
<option name="Make" enabled="true" />
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
|
</component>
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -24,7 +24,7 @@ public class GridController {
|
|||||||
TheseeController theseeController = new TheseeController(this.model.getThesee(), this.view);
|
TheseeController theseeController = new TheseeController(this.model.getThesee(), this.view);
|
||||||
|
|
||||||
this.view.setPreferredSize(new Dimension(700, 500));
|
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() {
|
this.view.addMouseListener(new MouseAdapter() {
|
||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
@ -123,8 +123,4 @@ public class GridController {
|
|||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public GridView getView() {
|
|
||||||
return this.view;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ import java.awt.*;
|
|||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
|
|
||||||
public class GridView extends JPanel {
|
public class GridView extends JPanel {
|
||||||
|
private Window window;
|
||||||
private Grid model;
|
private Grid model;
|
||||||
private int gridSize;
|
private int gridSize;
|
||||||
private int gridStartX;
|
private int gridStartX;
|
||||||
@ -15,8 +16,9 @@ public class GridView extends JPanel {
|
|||||||
/**
|
/**
|
||||||
* Manages the display of the grid
|
* Manages the display of the grid
|
||||||
*/
|
*/
|
||||||
public GridView() {
|
public GridView(Window window) {
|
||||||
super();
|
super();
|
||||||
|
this.window = window;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGrid(Grid model) {
|
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 i = 0; i < this.model.getSize(); i++) {
|
||||||
for (int j = 0; j < this.model.getSize(); j++) {
|
for (int j = 0; j < this.model.getSize(); j++) {
|
||||||
try {
|
try {
|
||||||
if (this.model.getSquare(i, j).isWall()) g.setColor(Color.BLACK);
|
if (this.model.getSquare(i, j).isWall()) g.setColor(new Color(122, 68, 25));
|
||||||
else g.setColor(Color.WHITE);
|
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.fillRect(this.gridStartX + (this.squareSize * j), this.gridStartY + (this.squareSize * i), this.squareSize, this.squareSize);
|
||||||
|
|
||||||
g.setColor(Color.BLACK);
|
g.setColor(Color.BLACK);
|
||||||
@ -69,7 +71,7 @@ public class GridView extends JPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Draw horizontal lines
|
// Draw horizontal lines
|
||||||
g.setColor(Color.BLACK);
|
g.setColor(new Color(73, 88, 103));
|
||||||
for (int i = 0; i < this.model.getSize()+1; i++) {
|
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));
|
g.drawLine(this.gridStartX, this.gridStartY + (this.squareSize * i), this.gridStartX + (this.squareSize * this.model.getSize()), this.gridStartY + (this.squareSize * i));
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,18 @@
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
public class HomeView extends JPanel {
|
public class HomeView extends JPanel {
|
||||||
private JFrame window;
|
private Window window;
|
||||||
|
|
||||||
public HomeView(JFrame window) {
|
public HomeView(Window window) {
|
||||||
this.window = window;
|
this.window = window;
|
||||||
|
|
||||||
JLabel texte = getTitre();
|
JLabel texte = getTitre();
|
||||||
|
|
||||||
//Récupération des boutons créés dans la classe Boutons
|
//Récupération des boutons créés dans la classe Boutons
|
||||||
JButton choisirGrille = Boutons.ChoisirGrille(this.window);
|
JButton choisirGrille = choisirGrille(this.window);
|
||||||
JButton importerGrille = Boutons.ImporterGrille(this.window);
|
JButton importerGrille = importerGrille(this.window);
|
||||||
|
|
||||||
// Création du panel pour le texte
|
// Création du panel pour le texte
|
||||||
JPanel panelTexte = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
|
JPanel panelTexte = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
|
||||||
@ -37,6 +38,82 @@ public class HomeView extends JPanel {
|
|||||||
return texte;
|
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
|
@Override
|
||||||
public void paintComponent(Graphics g) {
|
public void paintComponent(Graphics g) {
|
||||||
super.paintComponent(g);
|
super.paintComponent(g);
|
||||||
|
Loading…
Reference in New Issue
Block a user