From e42991900526ea380d0b4c61cab13fa20a0f5e7f Mon Sep 17 00:00:00 2001 From: philippe lhardy Date: Thu, 16 Nov 2017 22:30:21 +0100 Subject: [PATCH] create new maze with a given size - fixme ratio paramaters are not reset. --- java/org/artisanlogiciel/games/Display.java | 42 ++++++++++++++------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/java/org/artisanlogiciel/games/Display.java b/java/org/artisanlogiciel/games/Display.java index 562a512..ae0e3bc 100644 --- a/java/org/artisanlogiciel/games/Display.java +++ b/java/org/artisanlogiciel/games/Display.java @@ -65,7 +65,7 @@ public class Display extends JFrame maze = createMazeComponent(model,W,H); Container con = this.getContentPane(); con.add(new JScrollPane(maze), BorderLayout.CENTER); - controler = new MazeControler(); + controler = new MazeControler(params); con.add(controler.getMoveControl(), BorderLayout.NORTH); con.add(controler.getGenerationControl(), BorderLayout.SOUTH); @@ -98,6 +98,7 @@ public class Display extends JFrame System.out.println("TODO recreateModel"); if (params != null) { + params = controler.getSettings().getParams(); model = new LabyModel(params, new java.util.Random()); maze.resetWallsProvider(model); model.setMazeListener(maze); @@ -164,17 +165,17 @@ public class Display extends JFrame private class MazeSettings extends JPanel { - MazeParamsFixed params; + MazeParams params; JTextField textWidth = null; JTextField textHeight = null; JTextField textDepth = null; // TODO set width and height and depth of maze with gui - public MazeSettings() + public MazeSettings(MazeParams params) { super(); - params = new MazeParamsFixed(); + this.params = params; createSettingsGui(); } @@ -190,20 +191,26 @@ public class Display extends JFrame }); add(buttonCreate); JLabel widthLabel = new JLabel("width"); - textWidth = new JTextField("010"); + textWidth = new JTextField("0" + params.getWidth()); add(widthLabel); add(textWidth); JLabel heightLabel = new JLabel("height"); - textHeight = new JTextField("010"); + textHeight = new JTextField("0" + params.getHeight()); add(heightLabel); add(textHeight); JLabel depthLabel = new JLabel("depth"); - textDepth = new JTextField("015"); + textDepth = new JTextField("0" + params.getMaxDepth()); add(depthLabel); add(textDepth); } - + public MazeParams getParams() + { + return new MazeParamsFixed(params.getSaveDir(), + Integer.parseInt(textWidth.getText()), + Integer.parseInt(textHeight.getText()), + Integer.parseInt(textDepth.getText())); + } } @@ -218,7 +225,12 @@ public class Display extends JFrame public MazeParamsFixed() { } - + + public MazeParamsFixed(MazeParams params) + { + setParams(params.getSaveDir(),params.getWidth(),params.getHeight(),params.getMaxDepth()); + } + public void setParams(File saveDir, int W, int H, int MD) { labdir = saveDir; @@ -274,10 +286,10 @@ public class Display extends JFrame private MazeSettings settings = null; - public MazeControler() + public MazeControler(MazeParams params) { controlPanel = new JPanel(); - settings = new MazeSettings(); + settings = new MazeSettings(params); JButton button = new JButton("Resolve"); button.addActionListener(new ActionListener() { @@ -376,8 +388,7 @@ public class Display extends JFrame savePngButton.addActionListener(savePngAction); controlDisplayPanel.add(slider, BorderLayout.WEST); controlDisplayPanel.add(autoSlide, BorderLayout.EAST); - controlDisplayPanel.add(savePngButton, BorderLayout.SOUTH); - + controlDisplayPanel.add(savePngButton, BorderLayout.SOUTH); add(controlDisplayPanel, BorderLayout.SOUTH); add(settings,BorderLayout.EAST); @@ -393,6 +404,11 @@ public class Display extends JFrame return settings; } + public MazeSettings getSettings() + { + return settings; + } + } private JButton addDirection(final JPanel panel, final String direction, String key, Action goAction)