wall half closure control + layers
- add onewaywall option to create a wall if there is not step back - add layers of maze - load minetest scheme .we with onewall option
This commit is contained in:
25
java/org/artisanlogiciel/games/maze/LabyLayers.java
Normal file
25
java/org/artisanlogiciel/games/maze/LabyLayers.java
Normal file
@@ -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<Integer,LabyModel> 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -85,6 +85,8 @@ public class LabyModel implements WallsProvider {
|
|||||||
|
|
||||||
MazeCreationListener listener = null;
|
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) {
|
private LabyModel(int width, int height, int maxdepth, Random random) {
|
||||||
this.width = width;
|
this.width = width;
|
||||||
@@ -713,17 +715,23 @@ public class LabyModel implements WallsProvider {
|
|||||||
int reversedirection = 0;
|
int reversedirection = 0;
|
||||||
|
|
||||||
// is this direction on the path ? yes => no wall
|
// is this direction on the path ? yes => no wall
|
||||||
if ((t[x][y] & direction) == direction) {
|
if ( isFlagSet(t[x][y], direction)) {
|
||||||
return false;
|
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 =>
|
// is adjacent tile in direction pointing in reverse direction ? yes =>
|
||||||
// no wall
|
// no wall
|
||||||
if ((direction & POSITIVE) == POSITIVE) {
|
delta = ((direction & POSITIVE) == POSITIVE) ? 1 : -1;
|
||||||
delta = 1;
|
|
||||||
} else {
|
|
||||||
delta = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((direction & HORIZONTAL) == HORIZONTAL) {
|
if ((direction & HORIZONTAL) == HORIZONTAL) {
|
||||||
newx = x + delta;
|
newx = x + delta;
|
||||||
@@ -736,7 +744,7 @@ public class LabyModel implements WallsProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((newx >= 0) && (newy >= 0) && (newx < width) && (newy < height)) {
|
if ((newx >= 0) && (newy >= 0) && (newx < width) && (newy < height)) {
|
||||||
return !isFlagSet(t[newx][newy], (short) reversedirection);
|
return ! isFlagSet(t[newx][newy], (short) reversedirection);
|
||||||
} else {
|
} else {
|
||||||
// outside boundaries.
|
// outside boundaries.
|
||||||
// TODO CHECK exits.
|
// 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 ?
|
* is there no wall in that direction ?
|
||||||
**/
|
**/
|
||||||
public boolean canMoveInDirection(int x, int y, short direction) {
|
public boolean canMoveInDirection(int x, int y, short direction) {
|
||||||
// tried to replace by but does not work ( can't go back ...).
|
// one way wall will create walll if it not possible to step back to current position from next position
|
||||||
// return ! hasWallInDirection(x,y, (short) (direction << FLAGLENGTH));
|
return onewaywall ? ( ! hasWallInDirection(x,y, (short) (direction << FLAGLENGTH)) ) : ((getWalls(x, y) & direction ) == 0);
|
||||||
return ((getWalls(x, y) & direction ) == 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
package org.artisanlogiciel.games.maze.gui;
|
package org.artisanlogiciel.games.maze.gui;
|
||||||
|
|
||||||
import org.artisanlogiciel.games.maze.DrawingGenerator;
|
import org.artisanlogiciel.games.maze.*;
|
||||||
import org.artisanlogiciel.games.maze.LabyModel;
|
|
||||||
import org.artisanlogiciel.games.maze.MazeParams;
|
|
||||||
import org.artisanlogiciel.games.maze.MazeParamsFixed;
|
|
||||||
import org.artisanlogiciel.games.maze.persist.MazePersistWorldEdit;
|
import org.artisanlogiciel.games.maze.persist.MazePersistWorldEdit;
|
||||||
import org.artisanlogiciel.games.maze.persist.MazePersistRaw;
|
import org.artisanlogiciel.games.maze.persist.MazePersistRaw;
|
||||||
import org.artisanlogiciel.games.maze.solve.SolvingModel;
|
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());
|
public final static ResourceBundle labels = ResourceBundle.getBundle("LabelsBundle", Locale.getDefault(), Display.class.getClassLoader(), new UTF8Control());
|
||||||
|
|
||||||
|
LabyLayers layers = new LabyLayers();
|
||||||
|
int layer = 0;
|
||||||
|
|
||||||
MazeComponent maze;
|
MazeComponent maze;
|
||||||
MazeControler controler;
|
MazeControler controler;
|
||||||
LabyModel model;
|
LabyModel model;
|
||||||
@@ -110,12 +110,17 @@ implements StatusListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setModel( LabyModel model)
|
||||||
|
{
|
||||||
|
this.model = model;
|
||||||
|
layers.addLabyModel(layer, model);
|
||||||
|
}
|
||||||
|
|
||||||
void resetModel() {
|
void resetModel() {
|
||||||
// recreate labyrinth
|
// recreate labyrinth
|
||||||
if (params != null) {
|
if (params != null) {
|
||||||
params = controler.getSettings().resetParams();
|
params = controler.getSettings().resetParams();
|
||||||
model = new LabyModel(params);
|
setModel(new LabyModel(params));
|
||||||
|
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -133,7 +138,6 @@ implements StatusListener
|
|||||||
maze.changed(null, null, model);
|
maze.changed(null, null, model);
|
||||||
}
|
}
|
||||||
}.start();
|
}.start();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -623,11 +627,19 @@ implements StatusListener
|
|||||||
setAutoSize(autoSlide.isSelected());
|
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 = new JPanel(new FlowLayout());
|
||||||
resizecontrol.add(showAll);
|
resizecontrol.add(showAll);
|
||||||
resizecontrol.add(slider);
|
resizecontrol.add(slider);
|
||||||
resizecontrol.add(autoSlide);
|
resizecontrol.add(autoSlide);
|
||||||
|
resizecontrol.add(layerSlide);
|
||||||
|
|
||||||
add(controlDisplayPanel, BorderLayout.SOUTH);
|
add(controlDisplayPanel, BorderLayout.SOUTH);
|
||||||
add(resizecontrol, BorderLayout.WEST);
|
add(resizecontrol, BorderLayout.WEST);
|
||||||
@@ -658,7 +670,7 @@ implements StatusListener
|
|||||||
FileInputStream inputStream = null;
|
FileInputStream inputStream = null;
|
||||||
try {
|
try {
|
||||||
inputStream = new FileInputStream(infile);
|
inputStream = new FileInputStream(infile);
|
||||||
model = new MazePersistRaw().parseInputStream("raw",inputStream);
|
setModel(new MazePersistRaw().parseInputStream("raw",inputStream));
|
||||||
} catch (IOException io) {
|
} catch (IOException io) {
|
||||||
io.printStackTrace(System.err);
|
io.printStackTrace(System.err);
|
||||||
statusField.setText("[ERROR] Can't load " + infile.getAbsolutePath());
|
statusField.setText("[ERROR] Can't load " + infile.getAbsolutePath());
|
||||||
@@ -787,7 +799,7 @@ implements StatusListener
|
|||||||
FileInputStream inputStream = null;
|
FileInputStream inputStream = null;
|
||||||
try {
|
try {
|
||||||
inputStream = new FileInputStream(infile);
|
inputStream = new FileInputStream(infile);
|
||||||
model = new MazePersistWorldEdit().parseInputStream("we",inputStream);
|
setModel(new MazePersistWorldEdit().parseInputStream("we",inputStream));
|
||||||
} catch (IOException io) {
|
} catch (IOException io) {
|
||||||
io.printStackTrace(System.err);
|
io.printStackTrace(System.err);
|
||||||
statusField.setText("[ERROR] Can't load " + infile.getAbsolutePath());
|
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[]) {
|
public static void main(String pArgs[]) {
|
||||||
LabyModel model = null;
|
LabyModel model = null;
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ public class MazeSettings extends JPanel {
|
|||||||
JTextField textHeight = null;
|
JTextField textHeight = null;
|
||||||
JTextField textDepth = null;
|
JTextField textDepth = null;
|
||||||
JTextField textSeed = null;
|
JTextField textSeed = null;
|
||||||
|
JCheckBox onewaywallCB = 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(MazeParams params) {
|
public MazeSettings(MazeParams params) {
|
||||||
@@ -53,6 +54,8 @@ public class MazeSettings extends JPanel {
|
|||||||
textSeed = new JTextField( "" + params.getSeed(),16);
|
textSeed = new JTextField( "" + params.getSeed(),16);
|
||||||
add(seedLabel);
|
add(seedLabel);
|
||||||
add(textSeed);
|
add(textSeed);
|
||||||
|
onewaywallCB = new JCheckBox("one way wall", false);
|
||||||
|
add(onewaywallCB);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -125,6 +125,7 @@ public class MazePersistWorldEdit {
|
|||||||
if ( ground != null )
|
if ( ground != null )
|
||||||
{
|
{
|
||||||
model = getModelFromSlice(ground);
|
model = getModelFromSlice(ground);
|
||||||
|
model.setOnewaywall(true);
|
||||||
System.out.println(model);
|
System.out.println(model);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user