diff --git a/java/org/artisanlogiciel/games/maze/LabyLayers.java b/java/org/artisanlogiciel/games/maze/LabyLayers.java new file mode 100644 index 0000000..6c3178c --- /dev/null +++ b/java/org/artisanlogiciel/games/maze/LabyLayers.java @@ -0,0 +1,25 @@ +package org.artisanlogiciel.games.maze; + +import org.artisanlogiciel.games.minetest.Range; + +import java.util.HashMap; + +public class LabyLayers +extends Range +{ + HashMap layers = new HashMap<>(); + + public LabyLayers() + { + super(); + } + public void addLabyModel(int z, LabyModel model) + { + layers.put(new Integer(z), model); + } + + public LabyModel getLayer(int z) + { + return layers.get(new Integer(z)); + } +} diff --git a/java/org/artisanlogiciel/games/maze/LabyModel.java b/java/org/artisanlogiciel/games/maze/LabyModel.java index 358fd1a..1bb4ec3 100644 --- a/java/org/artisanlogiciel/games/maze/LabyModel.java +++ b/java/org/artisanlogiciel/games/maze/LabyModel.java @@ -85,6 +85,8 @@ public class LabyModel implements WallsProvider { MazeCreationListener listener = null; + // do we create wall when only one way is possible ? + private boolean onewaywall = false; private LabyModel(int width, int height, int maxdepth, Random random) { this.width = width; @@ -713,17 +715,23 @@ public class LabyModel implements WallsProvider { int reversedirection = 0; // is this direction on the path ? yes => no wall - if ((t[x][y] & direction) == direction) { - return false; + if ( isFlagSet(t[x][y], direction)) { + if (!onewaywall) { + return false; + } + // onewaywall : should check reverse direction is ok too. + } + else + { + if (onewaywall) + { + return true; + } } // is adjacent tile in direction pointing in reverse direction ? yes => // no wall - if ((direction & POSITIVE) == POSITIVE) { - delta = 1; - } else { - delta = -1; - } + delta = ((direction & POSITIVE) == POSITIVE) ? 1 : -1; if ((direction & HORIZONTAL) == HORIZONTAL) { newx = x + delta; @@ -736,7 +744,7 @@ public class LabyModel implements WallsProvider { } if ((newx >= 0) && (newy >= 0) && (newx < width) && (newy < height)) { - return !isFlagSet(t[newx][newy], (short) reversedirection); + return ! isFlagSet(t[newx][newy], (short) reversedirection); } else { // outside boundaries. // TODO CHECK exits. @@ -744,13 +752,16 @@ public class LabyModel implements WallsProvider { } } + public void setOnewaywall(boolean onewaywall) { + this.onewaywall = onewaywall; + } + /** * is there no wall in that direction ? **/ public boolean canMoveInDirection(int x, int y, short direction) { - // tried to replace by but does not work ( can't go back ...). - // return ! hasWallInDirection(x,y, (short) (direction << FLAGLENGTH)); - return ((getWalls(x, y) & direction ) == 0); + // one way wall will create walll if it not possible to step back to current position from next position + return onewaywall ? ( ! hasWallInDirection(x,y, (short) (direction << FLAGLENGTH)) ) : ((getWalls(x, y) & direction ) == 0); } } diff --git a/java/org/artisanlogiciel/games/maze/gui/Display.java b/java/org/artisanlogiciel/games/maze/gui/Display.java index c4a81e4..9474d84 100644 --- a/java/org/artisanlogiciel/games/maze/gui/Display.java +++ b/java/org/artisanlogiciel/games/maze/gui/Display.java @@ -1,9 +1,6 @@ package org.artisanlogiciel.games.maze.gui; -import org.artisanlogiciel.games.maze.DrawingGenerator; -import org.artisanlogiciel.games.maze.LabyModel; -import org.artisanlogiciel.games.maze.MazeParams; -import org.artisanlogiciel.games.maze.MazeParamsFixed; +import org.artisanlogiciel.games.maze.*; import org.artisanlogiciel.games.maze.persist.MazePersistWorldEdit; import org.artisanlogiciel.games.maze.persist.MazePersistRaw; import org.artisanlogiciel.games.maze.solve.SolvingModel; @@ -40,6 +37,9 @@ implements StatusListener public final static ResourceBundle labels = ResourceBundle.getBundle("LabelsBundle", Locale.getDefault(), Display.class.getClassLoader(), new UTF8Control()); + LabyLayers layers = new LabyLayers(); + int layer = 0; + MazeComponent maze; MazeControler controler; LabyModel model; @@ -110,12 +110,17 @@ implements StatusListener } } + void setModel( LabyModel model) + { + this.model = model; + layers.addLabyModel(layer, model); + } + void resetModel() { // recreate labyrinth if (params != null) { params = controler.getSettings().resetParams(); - model = new LabyModel(params); - + setModel(new LabyModel(params)); refresh(); } } @@ -133,7 +138,6 @@ implements StatusListener maze.changed(null, null, model); } }.start(); - } } @@ -623,11 +627,19 @@ implements StatusListener setAutoSize(autoSlide.isSelected()); } }); + final JSlider layerSlide = new JSlider( JSlider.HORIZONTAL, 0,10, 0); + layerSlide.addChangeListener(new ChangeListener() { + public void stateChanged(ChangeEvent e) { + int r = setLayer(layerSlide.getValue()); + //layerSlide.setMaximum(r); + } + }); resizecontrol = new JPanel(new FlowLayout()); resizecontrol.add(showAll); resizecontrol.add(slider); resizecontrol.add(autoSlide); + resizecontrol.add(layerSlide); add(controlDisplayPanel, BorderLayout.SOUTH); add(resizecontrol, BorderLayout.WEST); @@ -658,7 +670,7 @@ implements StatusListener FileInputStream inputStream = null; try { inputStream = new FileInputStream(infile); - model = new MazePersistRaw().parseInputStream("raw",inputStream); + setModel(new MazePersistRaw().parseInputStream("raw",inputStream)); } catch (IOException io) { io.printStackTrace(System.err); statusField.setText("[ERROR] Can't load " + infile.getAbsolutePath()); @@ -787,7 +799,7 @@ implements StatusListener FileInputStream inputStream = null; try { inputStream = new FileInputStream(infile); - model = new MazePersistWorldEdit().parseInputStream("we",inputStream); + setModel(new MazePersistWorldEdit().parseInputStream("we",inputStream)); } catch (IOException io) { io.printStackTrace(System.err); statusField.setText("[ERROR] Can't load " + infile.getAbsolutePath()); @@ -874,6 +886,24 @@ implements StatusListener } } + private int setLayer(int x) + { + addStatus("set layer " + x); + LabyModel layermodel = layers.getLayer(x); + if ( layermodel == null ) + { + // clone it + model = new LabyModel(model); + layers.addLabyModel(x, model); + } + else + { + model = layermodel; + } + layer = x; + refresh(); + return layer; + } public static void main(String pArgs[]) { LabyModel model = null; diff --git a/java/org/artisanlogiciel/games/maze/gui/MazeSettings.java b/java/org/artisanlogiciel/games/maze/gui/MazeSettings.java index 421c9bb..d975b5f 100644 --- a/java/org/artisanlogiciel/games/maze/gui/MazeSettings.java +++ b/java/org/artisanlogiciel/games/maze/gui/MazeSettings.java @@ -15,6 +15,7 @@ public class MazeSettings extends JPanel { JTextField textHeight = null; JTextField textDepth = null; JTextField textSeed = null; + JCheckBox onewaywallCB = null; // TODO set width and height and depth of maze with gui public MazeSettings(MazeParams params) { @@ -53,6 +54,8 @@ public class MazeSettings extends JPanel { textSeed = new JTextField( "" + params.getSeed(),16); add(seedLabel); add(textSeed); + onewaywallCB = new JCheckBox("one way wall", false); + add(onewaywallCB); } } diff --git a/java/org/artisanlogiciel/games/maze/persist/MazePersistWorldEdit.java b/java/org/artisanlogiciel/games/maze/persist/MazePersistWorldEdit.java index 99f296a..0cb58c1 100644 --- a/java/org/artisanlogiciel/games/maze/persist/MazePersistWorldEdit.java +++ b/java/org/artisanlogiciel/games/maze/persist/MazePersistWorldEdit.java @@ -125,6 +125,7 @@ public class MazePersistWorldEdit { if ( ground != null ) { model = getModelFromSlice(ground); + model.setOnewaywall(true); System.out.println(model); } else