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 userInterface.UserInterface;
|
||||
import universe.*;
|
||||
import universe.Universe;
|
||||
import universe.Stack;
|
||||
import universe.Situation;
|
||||
|
||||
public class AppLaser {
|
||||
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 == 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) {
|
||||
|
||||
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);
|
||||
|
||||
int choice;
|
||||
|
@ -315,7 +316,7 @@ public class AppLaser {
|
|||
} while (choice != 0);
|
||||
}
|
||||
else {
|
||||
UserInterface userInterface= new UserInterface();
|
||||
UserInterface userInterface = new UserInterface(universe);
|
||||
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:
|
||||
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
|
||||
jar cfe AppLaser.jar AppLaser *.class
|
||||
|
||||
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
|
||||
java AppLaser -cli --optimize-duration
|
||||
|
||||
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
|
||||
java AppLaser
|
||||
|
|
|
@ -381,4 +381,12 @@ public class Universe {
|
|||
public int[][] copyGrid() {
|
||||
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 javax.imageio.ImageIO;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
public class Grid extends JPanel {
|
||||
private int rows;
|
||||
private int cols;
|
||||
private Color[][] colors;
|
||||
private MouseAdapter mouseListener;
|
||||
|
||||
public Grid(int rows, int cols) {
|
||||
this.rows = rows;
|
||||
this.cols = cols;
|
||||
setPreferredSize(new Dimension(400, 400));
|
||||
setBackground(Color.WHITE);
|
||||
this.setPreferredSize(new Dimension(400, 400));
|
||||
this.setBackground(Color.WHITE);
|
||||
|
||||
colors = new Color[rows][cols];
|
||||
for (int i = 0; i < rows; i++) {
|
||||
|
@ -38,7 +41,7 @@ public class Grid extends JPanel {
|
|||
}
|
||||
}
|
||||
|
||||
addMouseListener(new MouseAdapter() {
|
||||
mouseListener = new MouseAdapter() {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent evt) {
|
||||
int cellWidth = getWidth() / cols;
|
||||
|
@ -48,7 +51,7 @@ public class Grid extends JPanel {
|
|||
|
||||
if (row >= 0 && row < rows && col >= 0 && col < cols) {
|
||||
if (colors[row][col] == Color.WHITE) {
|
||||
colors[row][col] = Color.RED;
|
||||
colors[row][col] = Color.GRAY;
|
||||
} else {
|
||||
colors[row][col] = Color.WHITE;
|
||||
}
|
||||
|
@ -60,7 +63,8 @@ public class Grid extends JPanel {
|
|||
public void mouseEntered(MouseEvent e) {
|
||||
try {
|
||||
// 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é
|
||||
Cursor customCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImage, new Point(0, 0), "customCursor");
|
||||
// Définir le curseur personnalisé
|
||||
|
@ -74,18 +78,20 @@ public class Grid extends JPanel {
|
|||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
int cellWidth = getWidth() / cols;
|
||||
int cellHeight = getHeight() / rows;
|
||||
int cellWidth = this.getWidth() / this.cols;
|
||||
int cellHeight = this.getHeight() / this.rows;
|
||||
|
||||
// Dessiner les cases avec les couleurs stockées
|
||||
for (int i = 0; i < rows; i++) {
|
||||
for (int j = 0; j < cols; j++) {
|
||||
for (int i = 0; i < this.rows; i++) {
|
||||
for (int j = 0; j < this.cols; j++) {
|
||||
g.setColor(colors[i][j]);
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
import universe.*;
|
||||
|
||||
public class UserInterface extends Thread {
|
||||
private Window window;
|
||||
|
||||
public UserInterface() {
|
||||
window = new Window();
|
||||
public UserInterface(Universe universe) {
|
||||
window = new Window(universe);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
package userInterface;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Color;
|
||||
import java.awt.GridBagConstraints;
|
||||
|
@ -20,35 +16,59 @@ import java.awt.image.BufferedImage;
|
|||
import java.io.File;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import universe.*;
|
||||
|
||||
public class Window extends JFrame {
|
||||
|
||||
JPanel panel;
|
||||
JMenuBar menuBar;
|
||||
Grid grid;
|
||||
private JPanel panel;
|
||||
private JMenuBar menuBar;
|
||||
private Grid grid;
|
||||
private Universe universe;
|
||||
|
||||
public Window() {
|
||||
public Window(Universe universe) {
|
||||
super("Laser Finder");
|
||||
|
||||
this.universe = universe;
|
||||
|
||||
panel = new JPanel();
|
||||
panel.setPreferredSize(new Dimension(1000,800));
|
||||
panel.setBackground(Color.decode("#EBEBD3"));
|
||||
|
||||
|
||||
menuBar = new JMenuBar();
|
||||
|
||||
JMenu fichierMenu = new JMenu("Fichier");
|
||||
JMenu aideMenu = new JMenu("Aide");
|
||||
JMenu fichierMenu = new JMenu("File");
|
||||
JMenu aideMenu = new JMenu("Help");
|
||||
JMenu toolsMenu = new JMenu("Tools");
|
||||
|
||||
URL newUrl = getClass().getResource("../images/new.png");
|
||||
URL openUrl = getClass().getResource("../images/open.png");
|
||||
URL saveUrl = getClass().getResource("../images/save.png");
|
||||
|
||||
ImageIcon nouveauIcon = new ImageIcon("h:\\Mes documents\\INF1404\\projet\\picture\\nouveau.png");
|
||||
ImageIcon openIcon = new ImageIcon("h:\\Mes documents\\INF1404\\projet\\picture\\ouvrir.png");
|
||||
ImageIcon saveIcon = new ImageIcon("h:\\Mes documents\\INF1404\\projet\\picture\\sauvegarder.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 ouvrirItem = new JMenuItem("Ouvrir", openIcon);
|
||||
JMenuItem enregistrerItem = new JMenuItem("Enregistrer", saveIcon);
|
||||
|
||||
JMenuItem apropos = new JMenuItem("à propos");
|
||||
JMenuItem regles = new JMenuItem("règles");
|
||||
JMenuItem apropos = new JMenuItem("About");
|
||||
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(ouvrirItem);
|
||||
|
@ -57,16 +77,32 @@ public class Window extends JFrame {
|
|||
aideMenu.add(apropos);
|
||||
aideMenu.add(regles);
|
||||
|
||||
toolsMenu.add(radioWall);
|
||||
toolsMenu.add(radioStart);
|
||||
toolsMenu.addSeparator();
|
||||
toolsMenu.add(changeSize);
|
||||
toolsMenu.addSeparator();
|
||||
toolsMenu.add(solve);
|
||||
|
||||
menuBar.add(fichierMenu);
|
||||
menuBar.add(aideMenu);
|
||||
menuBar.add(toolsMenu);
|
||||
|
||||
|
||||
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 !");
|
||||
});
|
||||
|
||||
changeSize.addActionListener(e -> {
|
||||
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();
|
||||
});
|
||||
|
||||
grid = new Grid(5, 5);
|
||||
panel.add(grid, BorderLayout.CENTER);
|
||||
this.grid = new Grid(this.universe.getHeight() - 2, this.universe.getWidth() - 2);
|
||||
this.panel.add(grid, BorderLayout.CENTER);
|
||||
|
||||
super.setJMenuBar(menuBar);
|
||||
super.setContentPane(this.panel);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue