draw path

This commit is contained in:
philippe lhardy
2017-12-02 16:45:22 +01:00
parent 7deeb203ff
commit 77a06c0061
3 changed files with 73 additions and 10 deletions

View File

@@ -127,6 +127,26 @@ public class LabyModel implements WallsProvider
}
}
/* set direction existing onee are lost */
// FIXME FULLY BREAK RESOLVING...
public void setDirection(int x, int y, short path)
{
if ((x > 0) && (x < width) && (y > 0) && (y < height))
{
t[x][y]= path;
}
}
/** add a new direction, exiting ones are kept */
// FIXME FULLY BREAK RESOLVING...
public void addDirection(int x, int y, short path)
{
if ((x > 0) && (x < width) && (y > 0) && (y < height))
{
t[x][y]|= path;
}
}
// entry and exit can be outside the model boundaries a one x or one y out.
public boolean addEntryOrExit(int x, int y)
{
@@ -548,6 +568,40 @@ public class LabyModel implements WallsProvider
{
return ((check & flag) == flag);
}
public final static short getReverseDirection(int index)
{
return AllDirections[(index + 2) % 4];
}
/** return direction to use to be closer to 'to' from 'from' */
public final static short getDirection(Position from, Position to)
{
short pointingdirection = DIRECTION;
if ( from.equals(to) )
{
return pointingdirection;
}
if ( from.getX() < to.getX() )
{
pointingdirection |= RIGHT;
}
else
if ( from.getX() > to.getX() )
{
pointingdirection |= LEFT;
}
if ( from.getY() < to.getY() )
{
pointingdirection |= DOWN;
}
else
if ( from.getY() > to.getY() )
{
pointingdirection |= UP;
}
return pointingdirection;
}
/**
* resolve this labrynth using internal representation
@@ -575,16 +629,14 @@ public class LabyModel implements WallsProvider
backpath.addFirst(found);
found = null;
// should find from all adjacent cells (directions) one that point to this.
// should find from all adjacent cells (directions) one that point to this.
{
ArrayList<Short> freeDirection = new ArrayList<Short>();
// didx is index of four cell adjacent to this (x,y)
for (int didx = 0; didx < 4; didx++)
{
int delta = 0;
short direction = AllDirections[didx];
short reversedirection = AllDirections[(didx + 2) % 4];
short reversedirection = getReverseDirection(didx);
short pointingdirection = DIRECTION;
if (isFlagSet(direction,POSITIVE))
@@ -902,7 +954,7 @@ public class LabyModel implements WallsProvider
if ((newx >= 0) && (newy >= 0) && (newx < width) && (newy < height))
{
return ((t[newx][newy] & reversedirection) != reversedirection);
return !isFlagSet(t[newx][newy],(short)reversedirection);
}
else
{