create new maze with a given size

- fixme ratio paramaters are not reset.
This commit is contained in:
philippe lhardy
2017-11-16 22:30:21 +01:00
parent 50bad7a474
commit e429919005

View File

@@ -65,7 +65,7 @@ public class Display extends JFrame
maze = createMazeComponent(model,W,H); maze = createMazeComponent(model,W,H);
Container con = this.getContentPane(); Container con = this.getContentPane();
con.add(new JScrollPane(maze), BorderLayout.CENTER); con.add(new JScrollPane(maze), BorderLayout.CENTER);
controler = new MazeControler(); controler = new MazeControler(params);
con.add(controler.getMoveControl(), BorderLayout.NORTH); con.add(controler.getMoveControl(), BorderLayout.NORTH);
con.add(controler.getGenerationControl(), BorderLayout.SOUTH); con.add(controler.getGenerationControl(), BorderLayout.SOUTH);
@@ -98,6 +98,7 @@ public class Display extends JFrame
System.out.println("TODO recreateModel"); System.out.println("TODO recreateModel");
if (params != null) if (params != null)
{ {
params = controler.getSettings().getParams();
model = new LabyModel(params, new java.util.Random()); model = new LabyModel(params, new java.util.Random());
maze.resetWallsProvider(model); maze.resetWallsProvider(model);
model.setMazeListener(maze); model.setMazeListener(maze);
@@ -164,17 +165,17 @@ public class Display extends JFrame
private class MazeSettings extends JPanel private class MazeSettings extends JPanel
{ {
MazeParamsFixed params; MazeParams params;
JTextField textWidth = null; JTextField textWidth = null;
JTextField textHeight = null; JTextField textHeight = null;
JTextField textDepth = null; JTextField textDepth = null;
// TODO set width and height and depth of maze with gui // TODO set width and height and depth of maze with gui
public MazeSettings() public MazeSettings(MazeParams params)
{ {
super(); super();
params = new MazeParamsFixed(); this.params = params;
createSettingsGui(); createSettingsGui();
} }
@@ -190,20 +191,26 @@ public class Display extends JFrame
}); });
add(buttonCreate); add(buttonCreate);
JLabel widthLabel = new JLabel("width"); JLabel widthLabel = new JLabel("width");
textWidth = new JTextField("010"); textWidth = new JTextField("0" + params.getWidth());
add(widthLabel); add(widthLabel);
add(textWidth); add(textWidth);
JLabel heightLabel = new JLabel("height"); JLabel heightLabel = new JLabel("height");
textHeight = new JTextField("010"); textHeight = new JTextField("0" + params.getHeight());
add(heightLabel); add(heightLabel);
add(textHeight); add(textHeight);
JLabel depthLabel = new JLabel("depth"); JLabel depthLabel = new JLabel("depth");
textDepth = new JTextField("015"); textDepth = new JTextField("0" + params.getMaxDepth());
add(depthLabel); add(depthLabel);
add(textDepth); add(textDepth);
} }
public MazeParams getParams()
{
return new MazeParamsFixed(params.getSaveDir(),
Integer.parseInt(textWidth.getText()),
Integer.parseInt(textHeight.getText()),
Integer.parseInt(textDepth.getText()));
}
} }
@@ -219,6 +226,11 @@ public class Display extends JFrame
{ {
} }
public MazeParamsFixed(MazeParams params)
{
setParams(params.getSaveDir(),params.getWidth(),params.getHeight(),params.getMaxDepth());
}
public void setParams(File saveDir, int W, int H, int MD) public void setParams(File saveDir, int W, int H, int MD)
{ {
labdir = saveDir; labdir = saveDir;
@@ -274,10 +286,10 @@ public class Display extends JFrame
private MazeSettings settings = null; private MazeSettings settings = null;
public MazeControler() public MazeControler(MazeParams params)
{ {
controlPanel = new JPanel(); controlPanel = new JPanel();
settings = new MazeSettings(); settings = new MazeSettings(params);
JButton button = new JButton("Resolve"); JButton button = new JButton("Resolve");
button.addActionListener(new ActionListener() button.addActionListener(new ActionListener()
{ {
@@ -378,7 +390,6 @@ public class Display extends JFrame
controlDisplayPanel.add(autoSlide, BorderLayout.EAST); controlDisplayPanel.add(autoSlide, BorderLayout.EAST);
controlDisplayPanel.add(savePngButton, BorderLayout.SOUTH); controlDisplayPanel.add(savePngButton, BorderLayout.SOUTH);
add(controlDisplayPanel, BorderLayout.SOUTH); add(controlDisplayPanel, BorderLayout.SOUTH);
add(settings,BorderLayout.EAST); add(settings,BorderLayout.EAST);
} }
@@ -393,6 +404,11 @@ public class Display extends JFrame
return settings; return settings;
} }
public MazeSettings getSettings()
{
return settings;
}
} }
private JButton addDirection(final JPanel panel, final String direction, String key, Action goAction) private JButton addDirection(final JPanel panel, final String direction, String key, Action goAction)