draw path
This commit is contained in:
@@ -22,6 +22,11 @@ public class DirectionPosition
|
|||||||
return direction;
|
return direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setDirection(short d)
|
||||||
|
{
|
||||||
|
direction = d;
|
||||||
|
}
|
||||||
|
|
||||||
Position getPosition()
|
Position getPosition()
|
||||||
{
|
{
|
||||||
return position;
|
return position;
|
||||||
|
|||||||
@@ -649,8 +649,10 @@ public class Display extends JFrame
|
|||||||
@Override
|
@Override
|
||||||
public void mouseDragged(MouseEvent e) {
|
public void mouseDragged(MouseEvent e) {
|
||||||
// should find the cell ...
|
// should find the cell ...
|
||||||
|
DirectionPosition last = null;
|
||||||
int pX = (int) ((double) (e.getX() - cp.getOffsetX()) / cp.getWidth());
|
int pX = (int) ((double) (e.getX() - cp.getOffsetX()) / cp.getWidth());
|
||||||
int pY = (int) ((double) (e.getY() - cp.getOffsetY()) / cp.getHeight());
|
int pY = (int) ((double) (e.getY() - cp.getOffsetY()) / cp.getHeight());
|
||||||
|
short path = 0;
|
||||||
Position newPosition = new Position(pX,pY);
|
Position newPosition = new Position(pX,pY);
|
||||||
if (drawingPath == null )
|
if (drawingPath == null )
|
||||||
{
|
{
|
||||||
@@ -658,17 +660,21 @@ public class Display extends JFrame
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DirectionPosition last = drawingPath.getLast();
|
// setShowAll(true);
|
||||||
|
last = drawingPath.getLast();
|
||||||
if ( last.getPosition().equals(newPosition))
|
if ( last.getPosition().equals(newPosition))
|
||||||
{
|
{
|
||||||
// no move.
|
// no move.
|
||||||
return;
|
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);
|
System.out.println("Mouse dragged Cell " + newPosition);
|
||||||
drawingPath.addLast(new DirectionPosition((short) 0,newPosition));
|
drawingPath.addLast(last);
|
||||||
map.noWalls(pX,pY);
|
// map.noWalls(pX,pY);
|
||||||
changed(null,null,map);
|
changed(null,null,map);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -679,7 +685,7 @@ public class Display extends JFrame
|
|||||||
|
|
||||||
public void setShowAll(boolean showall )
|
public void setShowAll(boolean showall )
|
||||||
{
|
{
|
||||||
showAll = showAll;
|
this.showAll = showAll;
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkExit()
|
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.
|
// entry and exit can be outside the model boundaries a one x or one y out.
|
||||||
public boolean addEntryOrExit(int x, int y)
|
public boolean addEntryOrExit(int x, int y)
|
||||||
{
|
{
|
||||||
@@ -548,6 +568,40 @@ public class LabyModel implements WallsProvider
|
|||||||
{
|
{
|
||||||
return ((check & flag) == flag);
|
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
|
* resolve this labrynth using internal representation
|
||||||
@@ -575,16 +629,14 @@ public class LabyModel implements WallsProvider
|
|||||||
backpath.addFirst(found);
|
backpath.addFirst(found);
|
||||||
found = null;
|
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)
|
// didx is index of four cell adjacent to this (x,y)
|
||||||
for (int didx = 0; didx < 4; didx++)
|
for (int didx = 0; didx < 4; didx++)
|
||||||
{
|
{
|
||||||
int delta = 0;
|
int delta = 0;
|
||||||
short direction = AllDirections[didx];
|
short direction = AllDirections[didx];
|
||||||
short reversedirection = AllDirections[(didx + 2) % 4];
|
short reversedirection = getReverseDirection(didx);
|
||||||
short pointingdirection = DIRECTION;
|
short pointingdirection = DIRECTION;
|
||||||
|
|
||||||
if (isFlagSet(direction,POSITIVE))
|
if (isFlagSet(direction,POSITIVE))
|
||||||
@@ -902,7 +954,7 @@ public class LabyModel implements WallsProvider
|
|||||||
|
|
||||||
if ((newx >= 0) && (newy >= 0) && (newx < width) && (newy < height))
|
if ((newx >= 0) && (newy >= 0) && (newx < width) && (newy < height))
|
||||||
{
|
{
|
||||||
return ((t[newx][newy] & reversedirection) != reversedirection);
|
return !isFlagSet(t[newx][newy],(short)reversedirection);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user