draging mouse with button pushed over maze clear walls
warning this break resolving ( endless => hang ) TO FIX.
This commit is contained in:
@@ -12,6 +12,8 @@ import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseMotionListener;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
@@ -69,8 +71,11 @@ public class Display extends JFrame
|
||||
}
|
||||
this.model = model;
|
||||
maze = createMazeComponent(model,W,H);
|
||||
|
||||
Container con = this.getContentPane();
|
||||
con.add(new JScrollPane(maze), BorderLayout.CENTER);
|
||||
JScrollPane scrollableMaze = new JScrollPane(maze);
|
||||
scrollableMaze.addMouseMotionListener(maze);
|
||||
con.add(scrollableMaze, BorderLayout.CENTER);
|
||||
controler = new MazeControler(params);
|
||||
con.add(controler.getMoveControl(), BorderLayout.NORTH);
|
||||
con.add(controler.getGenerationControl(), BorderLayout.SOUTH);
|
||||
@@ -572,11 +577,16 @@ public class Display extends JFrame
|
||||
|
||||
}
|
||||
|
||||
private static class MazeComponent extends JComponent implements MazeCreationListener, MazeResolutionListener
|
||||
private static class MazeComponent
|
||||
extends JComponent
|
||||
implements MazeCreationListener,
|
||||
MazeResolutionListener,
|
||||
MouseMotionListener
|
||||
{
|
||||
private static final long serialVersionUID = 3163272907991176390L;
|
||||
|
||||
WallsProvider map;
|
||||
// WallsProvider map;
|
||||
LabyModel map;
|
||||
final MazeCellParameters cp;
|
||||
Position current = null;
|
||||
LinkedList<Position> solvedPath = null;
|
||||
@@ -588,6 +598,21 @@ public class Display extends JFrame
|
||||
int gX = -1;
|
||||
int gY = -1;
|
||||
|
||||
@Override
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
// 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 + ']');
|
||||
map.noWalls(pX,pY);
|
||||
changed(null,null,map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseMoved(MouseEvent e) {
|
||||
System.out.println("Mouse moved (" + e.getX() + ',' + e.getY() + ')');
|
||||
}
|
||||
|
||||
void checkExit()
|
||||
{
|
||||
if ((sX == gX) && (sY == gY))
|
||||
@@ -659,7 +684,8 @@ public class Display extends JFrame
|
||||
width, height of one cell,
|
||||
offsetX, offsetY of upper left corner
|
||||
**/
|
||||
public MazeComponent(WallsProvider map, MazeCellParameters cp)
|
||||
// public MazeComponent(WallsProvider map, MazeCellParameters cp)
|
||||
public MazeComponent(LabyModel map, MazeCellParameters cp)
|
||||
{
|
||||
super();
|
||||
this.cp = cp;
|
||||
@@ -672,7 +698,8 @@ public class Display extends JFrame
|
||||
/**
|
||||
warning works only if new map has same dimensions than previous
|
||||
*/
|
||||
public void resetWallsProvider(WallsProvider map)
|
||||
// public void resetWallsProvider(WallsProvider map)
|
||||
public void resetWallsProvider(LabyModel map)
|
||||
{
|
||||
this.map = map;
|
||||
}
|
||||
@@ -782,6 +809,8 @@ public class Display extends JFrame
|
||||
}
|
||||
|
||||
g.setColor(Color.black);
|
||||
|
||||
// draw all walls within clip bounds horiz first then lines
|
||||
for (; pY < mY; pY++)
|
||||
{
|
||||
for (pX = 0; pX < mX; pX++)
|
||||
|
||||
@@ -61,6 +61,7 @@ public class LabyModel implements WallsProvider
|
||||
|
||||
private int width;
|
||||
private int height;
|
||||
// wall flags + status flags for each position (x,y)
|
||||
private short[][] t;
|
||||
private int depth = 0;
|
||||
/**
|
||||
@@ -114,6 +115,17 @@ public class LabyModel implements WallsProvider
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
// FIXME FULLY BREAK RESOLVING...
|
||||
public void noWalls(int x, int y)
|
||||
{
|
||||
if ((x > 0) && (x < width) && (y > 0) && (y < height))
|
||||
{
|
||||
// t[x][y] |= DIRECTION | VERTICAL | POSITIVE | HORIZONTAL | NEGATIVE | LEFT | RIGHT | UP | DOWN;
|
||||
t[x][y] |= DIRECTION | VERTICAL | POSITIVE | HORIZONTAL | NEGATIVE;
|
||||
t[x][y] |= LEFT | RIGHT | UP | DOWN;
|
||||
}
|
||||
}
|
||||
|
||||
// entry and exit can be outside the model boundaries a one x or one y out.
|
||||
public boolean addEntryOrExit(int x, int y)
|
||||
{
|
||||
@@ -395,6 +407,7 @@ public class LabyModel implements WallsProvider
|
||||
{
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
// resetCell(x,y);
|
||||
t[x][y] &= ~OPEN;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user