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);
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)