From 29ce62150e0542675cd770160760881c63a567e9 Mon Sep 17 00:00:00 2001 From: Ninja-Jambon Date: Wed, 27 Mar 2024 11:54:38 +0100 Subject: [PATCH] commit --- AppLaser.java | 15 +++--- images/blade.png | Bin 0 -> 1610 bytes images/new.png | Bin 0 -> 861 bytes images/open.png | Bin 0 -> 621 bytes images/save.png | Bin 0 -> 720 bytes makefile | 6 +++ universe/Universe.java | 8 +++ userInterface/Grid.java | 83 +++++++++++++++++++++++++++---- userInterface/UserInterface.java | 6 ++- userInterface/Window.java | 72 ++++++++++++++++++++------- 10 files changed, 153 insertions(+), 37 deletions(-) create mode 100644 images/blade.png create mode 100644 images/new.png create mode 100644 images/open.png create mode 100644 images/save.png diff --git a/AppLaser.java b/AppLaser.java index 7209609..b37f5c2 100644 --- a/AppLaser.java +++ b/AppLaser.java @@ -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 stack = new Stack (); + 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 stack = new Stack (); - 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(); } } diff --git a/images/blade.png b/images/blade.png new file mode 100644 index 0000000000000000000000000000000000000000..4ffe69a49d6b0550eff55f48ce541de5e64dcf3d GIT binary patch literal 1610 zcmZ{kdo&by6vuyR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?o@k&uHzV}n zhWj&8A{$**e|G5dPIH)Qe)wTE)91oFo0Efm(VGPs7ab=LMWlUc?~BqteV#z7yTo)3 zJg>d*gM=#8_Rki(>*=xvar1GPl^!bY=#xtB^^nvDCU*UFi(QK{?CuQc$ z4B9x)YSh~UD}}C?QTJ#mS*&%reo@OVq|IVP)}JV~A?(x*x&KA~bS(Pdnwn&VQ?yRU z(q1`@Z6hO91FDjV^Yh{qrtjxDq(Q>D6CpO_WA%O4yKwL&L2tQ2z^;JVj@SKdukN0p zooHWNoTc#=Wxua48oArs!MK(Ox;jk?UsuXAl4E>a?CXooFI(~X6YXGmwp`xbBP-rEl<%4>c;6ZvE!2 zpw330j}tyhE4XRiaziF}B8<1HLcW+!xI3;|SLVfXa2+aga{N?U>J{y|6s>c^6)iW4 zZ7z1jbIs4B*$N~`S=Tp#4oaB|0IplKF6F6SqyT4UU?_U;5XIIRa@$&@x^$u!{fsZ2 ziuDhtiUgP-Oi;!MQ)3fzcO(L9hQuN*4k8d(1VS$?0{Sl?IP^?lK+OLGo<@BYBEaCE i3G~2VY6RUknD$@B1oQV01HoIkhyf%bnNV#@N&X8cow)u0 literal 0 HcmV?d00001 diff --git a/images/new.png b/images/new.png new file mode 100644 index 0000000000000000000000000000000000000000..4d78a597bfc8fa5e49b0bfd4673d6c0aa685ad80 GIT binary patch literal 861 zcmeAS@N?(olHy`uVBq!ia0vp^A|TAc3?z4jzqJQa3dtTpz6=aiY77hwEes65fIfvhiX>JY z*wwP9%}n%kxRUK%H35Z_Zysiu20m!Fk&JR(>+8LBUGndjAreMKOMvDwCV9KNggjyH zSPJB@mw5WRvcF&!;j~Z|F{}>+3hniDaSV~ToScx5kd~Or%p6w6=cmWU=H|x6mM0fy zS0^AKAR;6t$l7US(9!8_;LxyS%9frrGU6SYYI^)v7+H9@g1Wp;X{}n(l=Vt#R@5!4 zI~q+qyQ+Q_v9)D1DI}!yC~-_QRCE^LF<`msbJl=W^o*`T*F+ZGwQIiS<^-~+zIkIB zAuBUCAas@G?j5^!Rxik8Z);V*;iJ}4rttFV!G<@!d2;#kjEwOLY>amH^`;YI7`zp< zWmwo)je#la`#PzK)4sL00zINy;u=wsl30>zm0Xkxq!^40j7)S5jCG9+LJTaeOwFte zO|=aStPBjCB&9r1H00)|WTsW()?nOVmnQ!hm}C fQX@Rme0>?TfNTyR27yb#lR=cHtDnm{r-UW|FV@-L literal 0 HcmV?d00001 diff --git a/images/open.png b/images/open.png new file mode 100644 index 0000000000000000000000000000000000000000..153e75ba3f891c4116072b8fe31b6fe9867fb9ed GIT binary patch literal 621 zcmeAS@N?(olHy`uVBq!ia0vp^A|TAc0wmQNuC@Uwg=CK)Uj~LMH3o);76yi2K%s^g z3=E|P3=FRl7#OT(FffQ0%-I!a1C(G&@^*J&_}|`tWO>_3^e&V2s1iq%&q_m zvX^-Jy0X7u7U8rqyt*%EHc;rVr;B5V#`)fh_WI3%BF8`a=g%)u2<4m_uyFO!q>oH{ zM7D0|Jo!%5aUb^M@&&;Bxo^^8g}}nzxGa}g`GZT6ZoO%n zb(QzjqU$^b2a7kXSUZ_fFO%i8oRN5Jp)^amWJHpiaz9gP2NC6e` frABzB`T8O>_%)lV(0K$w`{*CrP zLG}_)Usv`Q%pzP2a*+*&j~Eyj6FglULp09!UNX!UaTH;AkpJx&i}coQ7dSXOqHa|9 zy8Lfw&D^qK+oe-RtxGxFw`{)P#VsxE$`Pfi5I0d^qsS474Hu0UIZesQ+nhb|?&&+O zN48%*^ZVJ}+RdkXD$ncO`fz!gRwdWeL(c4tmCv`#{d!}IIA`^vMbE>|zO-^!wjo8~ z`uC{&d0%X{rks|2oo6*=C5yn86wWgfIE#v}mCg=1u+6A(tyCJYJUH>AWMX8XJ7Q!r{>J(q)fVJY$22FZYBGH%}|_ME!VlB<{qr_0BV@Qzzf$3tV9zoq6i(!}(wCTF;-fag)ZY7n$7m zc1&7Q^jq{>X17(6!Q)kpoJ+S(4CL@~ca`62`-A!RwA?j$5xqIU;8!hijVMV;EJ?LW zE=mPb3`Pbeh6Yv!23AI<+Cb94V3n&DFp7~h! z+=i0O+|=Td#M}Z*J;nwQON8dn$pY$;1nCLRPb(=;EJ|f4FE7{2%*!rLPAo{(%P&fw m{mw=TsE98$!ZXd+mq822<^W<4xD-4YM0vXUxvX= 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); + } } \ No newline at end of file diff --git a/userInterface/UserInterface.java b/userInterface/UserInterface.java index b1c4614..c91cd08 100644 --- a/userInterface/UserInterface.java +++ b/userInterface/UserInterface.java @@ -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() { diff --git a/userInterface/Window.java b/userInterface/Window.java index c1649c9..33d8f8f 100644 --- a/userInterface/Window.java +++ b/userInterface/Window.java @@ -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);