draw path
This commit is contained in:
@@ -22,6 +22,11 @@ public class DirectionPosition
|
||||
return direction;
|
||||
}
|
||||
|
||||
void setDirection(short d)
|
||||
{
|
||||
direction = d;
|
||||
}
|
||||
|
||||
Position getPosition()
|
||||
{
|
||||
return position;
|
||||
|
||||
@@ -649,8 +649,10 @@ public class Display extends JFrame
|
||||
@Override
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
// should find the cell ...
|
||||
DirectionPosition last = null;
|
||||
int pX = (int) ((double) (e.getX() - cp.getOffsetX()) / cp.getWidth());
|
||||
int pY = (int) ((double) (e.getY() - cp.getOffsetY()) / cp.getHeight());
|
||||
short path = 0;
|
||||
Position newPosition = new Position(pX,pY);
|
||||
if (drawingPath == null )
|
||||
{
|
||||
@@ -658,17 +660,21 @@ public class Display extends JFrame
|
||||
}
|
||||
else
|
||||
{
|
||||
DirectionPosition last = drawingPath.getLast();
|
||||
// setShowAll(true);
|
||||
last = drawingPath.getLast();
|
||||
if ( last.getPosition().equals(newPosition))
|
||||
{
|
||||
// no move.
|
||||
return;
|
||||
}
|
||||
// short path=computeMove(last,newPosition);
|
||||
path=LabyModel.getDirection(last.getPosition(),newPosition);
|
||||
last.setDirection(path);
|
||||
map.setDirection(last.getPosition().getX(),last.getPosition().getY(),path);
|
||||
}
|
||||
last = new DirectionPosition((short) 0,newPosition);
|
||||
System.out.println("Mouse dragged Cell " + newPosition);
|
||||
drawingPath.addLast(new DirectionPosition((short) 0,newPosition));
|
||||
map.noWalls(pX,pY);
|
||||
drawingPath.addLast(last);
|
||||
// map.noWalls(pX,pY);
|
||||
changed(null,null,map);
|
||||
}
|
||||
|
||||
@@ -679,7 +685,7 @@ public class Display extends JFrame
|
||||
|
||||
public void setShowAll(boolean showall )
|
||||
{
|
||||
showAll = showAll;
|
||||
this.showAll = showAll;
|
||||
}
|
||||
|
||||
void checkExit()
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
@@ -549,6 +569,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
|
||||
* initial (x,y) is exit, will return list of positions from start to end.
|
||||
@@ -577,14 +631,12 @@ public class LabyModel implements WallsProvider
|
||||
|
||||
// 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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user