* default with 60,60,15 labyrinth

* display labyrinth at re-recreation.
* save only labyrinth view ( png without background ).
This commit is contained in:
philippe lhardy
2017-11-18 21:44:01 +01:00
parent 65b9fb31dd
commit 2e5095372a
2 changed files with 30 additions and 20 deletions

View File

@@ -56,7 +56,7 @@ public class Display extends JFrame
LabyModel model;
JPanel controlPanel;
boolean autoSize;
// MazeParamsFixed fixedParams = null;
MazeParams params = null;
Display(LabyModel model,int W, int H, MazeParams params)
@@ -100,8 +100,7 @@ public class Display extends JFrame
void recreateModel()
{
// recreate labyrinth TODO / FIXME
System.out.println("TODO recreateModel");
// recreate labyrinth
if (params != null)
{
params = controler.getSettings().getParams();
@@ -109,9 +108,14 @@ public class Display extends JFrame
maze.resetWallsProvider(model);
model.setMazeListener(maze);
model.generateWithEntry(0, 0);
model.addEntryOrExit(-1, 0);
model.addEntryOrExit(params.getWidth(), params.getHeight() - 1);
// we are in GUI event thread, need to release it and do it outside.
new Thread() {
public void run() {
model.generateWithEntry(0, 0);
model.addEntryOrExit(-1, 0);
model.addEntryOrExit(params.getWidth(), params.getHeight() - 1);
}
}.start();
}
}
@@ -158,9 +162,11 @@ public class Display extends JFrame
void savePng()
{
File file = new File("snapshot.png");
BufferedImage bi = new BufferedImage(this.getSize().width, this.getSize().height, BufferedImage.TYPE_INT_ARGB);
// BufferedImage bi = new BufferedImage(this.getSize().width, this.getSize().height, BufferedImage.TYPE_INT_ARGB);
BufferedImage bi = new BufferedImage(maze.getSize().width, maze.getSize().height, BufferedImage.TYPE_INT_ARGB);
Graphics g = bi.createGraphics();
this.paint(g);
// this.paint(g);
maze.paint(g);
g.dispose();
try{
ImageIO.write(bi,"png",file);
@@ -187,15 +193,18 @@ public class Display extends JFrame
void createSettingsGui()
{
JButton buttonCreate = new JButton(labels.getString("create"));
buttonCreate.addActionListener(new ActionListener()
if ( params != null )
{
public void actionPerformed(ActionEvent evt)
{
recreateModel();
}
});
add(buttonCreate);
JButton buttonCreate = new JButton(labels.getString("create"));
buttonCreate.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
recreateModel();
}
});
add(buttonCreate);
}
if ( params != null )
{
JLabel widthLabel = new JLabel(labels.getString("width"));
@@ -223,7 +232,7 @@ public class Display extends JFrame
}
private class MazeParamsFixed implements MazeParams
private static class MazeParamsFixed implements MazeParams
{
int width;
int height;
@@ -848,9 +857,7 @@ public class Display extends JFrame
}
else
{
System.out.println("enter width height and maxdepth");
MazeParamEditor params = new MazeParamEditor(new File("lab"));
params.read(new Scanner(System.in));
MazeParamsFixed params = new MazeParamsFixed(new File("lab"),60,60,15);
model = new LabyModel(params, new java.util.Random());
setupDisplay(model,W,H,params);