minor chnages / renaming / path painting
- draw resolved path as showAll correctly it was displaying all direction of same cell as solution while only one direction is ok - Renderer renaming for class rendering cells - draw directions as arrows
This commit is contained in:
@@ -538,7 +538,7 @@ lues, they are used as it is for
|
|||||||
}
|
}
|
||||||
|
|
||||||
public final static boolean isFlagSet(short check, short flag) {
|
public final static boolean isFlagSet(short check, short flag) {
|
||||||
return ((check & flag) == flag);
|
return Brick.isFlagSet(flag,check);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final short getCell(Position p) {
|
public final short getCell(Position p) {
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ implements StatusListener
|
|||||||
|
|
||||||
private MazeComponent createMazeComponent(LabyModel model, int W, int H) {
|
private MazeComponent createMazeComponent(LabyModel model, int W, int H) {
|
||||||
|
|
||||||
MazeCellParameters cp = mHexagon ? new HexagonCell(model.getWidth(), model.getHeight(), W, H, 0, 0) : new MazeCellParameters(model.getWidth(), model.getHeight(), W, H, 0, 0);
|
MazeCellRenderer cp = mHexagon ? new HexagonCellRenderer(model.getWidth(), model.getHeight(), W, H, 0, 0) : new MazeCellRenderer(model.getWidth(), model.getHeight(), W, H, 0, 0);
|
||||||
MazeComponent comp = new MazeComponent(model, cp, this);
|
MazeComponent comp = new MazeComponent(model, cp, this);
|
||||||
Xpm xpm = new Xpm();
|
Xpm xpm = new Xpm();
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -9,12 +9,12 @@ import java.awt.*;
|
|||||||
* using a square model ( LEFT UP only).
|
* using a square model ( LEFT UP only).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class HexagonCell
|
public class HexagonCellRenderer
|
||||||
extends MazeCellParameters
|
extends MazeCellRenderer
|
||||||
{
|
{
|
||||||
public final static int SUBCELL = 4;
|
public final static int SUBCELL = 4;
|
||||||
|
|
||||||
public HexagonCell(int mapw, int maph, int W, int H, int x, int y) {
|
public HexagonCellRenderer(int mapw, int maph, int W, int H, int x, int y) {
|
||||||
super(mapw, maph, W, H, x, y);
|
super(mapw, maph, W, H, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@ import org.artisanlogiciel.games.maze.solve.DirectionPosition;
|
|||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class MazeCellParameters {
|
public class MazeCellRenderer {
|
||||||
int offsetX; // x offset of upper corner left in pixels
|
int offsetX; // x offset of upper corner left in pixels
|
||||||
int offsetY; // y offset of upper corner left in pixers
|
int offsetY; // y offset of upper corner left in pixers
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ public class MazeCellParameters {
|
|||||||
double width; // width of one cell in pixels
|
double width; // width of one cell in pixels
|
||||||
double height; // height of one cell in pixels
|
double height; // height of one cell in pixels
|
||||||
|
|
||||||
public MazeCellParameters(int mapw, int maph, int W, int H, int x, int y) {
|
public MazeCellRenderer(int mapw, int maph, int W, int H, int x, int y) {
|
||||||
mapWidth = mapw;
|
mapWidth = mapw;
|
||||||
mapHeight = maph;
|
mapHeight = maph;
|
||||||
offsetX = x;
|
offsetX = x;
|
||||||
@@ -106,6 +106,7 @@ public class MazeCellParameters {
|
|||||||
|
|
||||||
public void drawPath(Graphics g, DirectionPosition dp, int pX, int pY, int mX, int mY) {
|
public void drawPath(Graphics g, DirectionPosition dp, int pX, int pY, int mX, int mY) {
|
||||||
if (dp != null) {
|
if (dp != null) {
|
||||||
|
boolean arrow = true;
|
||||||
Position dot = dp.getPosition();
|
Position dot = dp.getPosition();
|
||||||
if ((dot.getX() >= pX) && (dot.getY() >= pY) && (dot.getX() < mX) && (dot.getY() < mY)) {
|
if ((dot.getX() >= pX) && (dot.getY() >= pY) && (dot.getX() < mX) && (dot.getY() < mY)) {
|
||||||
int x = offsetX + (int) (dot.getX() * width);
|
int x = offsetX + (int) (dot.getX() * width);
|
||||||
@@ -113,25 +114,29 @@ public class MazeCellParameters {
|
|||||||
short path = dp.getDirection();
|
short path = dp.getDirection();
|
||||||
int xm = x + (int) (width / 2);
|
int xm = x + (int) (width / 2);
|
||||||
int ym = y + (int) (height / 2);
|
int ym = y + (int) (height / 2);
|
||||||
if ((path & LabyModel.HORIZONTAL) == LabyModel.HORIZONTAL) {
|
if (LabyModel.isFlagSet(path,LabyModel.HORIZONTAL)) {
|
||||||
if ((path & LabyModel.POSITIVE) == LabyModel.POSITIVE) {
|
if (LabyModel.isFlagSet(path, LabyModel.POSITIVE)) {
|
||||||
g.drawLine(xm, ym, x + (int) width, ym);
|
g.drawLine(xm, ym - (int) (height / 4), x + (int) width, ym);
|
||||||
|
if (arrow ) g.drawLine(xm, ym, x + (int) width, ym);
|
||||||
g.drawLine(xm, ym + (int) (height / 4), x + (int) width, ym);
|
g.drawLine(xm, ym + (int) (height / 4), x + (int) width, ym);
|
||||||
}
|
}
|
||||||
// LEFT /_
|
// LEFT /_
|
||||||
if ((path & LabyModel.NEGATIVE) == LabyModel.NEGATIVE) {
|
if (LabyModel.isFlagSet(path,LabyModel.NEGATIVE)) {
|
||||||
g.drawLine(x, ym, xm, ym);
|
g.drawLine(x, ym, xm, ym + (int) (height / 4));
|
||||||
|
if (arrow) g.drawLine(x, ym, xm, ym);
|
||||||
g.drawLine(x, ym, xm, ym - (int) (height / 4));
|
g.drawLine(x, ym, xm, ym - (int) (height / 4));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((path & LabyModel.VERTICAL) == LabyModel.VERTICAL) {
|
if (LabyModel.isFlagSet(path,LabyModel.VERTICAL)) {
|
||||||
if ((path & LabyModel.POSITIVE) == LabyModel.POSITIVE) {
|
if (LabyModel.isFlagSet(path ,LabyModel.POSITIVE)) {
|
||||||
g.drawLine(xm, ym, xm, y + (int) height);
|
g.drawLine(xm + (int) (width / 4), ym, xm, y + (int) height);
|
||||||
|
if (arrow) g.drawLine(xm, ym, xm, y + (int) height);
|
||||||
g.drawLine(xm - (int) (width / 4), ym, xm, y + (int) height);
|
g.drawLine(xm - (int) (width / 4), ym, xm, y + (int) height);
|
||||||
}
|
}
|
||||||
// UP |\
|
// UP |\
|
||||||
if ((path & LabyModel.NEGATIVE) == LabyModel.NEGATIVE) {
|
if (LabyModel.isFlagSet(path,LabyModel.NEGATIVE)) {
|
||||||
g.drawLine(xm, ym, xm, y);
|
g.drawLine(xm - (int) (width / 4), ym, xm, y);
|
||||||
|
if (arrow) g.drawLine(xm, ym, xm, y);
|
||||||
g.drawLine(xm + (int) (width / 4), ym, xm, y);
|
g.drawLine(xm + (int) (width / 4), ym, xm, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -145,8 +150,8 @@ public class MazeCellParameters {
|
|||||||
if ((dot.getX() >= pX) && (dot.getY() >= pY) && (dot.getX() < mX) && (dot.getY() < mY)) {
|
if ((dot.getX() >= pX) && (dot.getY() >= pY) && (dot.getX() < mX) && (dot.getY() < mY)) {
|
||||||
int x = offsetX + (int) (dot.getX() * width);
|
int x = offsetX + (int) (dot.getX() * width);
|
||||||
int y = offsetY + (int) (dot.getY() * height);
|
int y = offsetY + (int) (dot.getY() * height);
|
||||||
int r2 = (int) ((radius * 3) / 4);
|
int r2 = (int) radius ; //(int) ((radius * 3) / 4);
|
||||||
g.drawOval(x + 1, y + 1, 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+a,x+width-a,y+height-a);
|
||||||
// g.drawLine(x+a,y+height-a,x+width-a,y+a);
|
// g.drawLine(x+a,y+height-a,x+width-a,y+a);
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ public class MazeComponent
|
|||||||
private static final long serialVersionUID = 3163272907991176390L;
|
private static final long serialVersionUID = 3163272907991176390L;
|
||||||
|
|
||||||
LabyModelProvider map;
|
LabyModelProvider map;
|
||||||
final MazeCellParameters cp;
|
final MazeCellRenderer cp;
|
||||||
Position current = null;
|
Position current = null;
|
||||||
LinkedList<DirectionPosition> solvedPath = null;
|
LinkedList<DirectionPosition> solvedPath = null;
|
||||||
LinkedList<DirectionPosition> drawingPath = null;
|
LinkedList<DirectionPosition> drawingPath = null;
|
||||||
@@ -216,7 +216,7 @@ public class MazeComponent
|
|||||||
* offsetX, offsetY of upper left corner
|
* offsetX, offsetY of upper left corner
|
||||||
**/
|
**/
|
||||||
// public MazeComponent(WallsProvider map, MazeCellParameters cp)
|
// public MazeComponent(WallsProvider map, MazeCellParameters cp)
|
||||||
public MazeComponent(LabyModel map, MazeCellParameters cp, StatusListener statusListener) {
|
public MazeComponent(LabyModel map, MazeCellRenderer cp, StatusListener statusListener) {
|
||||||
super();
|
super();
|
||||||
this.cp = cp;
|
this.cp = cp;
|
||||||
this.map = map;
|
this.map = map;
|
||||||
@@ -350,22 +350,6 @@ public class MazeComponent
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pX = aX;
|
|
||||||
pY = aY;
|
|
||||||
|
|
||||||
synchronized (lockChange) {
|
|
||||||
g.setColor(colorMap.goal);
|
|
||||||
if (current != null) {
|
|
||||||
cp.drawDot(g, current, pX, pY, mX, mY);
|
|
||||||
}
|
|
||||||
if (solvedPath != null) {
|
|
||||||
for (DirectionPosition resolved : solvedPath) {
|
|
||||||
// cp.drawDot(g, resolved.getPosition(), pX, pY, mX, mY);
|
|
||||||
cp.drawPath(g, resolved, pX, pY, mX, mY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.showAll) {
|
if (this.showAll) {
|
||||||
statusListener.addStatus("*");
|
statusListener.addStatus("*");
|
||||||
pX = aX;
|
pX = aX;
|
||||||
@@ -375,11 +359,7 @@ public class MazeComponent
|
|||||||
for (; pY < mY; pY++) {
|
for (; pY < mY; pY++) {
|
||||||
for (pX = 0; pX < mX; pX++) {
|
for (pX = 0; pX < mX; pX++) {
|
||||||
path = map.getPath(pX, pY);
|
path = map.getPath(pX, pY);
|
||||||
if ((path & LabyModel.SOLVED) == LabyModel.SOLVED) {
|
g.setColor(colorMap.path);
|
||||||
g.setColor(colorMap.resolved_path);
|
|
||||||
} else {
|
|
||||||
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(pX, pY));
|
||||||
cp.drawPath(g, dp, pX, pY, pX + 1, pY + 1);
|
cp.drawPath(g, dp, pX, pY, pX + 1, pY + 1);
|
||||||
@@ -387,6 +367,24 @@ public class MazeComponent
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pX = aX;
|
||||||
|
pY = aY;
|
||||||
|
|
||||||
|
synchronized (lockChange) {
|
||||||
|
g.setColor(colorMap.goal);
|
||||||
|
if (current != null) {
|
||||||
|
cp.drawDot(g, current, pX, pY, mX, mY);
|
||||||
|
}
|
||||||
|
g.setColor(colorMap.resolved_path);
|
||||||
|
if (solvedPath != null) {
|
||||||
|
for (DirectionPosition resolved : solvedPath) {
|
||||||
|
cp.drawDot(g, resolved.getPosition(), pX, pY, mX, mY);
|
||||||
|
cp.drawPath(g, resolved, pX, pY, mX, mY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -402,9 +400,15 @@ public class MazeComponent
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void notifySearchError(String error) {
|
public void notifySearchError(String error) {
|
||||||
System.err.println(error);
|
notifySearchInfoLevel(0,error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void notifySearchInfoLevel(int infoLevel, String pInfo)
|
||||||
|
{
|
||||||
|
statusListener.addStatus(pInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void notifyCompletion(LinkedList<DirectionPosition> solvedPath) {
|
public void notifyCompletion(LinkedList<DirectionPosition> solvedPath) {
|
||||||
LinkedList<DirectionPosition> newPath = new LinkedList<>(solvedPath);
|
LinkedList<DirectionPosition> newPath = new LinkedList<>(solvedPath);
|
||||||
statusListener.addStatus("resolution completed");
|
statusListener.addStatus("resolution completed");
|
||||||
|
|||||||
@@ -10,8 +10,13 @@ public interface MazeResolutionListener
|
|||||||
|
|
||||||
boolean notifySearch(DirectionPosition pPosition);
|
boolean notifySearch(DirectionPosition pPosition);
|
||||||
|
|
||||||
|
/* @deprecated
|
||||||
|
use notifySearchInfoLevel(0, String pInfo);
|
||||||
|
*/
|
||||||
void notifySearchError(String error);
|
void notifySearchError(String error);
|
||||||
|
|
||||||
|
void notifySearchInfoLevel(int infoLevel, String pInfo);
|
||||||
|
|
||||||
void notifyCompletion(LinkedList<DirectionPosition> solvedPath);
|
void notifyCompletion(LinkedList<DirectionPosition> solvedPath);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ extends LabyModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* resolve this labrynth using internal representation
|
* resolve this labyrinth using internal representation
|
||||||
* initial (x,y) is exit, will return list of positions from start (0,0) to end (x,y)
|
* initial (x,y) is exit, will return list of positions from start (0,0) to end (x,y)
|
||||||
**/
|
**/
|
||||||
public LinkedList<DirectionPosition> resolve(int x, int y, MazeResolutionListener rlistener) {
|
public LinkedList<DirectionPosition> resolve(int x, int y, MazeResolutionListener rlistener) {
|
||||||
|
|||||||
Reference in New Issue
Block a user