commit
This commit is contained in:
parent
b05b7cd13c
commit
29ce62150e
10 changed files with 153 additions and 37 deletions
|
@ -10,7 +10,9 @@ import java.util.stream.Stream;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import userInterface.UserInterface;
|
import userInterface.UserInterface;
|
||||||
import universe.*;
|
import universe.Universe;
|
||||||
|
import universe.Stack;
|
||||||
|
import universe.Situation;
|
||||||
|
|
||||||
public class AppLaser {
|
public class AppLaser {
|
||||||
public static void main(String [] args) {
|
public static void main(String [] args) {
|
||||||
|
@ -46,12 +48,11 @@ public class AppLaser {
|
||||||
else if (start_dir == 12) firstState_j = start_j + 1;
|
else if (start_dir == 12) firstState_j = start_j + 1;
|
||||||
else if (start_dir == 13) firstState_j = start_j - 1;
|
else if (start_dir == 13) firstState_j = start_j - 1;
|
||||||
|
|
||||||
|
Stack <Situation> stack = new Stack <Situation>();
|
||||||
|
Universe universe = new Universe(universe_width + 2, universe_height + 2, start_i + 1, start_j + 1, start_dir);
|
||||||
|
Situation currentState = new Situation(firstState_i + 1, firstState_j + 1, start_dir, 0);
|
||||||
|
|
||||||
if (cli == true) {
|
if (cli == true) {
|
||||||
|
|
||||||
Stack <Situation> stack = new Stack <Situation>();
|
|
||||||
Universe universe = new Universe(universe_width + 2, universe_height + 2, start_i + 1, start_j + 1, start_dir);
|
|
||||||
Situation currentState = new Situation(firstState_i + 1, firstState_j + 1, start_dir, 0);
|
|
||||||
|
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
|
||||||
int choice;
|
int choice;
|
||||||
|
@ -315,7 +316,7 @@ public class AppLaser {
|
||||||
} while (choice != 0);
|
} while (choice != 0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
UserInterface userInterface= new UserInterface();
|
UserInterface userInterface = new UserInterface(universe);
|
||||||
userInterface.start();
|
userInterface.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
BIN
images/blade.png
Normal file
BIN
images/blade.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
BIN
images/new.png
Normal file
BIN
images/new.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 861 B |
BIN
images/open.png
Normal file
BIN
images/open.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 621 B |
BIN
images/save.png
Normal file
BIN
images/save.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 720 B |
6
makefile
6
makefile
|
@ -1,11 +1,17 @@
|
||||||
build:
|
build:
|
||||||
|
javac --source 1.8 --target 1.8 universe/*.java
|
||||||
|
javac --source 1.8 --target 1.8 userInterface/*.java
|
||||||
javac --source 1.8 --target 1.8 AppLaser.java
|
javac --source 1.8 --target 1.8 AppLaser.java
|
||||||
jar cfe AppLaser.jar AppLaser *.class
|
jar cfe AppLaser.jar AppLaser *.class
|
||||||
|
|
||||||
run:
|
run:
|
||||||
|
javac --source 1.8 --target 1.8 universe/*.java
|
||||||
|
javac --source 1.8 --target 1.8 userInterface/*.java
|
||||||
javac --source 1.8 --target 1.8 AppLaser.java
|
javac --source 1.8 --target 1.8 AppLaser.java
|
||||||
java AppLaser -cli --optimize-duration
|
java AppLaser -cli --optimize-duration
|
||||||
|
|
||||||
run_gui:
|
run_gui:
|
||||||
|
javac --source 1.8 --target 1.8 universe/*.java
|
||||||
|
javac --source 1.8 --target 1.8 userInterface/*.java
|
||||||
javac --source 1.8 --target 1.8 AppLaser.java
|
javac --source 1.8 --target 1.8 AppLaser.java
|
||||||
java AppLaser
|
java AppLaser
|
||||||
|
|
|
@ -381,4 +381,12 @@ public class Universe {
|
||||||
public int[][] copyGrid() {
|
public int[][] copyGrid() {
|
||||||
return this.grid.clone();
|
return this.grid.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getWidth() {
|
||||||
|
return this.width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getHeight() {
|
||||||
|
return this.height;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,16 +20,19 @@ import java.awt.image.BufferedImage;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
public class Grid extends JPanel {
|
public class Grid extends JPanel {
|
||||||
private int rows;
|
private int rows;
|
||||||
private int cols;
|
private int cols;
|
||||||
private Color[][] colors;
|
private Color[][] colors;
|
||||||
|
private MouseAdapter mouseListener;
|
||||||
|
|
||||||
public Grid(int rows, int cols) {
|
public Grid(int rows, int cols) {
|
||||||
this.rows = rows;
|
this.rows = rows;
|
||||||
this.cols = cols;
|
this.cols = cols;
|
||||||
setPreferredSize(new Dimension(400, 400));
|
this.setPreferredSize(new Dimension(400, 400));
|
||||||
setBackground(Color.WHITE);
|
this.setBackground(Color.WHITE);
|
||||||
|
|
||||||
colors = new Color[rows][cols];
|
colors = new Color[rows][cols];
|
||||||
for (int i = 0; i < rows; i++) {
|
for (int i = 0; i < rows; i++) {
|
||||||
|
@ -38,7 +41,7 @@ public class Grid extends JPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addMouseListener(new MouseAdapter() {
|
mouseListener = new MouseAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void mousePressed(MouseEvent evt) {
|
public void mousePressed(MouseEvent evt) {
|
||||||
int cellWidth = getWidth() / cols;
|
int cellWidth = getWidth() / cols;
|
||||||
|
@ -48,7 +51,7 @@ public class Grid extends JPanel {
|
||||||
|
|
||||||
if (row >= 0 && row < rows && col >= 0 && col < cols) {
|
if (row >= 0 && row < rows && col >= 0 && col < cols) {
|
||||||
if (colors[row][col] == Color.WHITE) {
|
if (colors[row][col] == Color.WHITE) {
|
||||||
colors[row][col] = Color.RED;
|
colors[row][col] = Color.GRAY;
|
||||||
} else {
|
} else {
|
||||||
colors[row][col] = Color.WHITE;
|
colors[row][col] = Color.WHITE;
|
||||||
}
|
}
|
||||||
|
@ -60,7 +63,8 @@ public class Grid extends JPanel {
|
||||||
public void mouseEntered(MouseEvent e) {
|
public void mouseEntered(MouseEvent e) {
|
||||||
try {
|
try {
|
||||||
// Charger l'image pour le curseur personnalisé
|
// Charger l'image pour le curseur personnalisé
|
||||||
BufferedImage cursorImage = ImageIO.read(new File("h:\\Mes documents\\INF1404\\projet\\picture\\sabre.png"));
|
URL url = getClass().getResource("../images/blade.png");
|
||||||
|
BufferedImage cursorImage = ImageIO.read(new File(url.getPath()));
|
||||||
// Créer le curseur personnalisé
|
// Créer le curseur personnalisé
|
||||||
Cursor customCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImage, new Point(0, 0), "customCursor");
|
Cursor customCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImage, new Point(0, 0), "customCursor");
|
||||||
// Définir le curseur personnalisé
|
// Définir le curseur personnalisé
|
||||||
|
@ -74,18 +78,20 @@ public class Grid extends JPanel {
|
||||||
public void mouseExited(MouseEvent e) {
|
public void mouseExited(MouseEvent e) {
|
||||||
setCursor(Cursor.getDefaultCursor()); // Rétablir l'icône de la souris par défaut quand elle quitte le composant
|
setCursor(Cursor.getDefaultCursor()); // Rétablir l'icône de la souris par défaut quand elle quitte le composant
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
|
this.addMouseListener(this.mouseListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintComponent(Graphics g) {
|
protected void paintComponent(Graphics g) {
|
||||||
super.paintComponent(g);
|
super.paintComponent(g);
|
||||||
int cellWidth = getWidth() / cols;
|
int cellWidth = this.getWidth() / this.cols;
|
||||||
int cellHeight = getHeight() / rows;
|
int cellHeight = this.getHeight() / this.rows;
|
||||||
|
|
||||||
// Dessiner les cases avec les couleurs stockées
|
// Dessiner les cases avec les couleurs stockées
|
||||||
for (int i = 0; i < rows; i++) {
|
for (int i = 0; i < this.rows; i++) {
|
||||||
for (int j = 0; j < cols; j++) {
|
for (int j = 0; j < this.cols; j++) {
|
||||||
g.setColor(colors[i][j]);
|
g.setColor(colors[i][j]);
|
||||||
g.fillRect(j * cellWidth, i * cellHeight, cellWidth, cellHeight);
|
g.fillRect(j * cellWidth, i * cellHeight, cellWidth, cellHeight);
|
||||||
}
|
}
|
||||||
|
@ -100,4 +106,61 @@ public class Grid extends JPanel {
|
||||||
g.drawLine(j * cellWidth, 0, j * cellWidth, getHeight());
|
g.drawLine(j * cellWidth, 0, j * cellWidth, getHeight());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void changeDim(int width, int height) {
|
||||||
|
this.rows = height;
|
||||||
|
this.cols = width;
|
||||||
|
this.setPreferredSize(new Dimension(700, 400));
|
||||||
|
this.setBackground(Color.WHITE);
|
||||||
|
|
||||||
|
this.colors = new Color[height][width];
|
||||||
|
for (int i = 0; i < rows; i++) {
|
||||||
|
for (int j = 0; j < cols; j++) {
|
||||||
|
colors[i][j] = Color.WHITE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.removeMouseListener(this.mouseListener);
|
||||||
|
|
||||||
|
this.mouseListener = new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mousePressed(MouseEvent evt) {
|
||||||
|
int cellWidth = getWidth() / cols;
|
||||||
|
int cellHeight = getHeight() / rows;
|
||||||
|
int col = evt.getX() / cellWidth;
|
||||||
|
int row = evt.getY() / cellHeight;
|
||||||
|
|
||||||
|
if (row >= 0 && row < rows && col >= 0 && col < cols) {
|
||||||
|
if (colors[row][col] == Color.WHITE) {
|
||||||
|
colors[row][col] = Color.GRAY;
|
||||||
|
} else {
|
||||||
|
colors[row][col] = Color.WHITE;
|
||||||
|
}
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseEntered(MouseEvent e) {
|
||||||
|
try {
|
||||||
|
// Charger l'image pour le curseur personnalisé
|
||||||
|
URL url = getClass().getResource("../images/blade.png");
|
||||||
|
BufferedImage cursorImage = ImageIO.read(new File(url.getPath()));
|
||||||
|
// Créer le curseur personnalisé
|
||||||
|
Cursor customCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImage, new Point(0, 0), "customCursor");
|
||||||
|
// Définir le curseur personnalisé
|
||||||
|
setCursor(customCursor);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseExited(MouseEvent e) {
|
||||||
|
setCursor(Cursor.getDefaultCursor()); // Rétablir l'icône de la souris par défaut quand elle quitte le composant
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.addMouseListener(this.mouseListener);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,10 +1,12 @@
|
||||||
package userInterface;
|
package userInterface;
|
||||||
|
|
||||||
|
import universe.*;
|
||||||
|
|
||||||
public class UserInterface extends Thread {
|
public class UserInterface extends Thread {
|
||||||
private Window window;
|
private Window window;
|
||||||
|
|
||||||
public UserInterface() {
|
public UserInterface(Universe universe) {
|
||||||
window = new Window();
|
window = new Window(universe);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
package userInterface;
|
package userInterface;
|
||||||
|
|
||||||
import javax.swing.JButton;
|
|
||||||
import javax.swing.JFrame;
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
|
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.GridBagConstraints;
|
import java.awt.GridBagConstraints;
|
||||||
|
@ -20,35 +16,59 @@ import java.awt.image.BufferedImage;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
import universe.*;
|
||||||
|
|
||||||
public class Window extends JFrame {
|
public class Window extends JFrame {
|
||||||
|
|
||||||
JPanel panel;
|
private JPanel panel;
|
||||||
JMenuBar menuBar;
|
private JMenuBar menuBar;
|
||||||
Grid grid;
|
private Grid grid;
|
||||||
|
private Universe universe;
|
||||||
|
|
||||||
public Window() {
|
public Window(Universe universe) {
|
||||||
super("Laser Finder");
|
super("Laser Finder");
|
||||||
|
|
||||||
|
this.universe = universe;
|
||||||
|
|
||||||
panel = new JPanel();
|
panel = new JPanel();
|
||||||
panel.setPreferredSize(new Dimension(1000,800));
|
panel.setPreferredSize(new Dimension(1000,800));
|
||||||
panel.setBackground(Color.decode("#EBEBD3"));
|
panel.setBackground(Color.decode("#EBEBD3"));
|
||||||
|
|
||||||
|
|
||||||
menuBar = new JMenuBar();
|
menuBar = new JMenuBar();
|
||||||
|
|
||||||
JMenu fichierMenu = new JMenu("Fichier");
|
JMenu fichierMenu = new JMenu("File");
|
||||||
JMenu aideMenu = new JMenu("Aide");
|
JMenu aideMenu = new JMenu("Help");
|
||||||
|
JMenu toolsMenu = new JMenu("Tools");
|
||||||
|
|
||||||
ImageIcon nouveauIcon = new ImageIcon("h:\\Mes documents\\INF1404\\projet\\picture\\nouveau.png");
|
URL newUrl = getClass().getResource("../images/new.png");
|
||||||
ImageIcon openIcon = new ImageIcon("h:\\Mes documents\\INF1404\\projet\\picture\\ouvrir.png");
|
URL openUrl = getClass().getResource("../images/open.png");
|
||||||
ImageIcon saveIcon = new ImageIcon("h:\\Mes documents\\INF1404\\projet\\picture\\sauvegarder.png");
|
URL saveUrl = getClass().getResource("../images/save.png");
|
||||||
|
|
||||||
|
ImageIcon nouveauIcon = new ImageIcon(newUrl.getPath());
|
||||||
|
ImageIcon openIcon = new ImageIcon(openUrl.getPath());
|
||||||
|
ImageIcon saveIcon = new ImageIcon(saveUrl.getPath());
|
||||||
|
|
||||||
JMenuItem nouveauItem = new JMenuItem("Nouveau", nouveauIcon);
|
JMenuItem nouveauItem = new JMenuItem("Nouveau", nouveauIcon);
|
||||||
JMenuItem ouvrirItem = new JMenuItem("Ouvrir", openIcon);
|
JMenuItem ouvrirItem = new JMenuItem("Ouvrir", openIcon);
|
||||||
JMenuItem enregistrerItem = new JMenuItem("Enregistrer", saveIcon);
|
JMenuItem enregistrerItem = new JMenuItem("Enregistrer", saveIcon);
|
||||||
|
|
||||||
JMenuItem apropos = new JMenuItem("à propos");
|
JMenuItem apropos = new JMenuItem("About");
|
||||||
JMenuItem regles = new JMenuItem("règles");
|
JMenuItem regles = new JMenuItem("Rules");
|
||||||
|
|
||||||
|
JRadioButtonMenuItem radioWall = new JRadioButtonMenuItem("Wall");
|
||||||
|
JRadioButtonMenuItem radioStart = new JRadioButtonMenuItem("Start");
|
||||||
|
|
||||||
|
radioWall.setSelected(true);
|
||||||
|
|
||||||
|
ButtonGroup buttonGroup = new ButtonGroup();
|
||||||
|
|
||||||
|
buttonGroup.add(radioWall);
|
||||||
|
buttonGroup.add(radioStart);
|
||||||
|
|
||||||
|
JMenuItem changeSize = new JMenuItem("Change Size");
|
||||||
|
JMenuItem solve = new JMenuItem("Solve");
|
||||||
|
|
||||||
fichierMenu.add(nouveauItem);
|
fichierMenu.add(nouveauItem);
|
||||||
fichierMenu.add(ouvrirItem);
|
fichierMenu.add(ouvrirItem);
|
||||||
|
@ -57,16 +77,32 @@ public class Window extends JFrame {
|
||||||
aideMenu.add(apropos);
|
aideMenu.add(apropos);
|
||||||
aideMenu.add(regles);
|
aideMenu.add(regles);
|
||||||
|
|
||||||
|
toolsMenu.add(radioWall);
|
||||||
|
toolsMenu.add(radioStart);
|
||||||
|
toolsMenu.addSeparator();
|
||||||
|
toolsMenu.add(changeSize);
|
||||||
|
toolsMenu.addSeparator();
|
||||||
|
toolsMenu.add(solve);
|
||||||
|
|
||||||
menuBar.add(fichierMenu);
|
menuBar.add(fichierMenu);
|
||||||
menuBar.add(aideMenu);
|
menuBar.add(aideMenu);
|
||||||
|
menuBar.add(toolsMenu);
|
||||||
|
|
||||||
|
|
||||||
regles.addActionListener(e -> {
|
regles.addActionListener(e -> {
|
||||||
JOptionPane.showMessageDialog(this, "Définissez la taille du plateau ainsi que l'orientation du laser, enfin ajoutez des obstacles et laissez le programme trouver le bon chemin !");
|
JOptionPane.showMessageDialog(this, "Définissez la taille du plateau ainsi que l'orientation du laser, enfin ajoutez des obstacles et laissez le programme trouver le bon chemin !");
|
||||||
});
|
});
|
||||||
|
|
||||||
grid = new Grid(5, 5);
|
changeSize.addActionListener(e -> {
|
||||||
panel.add(grid, BorderLayout.CENTER);
|
int width = Integer.valueOf(JOptionPane.showInputDialog("Choose the width"));
|
||||||
|
int height = Integer.valueOf(JOptionPane.showInputDialog("Choose the height"));
|
||||||
|
|
||||||
|
this.grid.changeDim(width, height);
|
||||||
|
this.grid.repaint();
|
||||||
|
});
|
||||||
|
|
||||||
|
this.grid = new Grid(this.universe.getHeight() - 2, this.universe.getWidth() - 2);
|
||||||
|
this.panel.add(grid, BorderLayout.CENTER);
|
||||||
|
|
||||||
super.setJMenuBar(menuBar);
|
super.setJMenuBar(menuBar);
|
||||||
super.setContentPane(this.panel);
|
super.setContentPane(this.panel);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue