prepare for hand drawing with maze.

This commit is contained in:
philippe lhardy
2017-12-01 22:20:33 +01:00
parent eeb1172f88
commit 7deeb203ff
3 changed files with 37 additions and 2 deletions

View File

@@ -634,6 +634,7 @@ public class Display extends JFrame
final MazeCellParameters cp;
Position current = null;
LinkedList<DirectionPosition> solvedPath = null;
LinkedList<DirectionPosition> drawingPath = null;
final Object lockChange = new Object();
// current postion of human resolving
int sX = 0;
@@ -650,7 +651,23 @@ public class Display extends JFrame
// should find the cell ...
int pX = (int) ((double) (e.getX() - cp.getOffsetX()) / cp.getWidth());
int pY = (int) ((double) (e.getY() - cp.getOffsetY()) / cp.getHeight());
System.out.println("Mouse dragged Cell [" + pX + ',' + pY + ']');
Position newPosition = new Position(pX,pY);
if (drawingPath == null )
{
drawingPath = new LinkedList<>();
}
else
{
DirectionPosition last = drawingPath.getLast();
if ( last.getPosition().equals(newPosition))
{
// no move.
return;
}
// short path=computeMove(last,newPosition);
}
System.out.println("Mouse dragged Cell " + newPosition);
drawingPath.addLast(new DirectionPosition((short) 0,newPosition));
map.noWalls(pX,pY);
changed(null,null,map);
}

View File

@@ -643,7 +643,8 @@ public class LabyModel implements WallsProvider
{
rlistener.notifySearch(found);
}
break;
// support multiple pathes
// break;
}
}
}

View File

@@ -1,5 +1,6 @@
package org.artisanlogiciel.games;
/** position of a cell with maze */
public class Position
{
private int x, y;
@@ -38,4 +39,20 @@ public class Position
{
return "(" + x + "," + y + ")" + "/" + depth;
}
public boolean equals(Object other)
{
// disregards depth
if (other instanceof Position )
{
Position p = (Position) other;
return (p.getX() == x) && (p.getY() == y);
}
else
{
return false;
}
}
}