refactoring, deploy Position and XYGridIterator

- try to use more Position instead of (x,y)
  - create PositionWithDpeth for its specific usage in path finding
- create a XYGridITerator that walk cells from grid X then Y.
This commit is contained in:
philippe lhardy
2020-12-28 19:12:35 +01:00
parent 0c886f0cd1
commit 02fda1fc2e
15 changed files with 311 additions and 162 deletions

View File

@@ -27,6 +27,11 @@ public class LabyMap implements WallsProvider
return getAt(x, y).getWalls(); return getAt(x, y).getWalls();
} }
public short getWalls(Position cell)
{
return getAt(cell.getX(), cell.getY()).getWalls();
}
public int getWidth() public int getWidth()
{ {
return tileMap[0].length; return tileMap[0].length;

View File

@@ -79,7 +79,7 @@ lues, they are used as it is for
boolean maxreached = false; boolean maxreached = false;
java.util.Random random; java.util.Random random;
// list of positions not fully walked // list of positions not fully walked
private final LinkedList<Position> openList = new LinkedList<Position>(); private final LinkedList<PositionWithDepth> openList = new LinkedList<>();
// list of entries and exits. // list of entries and exits.
private final LinkedList<Position> entryExits = new LinkedList<Position>(); private final LinkedList<Position> entryExits = new LinkedList<Position>();
private final Object coherentLock = new Object(); // before getting the lock private final Object coherentLock = new Object(); // before getting the lock
@@ -390,7 +390,7 @@ lues, they are used as it is for
return this.height; return this.height;
} }
public LinkedList<Position> getOpenList() { public LinkedList<PositionWithDepth> getOpenList() {
return openList; return openList;
} }
@@ -464,7 +464,7 @@ lues, they are used as it is for
t[x][y] &= ~OPEN; t[x][y] &= ~OPEN;
} }
if (isFlagSet(t[x][y], OPEN) || (t[x][y] == CLEAR)) { if (isFlagSet(t[x][y], OPEN) || (t[x][y] == CLEAR)) {
openList.add(new Position(x, y)); openList.add(new PositionWithDepth(x, y,0));
} }
} }
} }
@@ -477,7 +477,7 @@ lues, they are used as it is for
**/ **/
public void generateWithEntry(int x, int y) { public void generateWithEntry(int x, int y) {
openList.add(new Position(x, y)); openList.add(new PositionWithDepth(x, y,0));
while (!openList.isEmpty()) { while (!openList.isEmpty()) {
// this is where magic happens // this is where magic happens
step(); step();
@@ -493,7 +493,7 @@ lues, they are used as it is for
// should not continue in depth first... // should not continue in depth first...
if (!openList.isEmpty()) { if (!openList.isEmpty()) {
// insert head as next position to pick up. // insert head as next position to pick up.
Position current = openList.removeFirst(); PositionWithDepth current = openList.removeFirst();
openList.add(current); openList.add(current);
} }
} }
@@ -526,7 +526,7 @@ lues, they are used as it is for
* @param p Position * @param p Position
* @return true if newly added , false if already open. * @return true if newly added , false if already open.
**/ **/
private boolean open(boolean first, Position p) { private boolean open(boolean first, PositionWithDepth p) {
int x = p.getX(); int x = p.getX();
int y = p.getY(); int y = p.getY();
if ((t[x][y] & OPEN) != OPEN) { if ((t[x][y] & OPEN) != OPEN) {
@@ -537,6 +537,7 @@ lues, they are used as it is for
return false; return false;
} }
// WARNING Brick uses argument in other order... ( bad ... )
public final static boolean isFlagSet(short check, short flag) { public final static boolean isFlagSet(short check, short flag) {
return Brick.isFlagSet(flag,check); return Brick.isFlagSet(flag,check);
} }
@@ -588,7 +589,7 @@ lues, they are used as it is for
**/ **/
public boolean step() { public boolean step() {
boolean complete = false; boolean complete = false;
Position current = null; PositionWithDepth current = null;
synchronized (coherentLock) { synchronized (coherentLock) {
@@ -668,7 +669,7 @@ lues, they are used as it is for
newx = x; newx = x;
} }
Position target = new Position(newx, newy, current.getDepth() + 1); PositionWithDepth target = new PositionWithDepth(newx, newy, current.getDepth() + 1);
open(false, target); open(false, target);
if ((t[x][y] & DIRECTION) == DIRECTION) { if ((t[x][y] & DIRECTION) == DIRECTION) {
t[x][y] |= direction; t[x][y] |= direction;
@@ -707,6 +708,10 @@ lues, they are used as it is for
return complete; return complete;
} }
public short getWalls(Position cell) {
return getWalls(cell.getX(), cell.getY());
}
public short getWalls(int x, int y) { public short getWalls(int x, int y) {
short walls = 0; short walls = 0;
for (short direction : AllDirections) { for (short direction : AllDirections) {

View File

@@ -4,22 +4,20 @@ package org.artisanlogiciel.games.maze;
public class Position public class Position
{ {
private int x, y; private int x, y;
private int depth;
public Position(int x, int y, int depth)
{
this.x = x;
this.y = y;
this.depth = depth;
}
public Position(int x, int y) public Position(int x, int y)
{ {
this.x = x; this.x = x;
this.y = y; this.y = y;
this.depth = 0;
} }
public Position(Position other)
{
this.x = other.x;
this.y = other.y;
}
public int getX() public int getX()
{ {
return this.x; return this.x;
@@ -30,14 +28,45 @@ public class Position
return this.y; return this.y;
} }
public int getDepth() public Position translate(Position other) {
{ return new Position(x + other.x, y + other.y);
return depth;
} }
public Position doTranslate(Position other) {
x += other.x;
y += other.y;
return this;
}
public void limitToMax(int mx, int my)
{
x = Math.min(x,mx);
y = Math.min(y,my);
}
public void limitToMin(int mx, int my)
{
x = Math.max(x,mx);
y = Math.max(y,my);
}
public Position setX(int x)
{
this.x = x;
return this;
}
public Position setY(int y)
{
this.y = y;
return this;
}
public String toString() public String toString()
{ {
return "(" + x + "," + y + ")" + "/" + depth; return "(" + x + "," + y + ")";
} }
public boolean equals(Object other) public boolean equals(Object other)
@@ -52,7 +81,5 @@ public class Position
{ {
return false; return false;
} }
} }
} }

View File

@@ -0,0 +1,24 @@
package org.artisanlogiciel.games.maze;
public class PositionWithDepth
extends Position
{
private int depth;
public PositionWithDepth(int x, int y, int depth)
{
super(x,y);
this.depth = depth;
}
public int getDepth()
{
return depth;
}
public String toString()
{
return "(" + getX() + "," + getY() + ")" + "/" + depth;
}
}

View File

@@ -22,4 +22,6 @@ public interface WallsProvider
* t * t
**/ **/
short getWalls(int x, int y); short getWalls(int x, int y);
short getWalls(Position cell);
} }

View File

@@ -0,0 +1,46 @@
package org.artisanlogiciel.games.maze;
public class XYGridIterator {
final static Position stepX = new Position(1,0);
final static Position stepY = new Position( 0,1);
Position min;
Position max;
Position next;
public XYGridIterator(Position min, Position max) {
this.min = min;
this.max = max;
reset();
}
public void reset()
{
this.next = new Position(min);
}
public boolean hasNext()
{
return next != null;
}
public Position next()
{
if ( next != null)
{
Position current = new Position(next);
next.doTranslate(stepX);
if ( next.getX() >= max.getX()) {
if (next.getY() < max.getY() - 1) {
next.setX(min.getX()).doTranslate(stepY);
} else {
next = null;
}
}
return current;
}
return null;
}
}

View File

@@ -0,0 +1,19 @@
package org.artisanlogiciel.games.maze.gui;
import org.artisanlogiciel.games.maze.model.WidthHeightProvider;
import javax.swing.*;
public abstract class CellGridComponent
extends JComponent {
MazeCellRenderer cp;
MazeCellRenderer createCellRenderer(boolean hexagon, WidthHeightProvider model, WidthHeightProvider frame)
{
MazeCellRenderer cellRenderer = hexagon ?
new HexagonCellRenderer(model, frame, 0, 0)
: new MazeCellRenderer(model, frame, 0, 0);
return cellRenderer;
}
}

View File

@@ -66,6 +66,11 @@ implements StatusListener
maze.resetCellRenderer(hexagon, frameSize); maze.resetCellRenderer(hexagon, frameSize);
} }
public void setBackground(boolean background) {
addStatus(background ? "view background" : "hide background");
maze.setViewBackground(background);
}
private class MazeFrame extends JFrame private class MazeFrame extends JFrame
{ {
MazeFrame(LabyModel model, WidthHeightProvider frame, MazeParams params) { MazeFrame(LabyModel model, WidthHeightProvider frame, MazeParams params) {

View File

@@ -1,6 +1,7 @@
package org.artisanlogiciel.games.maze.gui; package org.artisanlogiciel.games.maze.gui;
import org.artisanlogiciel.games.maze.Brick; import org.artisanlogiciel.games.maze.Brick;
import org.artisanlogiciel.games.maze.Position;
import org.artisanlogiciel.games.maze.model.WidthHeightProvider; import org.artisanlogiciel.games.maze.model.WidthHeightProvider;
import java.awt.*; import java.awt.*;
@@ -20,15 +21,15 @@ extends MazeCellRenderer
super(model, frame, x, y); super(model, frame, x, y);
} }
void drawLine(Graphics g, int refx, int refy, int x, int y, int a, int b) { void drawLine(Graphics g, Position ref, int x, int y, int a, int b) {
g.drawLine( g.drawLine(
(int) ((refx + x) * width / SUBCELL), (int) ((refy + y) * height / SUBCELL), (int) ((ref.getX() + x) * width / SUBCELL), (int) ((ref.getY() + y) * height / SUBCELL),
(int) ((refx + a) * width / SUBCELL),(int) ((refy + b) * height / SUBCELL)); (int) ((ref.getX() + a) * width / SUBCELL),(int) ((ref.getY() + b) * height / SUBCELL));
} }
@Override @Override
public void drawBackground(Graphics g, int pX, int pY, short walls) { public void drawBackground(Graphics g, Position cell, short walls) {
UV uv= new UV(pX,pY); UV uv= new UV(cell);
int x = offsetX + (int) (uv.getX() * width / SUBCELL); int x = offsetX + (int) (uv.getX() * width / SUBCELL);
int y = offsetY + (int) (uv.getY() * height / SUBCELL); int y = offsetY + (int) (uv.getY() * height / SUBCELL);
Color savecolor = g.getColor(); Color savecolor = g.getColor();
@@ -39,47 +40,39 @@ extends MazeCellRenderer
} }
class UV class UV
extends Position
{ {
int u; int u;
int v; int v;
UV(int u, int v) UV(Position p)
{ {
this.u=u; super(p);
this.v=v; u=p.getX();
} v=p.getY();
setX(u*4 + 2*(v%2));
int getX() setY(3*v);
{
return u*4 + 2*(v%2);
}
int getY()
{
return 3*v;
} }
} }
@Override @Override
public void drawWalls(Graphics g, int pX, int pY, short walls) { public void drawWalls(Graphics g, Position cell, short walls) {
drawHalfNW(g, pX, pY, walls); drawHalfNW(g, cell, walls);
} }
void drawHalfNW(Graphics g, int refx, int refy, short walls) void drawHalfNW(Graphics g, Position cell, short walls)
{ {
UV uv= new UV(refx,refy); UV uv= new UV(cell);
int x = uv.getX();
int y = uv.getY();
// NW : (0,1) - (2,0) // NW : (0,1) - (2,0)
if (Brick.isFlagSet( Brick.UP, walls)) if (Brick.isFlagSet( Brick.UP, walls))
drawLine(g,x, y, 0,1,2,0); drawLine(g,uv, 0,1,2,0);
// W : (0,1) - (0,3) // W : (0,1) - (0,3)
if (Brick.isFlagSet( Brick.LEFT, walls)) if (Brick.isFlagSet( Brick.LEFT, walls))
drawLine(g,x,y,0,1,0,3); drawLine(g,uv,0,1,0,3);
// NE : (2,0) - (4,1) // NE : (2,0) - (4,1)
// if (Brick.isFlagSet( Brick.NE, walls)) // if (Brick.isFlagSet( Brick.NE, walls))
drawLine(g,x,y,2,0,4,1); drawLine(g,uv,2,0,4,1);
} }
void drawHalfSW(Graphics g) void drawHalfSW(Graphics g)

View File

@@ -82,25 +82,25 @@ public class MazeCellRenderer {
Math.max(0,color.getBlue() - greylevel)); Math.max(0,color.getBlue() - greylevel));
return greyedColor; return greyedColor;
} }
public void drawBackground(Graphics g, int pX, int pY, short walls) { public void drawBackground(Graphics g, Position cell, short walls) {
int x = offsetX + (int) (pX * width); int x = offsetX + (int) (cell.getX() * width);
int y = offsetY + (int) (pY * height); int y = offsetY + (int) (cell.getY() * height);
Color savecolor = g.getColor(); Color savecolor = g.getColor();
int greylevel = walls << 2; int greylevel = walls << 2;
g.setColor(getGreyedColor(savecolor,greylevel)); g.setColor(getGreyedColor(savecolor,greylevel));
//g.fillRect(x+1,y+1,((int)width) -1,((int)height) - 1); //g.fillRect(x+1,y+1,((int)width) -1,((int)height) - 1);
g.fillRect(x,y,((int)width),((int)height)); g.fillRect(x,y,((int)width),((int)height));
} }
public void drawWalls(Graphics g, int pX, int pY, short walls) { public void drawWalls(Graphics g, Position cell, short walls) {
int x = offsetX + (int) (pX * width); int x = offsetX + (int) (cell.getX() * width);
int y = offsetY + (int) (pY * height); int y = offsetY + (int) (cell.getY() * height);
if ((pY == 0) && ( Brick.isFlagSet( Brick.UP, walls))) if ((cell.getY() == 0) && ( Brick.isFlagSet( Brick.UP, walls)))
g.drawLine(x, y, x + (int) width, y); g.drawLine(x, y, x + (int) width, y);
if (Brick.isFlagSet( Brick.DOWN, walls)) if (Brick.isFlagSet( Brick.DOWN, walls))
g.drawLine(x, y + (int) height, x + (int) width, y + (int) height); g.drawLine(x, y + (int) height, x + (int) width, y + (int) height);
if (Brick.isFlagSet( Brick.RIGHT, walls)) if (Brick.isFlagSet( Brick.RIGHT, walls))
g.drawLine(x + (int) width, y, x + (int) width, y + (int) height); g.drawLine(x + (int) width, y, x + (int) width, y + (int) height);
if ((pX == 0) && (Brick.isFlagSet( Brick.LEFT, walls))) if ((cell.getX() == 0) && (Brick.isFlagSet( Brick.LEFT, walls)))
g.drawLine(x, y, x, y + (int) height); g.drawLine(x, y, x, y + (int) height);
} }
@@ -145,23 +145,23 @@ public class MazeCellRenderer {
} }
} }
public void drawDot(Graphics g, Position dot, int pX, int pY, int mX, int mY) { public void drawDot(Graphics g, Position dot, Position min, Position max) {
double h = getHeight(); double h = getHeight();
double radius = (h > width) ? width : h; double radius = (h > width) ? width : h;
int a = (int) (radius / 4); int a = (int) (radius / 4);
if ((dot.getX() >= pX) && (dot.getY() >= pY) && (dot.getX() < mX) && (dot.getY() < mY)) { if ((dot.getX() >= min.getX()) && (dot.getY() >= min.getY()) && (dot.getX() < max.getX()) && (dot.getY() < max.getY())) {
int x = offsetX + (int) (dot.getX() * width); int x = offsetX + (int) (dot.getX() * width);
int y = offsetY + (int) (dot.getY() * h); int y = offsetY + (int) (dot.getY() * h);
int r2 = (int) radius ; //(int) ((radius * 3) / 4); int r2 = (int) radius ; //(int) ((radius * 3) / 4);
g.drawOval(x, y, r2, r2); g.drawOval(x, y, r2, r2);
// g.drawLine(x+a,y+a,x+width-a,y+height-a); }
// g.drawLine(x+a,y+height-a,x+width-a,y+a); /* why do we drwa anything at all ?
else {
} else { int x = offsetX + (int) (min.getX() * width);
int x = offsetX + (int) (pX * width); int y = offsetY + (int) (min.getY() * h);
int y = offsetY + (int) (pY * h);
g.drawLine(x + 1, y + 1, x + (int) width - 1, y + (int) h - 1); g.drawLine(x + 1, y + 1, x + (int) width - 1, y + (int) h - 1);
} }
*/
} }
} }

View File

@@ -0,0 +1,19 @@
package org.artisanlogiciel.games.maze.gui;
import java.awt.*;
public class MazeColorMap {
public Color background;
public Color wall;
public Color path;
public Color resolved_path;
public Color goal;
public MazeColorMap(Color background, Color wall, Color path, Color resolved_path, Color goal) {
this.background = background;
this.wall = wall;
this.path = path;
this.resolved_path = resolved_path;
this.goal = goal;
}
}

View File

@@ -19,16 +19,16 @@ import java.util.Date;
import java.util.LinkedList; import java.util.LinkedList;
public class MazeComponent public class MazeComponent
extends JComponent extends CellGridComponent
implements MazeCreationListener, implements MazeCreationListener,
MazeResolutionListener, MazeResolutionListener,
MouseMotionListener, MouseMotionListener,
Scrollable Scrollable
{ {
private static final long serialVersionUID = 3163272907991176390L; private static final long serialVersionUID = 3163272907991176390L;
private boolean viewBackground = true;
LabyModelProvider map; LabyModelProvider map;
MazeCellRenderer cp;
Position current = null; Position current = null;
LinkedList<DirectionPosition> solvedPath = null; LinkedList<DirectionPosition> solvedPath = null;
LinkedList<DirectionPosition> drawingPath = null; LinkedList<DirectionPosition> drawingPath = null;
@@ -52,33 +52,8 @@ public class MazeComponent
StatusListener statusListener; StatusListener statusListener;
MazeCellRenderer createCellRenderer(boolean hexagon, WidthHeightProvider model, WidthHeightProvider frame)
{
MazeCellRenderer cellRenderer = hexagon ?
new HexagonCellRenderer(model, frame, 0, 0)
: new MazeCellRenderer(model, frame, 0, 0);
return cellRenderer;
}
MazeColorMap colorMap = new MazeColorMap(Color.white, Color.black, Color.blue, Color.green, Color.red); MazeColorMap colorMap = new MazeColorMap(Color.white, Color.black, Color.blue, Color.green, Color.red);
public class MazeColorMap
{
public Color background;
public Color wall;
public Color path;
public Color resolved_path;
public Color goal;
public MazeColorMap(Color background, Color wall, Color path, Color resolved_path, Color goal) {
this.background = background;
this.wall = wall;
this.path = path;
this.resolved_path = resolved_path;
this.goal = goal;
}
}
public void setXpm(Xpm xpm) public void setXpm(Xpm xpm)
{ {
this.xpm = xpm; this.xpm = xpm;
@@ -287,6 +262,15 @@ public class MazeComponent
*/ */
} }
public void setViewBackground(boolean viewBackground)
{
this.viewBackground = viewBackground;
}
private boolean hasBackground()
{
return viewBackground && (xpm != null);
}
@Override @Override
protected void paintComponent(Graphics g) { protected void paintComponent(Graphics g) {
super.paintComponent(g); super.paintComponent(g);
@@ -300,101 +284,95 @@ public class MazeComponent
// Shape s=g.getClip(); // Shape s=g.getClip();
Rectangle r = g.getClipBounds(); Rectangle r = g.getClipBounds();
int mX = (int) ((double) r.getWidth() / cp.getWidth()); // visible part of grid :
int mY = (int) ((double) r.getHeight() / cp.getHeight()); // (min)-------------
int pX = (int) ((double) (r.getX() - cp.getOffsetX()) / cp.getWidth()); // | |
int pY = (int) ((double) (r.getY() - cp.getOffsetY()) / cp.getHeight()); // _______________(max)
if (pX < 0) Position min = new Position(
pX = 0; (int) ((double) (r.getX() - cp.getOffsetX()) / cp.getWidth()),
if (pY < 0) (int) ((double) (r.getY() - cp.getOffsetY()) / cp.getHeight())
pY = 0; );
if (pX >= map.getWidth())
return; min.limitToMin(0,0);
if (pY >= map.getHeight())
if ( (min.getX() >= map.getWidth()) || (min.getY() >= map.getHeight()) )
return; return;
mX = mX + pX; Position extent = new Position(
mY = mY + pY; (int) ((double) r.getWidth() / cp.getWidth()),
(int) ((double) r.getHeight() / cp.getHeight())
);
Position max = min.translate(extent);
if (mX > map.getWidth()) { max.limitToMax(map.getWidth(), map.getHeight());
mX = map.getWidth();
} int mX = max.getX();
if (mY > map.getHeight()) { int mY = max.getY();
mY = map.getHeight();
}
int aX = pX;
int aY = pY;
// draw background // draw background
for (; pY < mY; pY++) { XYGridIterator iterator = new XYGridIterator(min,max);
for (pX = 0; pX < mX; pX++) { Position cell = null;
walls = map.getWalls(pX, pY); while ( ( cell = iterator.next()) != null )
if ( xpm != null ) { {
int cX = ( pX < xpm.getWidth()) ? pX : xpm.getWidth() - 1; walls = map.getWalls(cell);
int cY = ( pY < xpm.getHeight()) ? pY : xpm.getHeight() - 1; if ( hasBackground() ) {
g.setColor(xpm.getColor(cX,cY)); Position colored = new Position(cell);
colored.limitToMax(xpm.getWidth() - 1, xpm.getHeight() -1 );
g.setColor(xpm.getColor(colored.getX(), colored.getY()));
} }
else { else {
g.setColor(colorMap.background); g.setColor(colorMap.background);
} }
cp.drawBackground(g, pX, pY, walls); cp.drawBackground(g, cell, walls);
}
} }
if ((sX == gX) && (sY == gY)) { if ((sX == gX) && (sY == gY)) {
g.setColor(colorMap.goal); g.setColor(colorMap.goal);
} else { } else {
g.setColor(colorMap.resolved_path); g.setColor(colorMap.resolved_path);
cp.drawDot(g, new Position(gX, gY), pX, pY, mX, mY); cp.drawDot(g, new Position(gX, gY), min, max);
g.setColor(colorMap.path); g.setColor(colorMap.path);
} }
cp.drawDot(g, new Position(sX, sY), pX, pY, mX, mY); cp.drawDot(g, new Position(sX, sY), min, max);
pX = aX;
pY = aY;
// draw all walls within clip bounds horiz first then lines // draw all walls within clip bounds horiz first then lines
g.setColor(colorMap.wall); g.setColor(colorMap.wall);
for (; pY < mY; pY++) { iterator.reset();
for (pX = 0; pX < mX; pX++) { cell = null;
walls = map.getWalls(pX, pY); while ( ( cell = iterator.next()) != null )
cp.drawWalls(g, pX, pY, walls); {
} cp.drawWalls(g, cell, map.getWalls(cell));
} }
if (this.showAll) { if (this.showAll) {
statusListener.addStatus("*"); statusListener.addStatus("*");
pX = aX;
pY = aY;
// draw all path within clip bounds horiz first then lines // draw all path within clip bounds horiz first then lines
for (; pY < mY; pY++) { iterator.reset();
for (pX = 0; pX < mX; pX++) { cell = null;
path = map.getPath(pX, pY); while ( ( cell = iterator.next()) != null )
{
path = map.getPath(cell.getX(), cell.getY());
g.setColor(colorMap.path); g.setColor(colorMap.path);
if (path != 0) { if (path != 0) {
DirectionPosition dp = new DirectionPosition(path, new Position(pX, pY)); DirectionPosition dp = new DirectionPosition(path, new Position(cell));
cp.drawPath(g, dp, pX, pY, pX + 1, pY + 1); cp.drawPath(g, dp, cell.getX(), cell.getY(), cell.getX() + 1, cell.getY() + 1);
} }
} }
} }
}
pX = aX;
pY = aY;
synchronized (lockChange) { synchronized (lockChange) {
g.setColor(colorMap.goal); g.setColor(colorMap.goal);
if (current != null) { if (current != null) {
cp.drawDot(g, current, pX, pY, mX, mY); cp.drawDot(g, current, min, max);
} }
g.setColor(colorMap.resolved_path); g.setColor(colorMap.resolved_path);
if (solvedPath != null) { if (solvedPath != null) {
for (DirectionPosition resolved : solvedPath) { for (DirectionPosition resolved : solvedPath) {
cp.drawDot(g, resolved.getPosition(), pX, pY, mX, mY); cp.drawDot(g, resolved.getPosition(), min, max);
cp.drawPath(g, resolved, pX, pY, mX, mY); cp.drawPath(g, resolved, min.getX(), min.getY(), mX, mY);
} }
} }
} }

View File

@@ -229,6 +229,11 @@ public class MazeControler extends JPanel {
return newActionButton("load", format, action); return newActionButton("load", format, action);
} }
private JPanel createPaletteChooser()
{
return new JPanel(new FlowLayout());
}
private JPanel createResolveQuitBar() { private JPanel createResolveQuitBar() {
JPanel resolveQuitBar = new JPanel(new FlowLayout()); JPanel resolveQuitBar = new JPanel(new FlowLayout());
@@ -388,6 +393,7 @@ public class MazeControler extends JPanel {
display.setAutoSize(autoSlide.isSelected()); display.setAutoSize(autoSlide.isSelected());
} }
}); });
final JCheckBox hexagon = new JCheckBox("hexagon"); final JCheckBox hexagon = new JCheckBox("hexagon");
hexagon.addChangeListener(new ChangeListener() { hexagon.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) { public void stateChanged(ChangeEvent e) {
@@ -395,11 +401,19 @@ public class MazeControler extends JPanel {
} }
}); });
final JCheckBox background = new JCheckBox("background");
background.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
display.setBackground(background.isSelected());
}
});
JPanel resizecontrol = new JPanel(new FlowLayout()); JPanel 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(hexagon); resizecontrol.add(hexagon);
resizecontrol.add(background);
return resizecontrol; return resizecontrol;

View File

@@ -1,6 +1,7 @@
package org.artisanlogiciel.games.maze.model; package org.artisanlogiciel.games.maze.model;
import org.artisanlogiciel.games.maze.MovesProvider; import org.artisanlogiciel.games.maze.MovesProvider;
import org.artisanlogiciel.games.maze.Position;
import org.artisanlogiciel.games.maze.WallsProvider; import org.artisanlogiciel.games.maze.WallsProvider;
/** /**
@@ -98,6 +99,12 @@ public class HalfSquareRasterModel
); );
} }
public short getWalls(Position cell)
{
return getWalls(cell.getX(), cell.getY());
}
public short getMoves(int x, int y) public short getMoves(int x, int y)
{ {
// moves are where there is no walls ... // moves are where there is no walls ...

View File

@@ -2,6 +2,7 @@ package org.artisanlogiciel.games.maze.model;
import org.artisanlogiciel.games.maze.Brick; import org.artisanlogiciel.games.maze.Brick;
import org.artisanlogiciel.games.maze.MovesProvider; import org.artisanlogiciel.games.maze.MovesProvider;
import org.artisanlogiciel.games.maze.Position;
import org.artisanlogiciel.games.maze.WallsProvider; import org.artisanlogiciel.games.maze.WallsProvider;
public class LineColumnModel public class LineColumnModel
@@ -40,6 +41,10 @@ public class LineColumnModel
return c; return c;
} }
public short getWalls(Position cell) {
return getWalls(cell.getX(),cell.getY());
}
@Override @Override
public short getWalls(int x, int y) { public short getWalls(int x, int y) {
return (short) ( return (short) (