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.ActionListener;
|
||||||
import java.awt.event.ComponentAdapter;
|
import java.awt.event.ComponentAdapter;
|
||||||
import java.awt.event.ComponentEvent;
|
import java.awt.event.ComponentEvent;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.event.MouseMotionListener;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
@@ -69,8 +71,11 @@ public class Display extends JFrame
|
|||||||
}
|
}
|
||||||
this.model = model;
|
this.model = model;
|
||||||
maze = createMazeComponent(model,W,H);
|
maze = createMazeComponent(model,W,H);
|
||||||
|
|
||||||
Container con = this.getContentPane();
|
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);
|
controler = new MazeControler(params);
|
||||||
con.add(controler.getMoveControl(), BorderLayout.NORTH);
|
con.add(controler.getMoveControl(), BorderLayout.NORTH);
|
||||||
con.add(controler.getGenerationControl(), BorderLayout.SOUTH);
|
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;
|
private static final long serialVersionUID = 3163272907991176390L;
|
||||||
|
|
||||||
WallsProvider map;
|
// WallsProvider map;
|
||||||
|
LabyModel map;
|
||||||
final MazeCellParameters cp;
|
final MazeCellParameters cp;
|
||||||
Position current = null;
|
Position current = null;
|
||||||
LinkedList<Position> solvedPath = null;
|
LinkedList<Position> solvedPath = null;
|
||||||
@@ -588,6 +598,21 @@ public class Display extends JFrame
|
|||||||
int gX = -1;
|
int gX = -1;
|
||||||
int gY = -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()
|
void checkExit()
|
||||||
{
|
{
|
||||||
if ((sX == gX) && (sY == gY))
|
if ((sX == gX) && (sY == gY))
|
||||||
@@ -659,7 +684,8 @@ public class Display extends JFrame
|
|||||||
width, height of one cell,
|
width, height of one cell,
|
||||||
offsetX, offsetY of upper left corner
|
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();
|
super();
|
||||||
this.cp = cp;
|
this.cp = cp;
|
||||||
@@ -672,7 +698,8 @@ public class Display extends JFrame
|
|||||||
/**
|
/**
|
||||||
warning works only if new map has same dimensions than previous
|
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;
|
this.map = map;
|
||||||
}
|
}
|
||||||
@@ -782,6 +809,8 @@ public class Display extends JFrame
|
|||||||
}
|
}
|
||||||
|
|
||||||
g.setColor(Color.black);
|
g.setColor(Color.black);
|
||||||
|
|
||||||
|
// draw all walls within clip bounds horiz first then lines
|
||||||
for (; pY < mY; pY++)
|
for (; pY < mY; pY++)
|
||||||
{
|
{
|
||||||
for (pX = 0; pX < mX; pX++)
|
for (pX = 0; pX < mX; pX++)
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ public class LabyModel implements WallsProvider
|
|||||||
|
|
||||||
private int width;
|
private int width;
|
||||||
private int height;
|
private int height;
|
||||||
|
// wall flags + status flags for each position (x,y)
|
||||||
private short[][] t;
|
private short[][] t;
|
||||||
private int depth = 0;
|
private int depth = 0;
|
||||||
/**
|
/**
|
||||||
@@ -114,6 +115,17 @@ public class LabyModel implements WallsProvider
|
|||||||
this.listener = listener;
|
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.
|
// 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)
|
||||||
{
|
{
|
||||||
@@ -395,6 +407,7 @@ public class LabyModel implements WallsProvider
|
|||||||
{
|
{
|
||||||
for (int x = 0; x < width; x++)
|
for (int x = 0; x < width; x++)
|
||||||
{
|
{
|
||||||
|
// resetCell(x,y);
|
||||||
t[x][y] &= ~OPEN;
|
t[x][y] &= ~OPEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user