diff --git a/build.xml b/build.xml index 34d7b55..2140eab 100644 --- a/build.xml +++ b/build.xml @@ -1,4 +1,4 @@ - + simple example build file diff --git a/java/org/artisanlogiciel/games/Display.java b/java/org/artisanlogiciel/games/Display.java index effe374..722c7bd 100644 --- a/java/org/artisanlogiciel/games/Display.java +++ b/java/org/artisanlogiciel/games/Display.java @@ -36,7 +36,7 @@ import javax.swing.event.ChangeListener; import org.artisanlogiciel.games.stl.Wall3d; /** - * Display + * Display is Main JFrame for this tool **/ public class Display extends JFrame { @@ -48,14 +48,21 @@ public class Display extends JFrame LabyModel model; JPanel controlPanel; boolean autoSize; - - Display(LabyModel model, MazeComponent comp) + // MazeParamsFixed fixedParams = null; + MazeParams params = null; + + Display(LabyModel model,int W, int H, MazeParams params) { super("Maze display"); - maze = comp; - this.model = model; + if (params != null) + { + // fixedParams = new MazeParamsFixed(params.getSaveDir(),params.getWidth(),params.getHeight(),params.getMaxDepth()); + this.params = params; + } + this.model = model; + maze = createMazeComponent(model,W,H); Container con = this.getContentPane(); - con.add(new JScrollPane(comp), BorderLayout.CENTER); + con.add(new JScrollPane(maze), BorderLayout.CENTER); controler = new MazeControler(); con.add(controler, BorderLayout.NORTH); @@ -68,6 +75,35 @@ public class Display extends JFrame } } }); + + model.setMazeListener(maze); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setBounds(W, H, W, H); + setVisible(true); + } + + private static MazeComponent createMazeComponent(LabyModel model, int W, int H) + { + MazeCellParameters cp = new MazeCellParameters(model.getWidth(),model.getHeight(), W, H, 3, 3); + MazeComponent comp = new MazeComponent(model, cp); + return comp; + } + + void recreateModel() + { + // recreate labyrinth TODO / FIXME + System.out.println("TODO recreateModel"); + if (params != null) + { + model = new LabyModel(params, new java.util.Random()); + maze.resetWallsProvider(model); + model.setMazeListener(maze); + + model.generateWithEntry(0, 0); + model.addEntryOrExit(-1, 0); + model.addEntryOrExit(params.getWidth(), params.getHeight() - 1); + + } } void resolve() @@ -126,8 +162,76 @@ public class Display extends JFrame private class MazeSettings extends JPanel { // TODO set width and height and depth of maze with gui + public MazeSettings() + { + super(); + createSettingsGui(); + } + + void createSettingsGui() + { + JButton buttonCreate = new JButton("Create"); + buttonCreate.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent evt) + { + recreateModel(); + } + }); + add(buttonCreate,BorderLayout.CENTER); + } + } + + private class MazeParamsFixed implements MazeParams + { + int width; + int height; + int maxdepth; + File labdir; + String name; + + public MazeParamsFixed(File saveDir, int W, int H, int MD) + { + name = null; + labdir = saveDir; + width=W; + height=H; + maxdepth=MD; + } + + public int getWidth() + { + return width; + } + + public int getHeight() + { + return height; + } + + public int getMaxDepth() + { + return maxdepth; + } + + public String getName() + { + if (name == null) + { + name = "lab" + width + "x" + height; + } + return name; + } + + public File getSaveDir() + { + return labdir; + } + } + + private class MazeControler extends JPanel { /** @@ -137,6 +241,8 @@ public class Display extends JFrame public MazeControler() { + MazeSettings settings = new MazeSettings(); + controlPanel = new JPanel(); JButton button = new JButton("Resolve"); button.addActionListener(new ActionListener() @@ -240,6 +346,7 @@ public class Display extends JFrame add(controlDisplayPanel, BorderLayout.SOUTH); + add(settings,BorderLayout.EAST); } } @@ -463,6 +570,14 @@ public class Display extends JFrame gY = map.getHeight() - 1; } + /** + warning works only if new map has same dimensions than previous + */ + public void resetWallsProvider(WallsProvider map) + { + this.map = map; + } + public void setWallSize(int size) { cp.setCellSize((double) size,(double) size); @@ -616,16 +731,9 @@ public class Display extends JFrame } } - private static MazeComponent setupDisplay(LabyModel model, int W, int H) + private static void setupDisplay(LabyModel model, int W, int H, MazeParams params) { - MazeCellParameters cp = new MazeCellParameters(model.getWidth(),model.getHeight(), W, H, 3, 3); - MazeComponent comp = new MazeComponent(model, cp); - Display display = new Display(model, comp); - model.setMazeListener(comp); - display.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - display.setBounds(W, H, W, H); - display.setVisible(true); - return comp; + Display display = new Display(model, W,H,params); } public static void main(String pArgs[]) @@ -646,7 +754,7 @@ public class Display extends JFrame System.exit(1); } - setupDisplay(model, W,H); + setupDisplay(model, W,H,null); } else { @@ -655,7 +763,7 @@ public class Display extends JFrame params.read(new Scanner(System.in)); model = new LabyModel(params, new java.util.Random()); - setupDisplay(model,W,H); + setupDisplay(model,W,H,params); model.generateWithEntry(0, 0);