add path view

limit resolve depth ( to avoid infinite ).
to complete : horrible
This commit is contained in:
philippe lhardy
2017-11-29 23:09:32 +01:00
parent ce485f2263
commit 401c7e15d0
2 changed files with 181 additions and 72 deletions

View File

@@ -553,6 +553,50 @@ public class Display extends JFrame
g.drawLine(x, y, x, y + (int) height);
}
public void drawPath(Graphics g, int pX, int pY, short path)
{
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)
{
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));
}
}
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)
{
double radius = (height > width) ? width : height;
@@ -748,6 +792,7 @@ public class Display extends JFrame
int x = 0;
int y = 0;
short walls = 0;
short path = 0;
// try to display only visible part...
// should compute pX, pY, mX, mY based on clip...
@@ -808,6 +853,9 @@ public class Display extends JFrame
}
}
int aX = pX;
int aY = pY;
g.setColor(Color.black);
// draw all walls within clip bounds horiz first then lines
@@ -819,7 +867,31 @@ public class Display extends JFrame
cp.drawWalls(g, pX, pY, walls);
}
}
}
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 )
{
g.setColor(Color.green);
}
else
{
g.setColor(Color.blue);
}
if ( path != 0 )
{
cp.drawPath(g,pX,pY,path);
}
}
}
}
public boolean notifySearch(Position pPosition)