show path with selected direction when resolved.
This commit is contained in:
@@ -60,7 +60,7 @@ public class Display extends JFrame
|
||||
boolean autoSize;
|
||||
|
||||
MazeParams params = null;
|
||||
|
||||
|
||||
Display(LabyModel model,int W, int H, MazeParams params)
|
||||
{
|
||||
super("Maze display");
|
||||
@@ -553,48 +553,48 @@ public class Display extends JFrame
|
||||
g.drawLine(x, y, x, y + (int) height);
|
||||
}
|
||||
|
||||
public void drawPath(Graphics g, int pX, int pY, short path)
|
||||
public void drawPath(Graphics g, DirectionPosition dp, int pX, int pY, int mX, int mY)
|
||||
{
|
||||
int x = offsetX + (int) (pX * width);
|
||||
int y = offsetY + (int) (pY * height);
|
||||
int xm = x+ (int) (width / 2);
|
||||
int ym = y+ (int) (height / 2);
|
||||
if ( (path & LabyModel.HORIZONTAL) == LabyModel.HORIZONTAL)
|
||||
if ( dp != null )
|
||||
{
|
||||
g.drawLine(x, ym, x + (int) width, ym);
|
||||
if ( (path & LabyModel.POSITIVE) == LabyModel.POSITIVE )
|
||||
{
|
||||
g.drawLine(x, ym + (int) (height / 4), x + (int) width, ym);
|
||||
}
|
||||
if ( (path & LabyModel.NEGATIVE) == LabyModel.NEGATIVE )
|
||||
{
|
||||
g.drawLine(x, ym , x + (int) width, ym - (int) (height / 4));
|
||||
}
|
||||
Position dot = dp.getPosition();
|
||||
if ((dot.getX() >= pX) && (dot.getY() >= pY) && (dot.getX() < mX) && (dot.getY() < mY))
|
||||
{
|
||||
int x = offsetX + (int) (dot.getX() * width);
|
||||
int y = offsetY + (int) (dot.getY() * height);
|
||||
short path = dp.getDirection();
|
||||
int xm = x+ (int) (width / 2);
|
||||
int ym = y+ (int) (height / 2);
|
||||
if ( (path & LabyModel.HORIZONTAL) == LabyModel.HORIZONTAL)
|
||||
{
|
||||
if ( (path & LabyModel.POSITIVE) == LabyModel.POSITIVE )
|
||||
{
|
||||
g.drawLine(xm, ym, x + (int) width, ym);
|
||||
g.drawLine(xm, ym + (int) (height / 4), x + (int) width, ym);
|
||||
}
|
||||
// LEFT /_
|
||||
if ( (path & LabyModel.NEGATIVE) == LabyModel.NEGATIVE )
|
||||
{
|
||||
g.drawLine(x, ym, xm, ym);
|
||||
g.drawLine(x, ym, xm, ym - (int) (height / 4));
|
||||
}
|
||||
}
|
||||
if ((path & LabyModel.VERTICAL) == LabyModel.VERTICAL)
|
||||
{
|
||||
if ( (path & LabyModel.POSITIVE) == LabyModel.POSITIVE )
|
||||
{
|
||||
g.drawLine(xm, ym, xm , y + (int) height);
|
||||
g.drawLine(xm - (int) (width / 4), ym , xm, y + (int) height);
|
||||
}
|
||||
// UP |\
|
||||
if ( (path & LabyModel.NEGATIVE) == LabyModel.NEGATIVE )
|
||||
{
|
||||
g.drawLine(xm, ym, xm , y);
|
||||
g.drawLine(xm + (int) (width /4), ym , xm , y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((path & LabyModel.VERTICAL) == LabyModel.VERTICAL)
|
||||
{
|
||||
g.drawLine(xm, y, xm , y + (int) height);
|
||||
if ( (path & LabyModel.POSITIVE) == LabyModel.POSITIVE )
|
||||
{
|
||||
g.drawLine(xm - (int) (width / 4), y , xm, y + (int) height);
|
||||
}
|
||||
if ( (path & LabyModel.NEGATIVE) == LabyModel.NEGATIVE )
|
||||
{
|
||||
g.drawLine(xm, y , xm + (int) (width /4), y + (int) (height));
|
||||
}
|
||||
}
|
||||
/*
|
||||
if ((path & LabyModel.HORIZONTAL) ==LabyModel.HORIZONTAL)
|
||||
{
|
||||
y=y+ (int) (height / 2);
|
||||
g.drawLine(x + (int) width, y, x + (int) width, y + (int) height);
|
||||
}
|
||||
if ( (pX == 0 ) && ((path & LabyModel.VERTICAL) == LabyModel.VERTICAL))
|
||||
{
|
||||
x=x+ (int) (width / 2);
|
||||
g.drawLine(x, y, x, y + (int) height);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
public void drawDot(Graphics g, Position dot, int pX, int pY, int mX, int mY)
|
||||
@@ -633,7 +633,7 @@ public class Display extends JFrame
|
||||
LabyModel map;
|
||||
final MazeCellParameters cp;
|
||||
Position current = null;
|
||||
LinkedList<Position> solvedPath = null;
|
||||
LinkedList<DirectionPosition> solvedPath = null;
|
||||
final Object lockChange = new Object();
|
||||
// current postion of human resolving
|
||||
int sX = 0;
|
||||
@@ -641,6 +641,9 @@ public class Display extends JFrame
|
||||
// goal exit
|
||||
int gX = -1;
|
||||
int gY = -1;
|
||||
|
||||
// not set by default for debug, will show any path
|
||||
boolean showAll = false;
|
||||
|
||||
@Override
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
@@ -654,9 +657,14 @@ public class Display extends JFrame
|
||||
|
||||
@Override
|
||||
public void mouseMoved(MouseEvent e) {
|
||||
System.out.println("Mouse moved (" + e.getX() + ',' + e.getY() + ')');
|
||||
// System.out.println("Mouse moved (" + e.getX() + ',' + e.getY() + ')');
|
||||
}
|
||||
|
||||
public void setShowAll(boolean showall )
|
||||
{
|
||||
showAll = showAll;
|
||||
}
|
||||
|
||||
void checkExit()
|
||||
{
|
||||
if ((sX == gX) && (sY == gY))
|
||||
@@ -846,9 +854,10 @@ public class Display extends JFrame
|
||||
}
|
||||
if (solvedPath != null)
|
||||
{
|
||||
for (Position resolved : solvedPath)
|
||||
for (DirectionPosition resolved : solvedPath)
|
||||
{
|
||||
cp.drawDot(g, resolved, pX, pY, mX, mY);
|
||||
// cp.drawDot(g, resolved.getPosition(), pX, pY, mX, mY);
|
||||
cp.drawPath(g,resolved, pX, pY, mX, mY);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -868,37 +877,42 @@ public class Display extends JFrame
|
||||
}
|
||||
}
|
||||
|
||||
pX = aX;
|
||||
pY = aY;
|
||||
if (showAll)
|
||||
{
|
||||
|
||||
pX = aX;
|
||||
pY = aY;
|
||||
|
||||
// draw all path within clip bounds horiz first then lines
|
||||
for (; pY < mY; pY++)
|
||||
{
|
||||
for (pX = 0; pX < mX; pX++)
|
||||
{
|
||||
path = map.getPath(pX,pY);
|
||||
if ( ( path & LabyModel.SOLVED ) == LabyModel.SOLVED )
|
||||
// draw all path within clip bounds horiz first then lines
|
||||
for (; pY < mY; pY++)
|
||||
{
|
||||
g.setColor(Color.green);
|
||||
for (pX = 0; pX < mX; pX++)
|
||||
{
|
||||
path = map.getPath(pX,pY);
|
||||
if ( ( path & LabyModel.SOLVED ) == LabyModel.SOLVED )
|
||||
{
|
||||
g.setColor(Color.green);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.setColor(Color.blue);
|
||||
}
|
||||
if ( path != 0 )
|
||||
{
|
||||
DirectionPosition dp = new DirectionPosition(path,new Position(pX,pY));
|
||||
cp.drawPath(g,dp,pX,pY,pX+1,pY+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
g.setColor(Color.blue);
|
||||
}
|
||||
if ( path != 0 )
|
||||
{
|
||||
cp.drawPath(g,pX,pY,path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean notifySearch(Position pPosition)
|
||||
public boolean notifySearch(DirectionPosition pPosition)
|
||||
{
|
||||
synchronized (lockChange)
|
||||
{
|
||||
current = pPosition;
|
||||
current = pPosition.getPosition();
|
||||
}
|
||||
// should redraw ...
|
||||
invalidate();
|
||||
@@ -912,9 +926,9 @@ public class Display extends JFrame
|
||||
System.err.println(error);
|
||||
}
|
||||
|
||||
public void notifyCompletion(LinkedList<Position> solvedPath)
|
||||
public void notifyCompletion(LinkedList<DirectionPosition> solvedPath)
|
||||
{
|
||||
LinkedList<Position> newPath = new LinkedList<>(solvedPath);
|
||||
LinkedList<DirectionPosition> newPath = new LinkedList<>(solvedPath);
|
||||
System.out.println("resolution completed");
|
||||
synchronized (lockChange)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user