some eclipse stuff
provide artlogjavaformat to reformat code
This commit is contained in:
23
artlogjavaformat.epf
Normal file
23
artlogjavaformat.epf
Normal file
File diff suppressed because one or more lines are too long
3
devenv_params
Normal file
3
devenv_params
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
DEV_ENV=~/artisanlogiciel/devel_tools
|
||||||
|
JDK_PATH=~/artisanlogiciel/devel_tools/jdk1.8.0_74
|
||||||
|
ECLIPSE_PATH=~/artisanlogiciel/devel_tools/eclipse
|
||||||
7
java/.classpath
Normal file
7
java/.classpath
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="src" path=""/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.fx.ide.jdt.core.JAVAFX_CONTAINER"/>
|
||||||
|
<classpathentry kind="output" path=""/>
|
||||||
|
</classpath>
|
||||||
23
java/.project
Normal file
23
java/.project
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>Karmazoff</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
||||||
@@ -2,19 +2,21 @@ package org.artisanlogiciel.games;
|
|||||||
|
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
import java.awt.Container;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Container;
|
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
import javax.swing.Action;
|
|
||||||
import javax.swing.AbstractAction;
|
import javax.swing.AbstractAction;
|
||||||
import javax.swing.event.ChangeEvent;
|
import javax.swing.Action;
|
||||||
import javax.swing.event.ChangeListener;
|
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
@@ -22,19 +24,17 @@ import javax.swing.JPanel;
|
|||||||
import javax.swing.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.JSlider;
|
import javax.swing.JSlider;
|
||||||
import javax.swing.KeyStroke;
|
import javax.swing.KeyStroke;
|
||||||
|
import javax.swing.event.ChangeEvent;
|
||||||
import java.io.File;
|
import javax.swing.event.ChangeListener;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Display
|
* Display
|
||||||
**/
|
**/
|
||||||
public class Display extends JFrame
|
public class Display extends JFrame
|
||||||
|
|
||||||
{
|
{
|
||||||
Object param;
|
// to please eclipse, not supposed to be serialized
|
||||||
|
private static final long serialVersionUID = 8500214871372184418L;
|
||||||
|
|
||||||
MazeComponent maze;
|
MazeComponent maze;
|
||||||
MazeControler controler;
|
MazeControler controler;
|
||||||
LabyModel model;
|
LabyModel model;
|
||||||
@@ -43,18 +43,17 @@ public class Display extends JFrame
|
|||||||
Display(LabyModel model, MazeComponent comp)
|
Display(LabyModel model, MazeComponent comp)
|
||||||
{
|
{
|
||||||
super("Maze display");
|
super("Maze display");
|
||||||
maze=comp;
|
maze = comp;
|
||||||
this.param=param;
|
this.model = model;
|
||||||
this.model=model;
|
|
||||||
Container con = this.getContentPane();
|
Container con = this.getContentPane();
|
||||||
con.add(new JScrollPane(comp), BorderLayout.CENTER);
|
con.add(new JScrollPane(comp), BorderLayout.CENTER);
|
||||||
controler = new MazeControler();
|
controler = new MazeControler();
|
||||||
con.add(controler,BorderLayout.NORTH);
|
con.add(controler, BorderLayout.NORTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
void resolve()
|
void resolve()
|
||||||
{
|
{
|
||||||
model.resolve(model.getWidth()-1,model.getHeight()-1,maze);
|
model.resolve(model.getWidth() - 1, model.getHeight() - 1, maze);
|
||||||
}
|
}
|
||||||
|
|
||||||
void goNorth()
|
void goNorth()
|
||||||
@@ -82,8 +81,7 @@ public class Display extends JFrame
|
|||||||
maze.setWallSize(size);
|
maze.setWallSize(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class MazeParamEditor
|
private static class MazeParamEditor implements MazeParams
|
||||||
implements MazeParams
|
|
||||||
{
|
{
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
@@ -91,21 +89,14 @@ public class Display extends JFrame
|
|||||||
File labdir;
|
File labdir;
|
||||||
String name;
|
String name;
|
||||||
|
|
||||||
public MazeParamEditor()
|
|
||||||
{
|
|
||||||
name=null;
|
|
||||||
labdir = new File("lab");
|
|
||||||
}
|
|
||||||
|
|
||||||
public MazeParamEditor(File saveDir)
|
public MazeParamEditor(File saveDir)
|
||||||
{
|
{
|
||||||
name=null;
|
name = null;
|
||||||
labdir = saveDir;
|
labdir = saveDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void consoleRead()
|
public void read(Scanner console)
|
||||||
{
|
{
|
||||||
Scanner console = new Scanner(System.in);
|
|
||||||
width = console.nextInt();
|
width = console.nextInt();
|
||||||
height = console.nextInt();
|
height = console.nextInt();
|
||||||
maxdepth = console.nextInt();
|
maxdepth = console.nextInt();
|
||||||
@@ -130,7 +121,7 @@ public class Display extends JFrame
|
|||||||
{
|
{
|
||||||
if (name == null)
|
if (name == null)
|
||||||
{
|
{
|
||||||
name="lab" + width + "x" + height;
|
name = "lab" + width + "x" + height;
|
||||||
}
|
}
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
@@ -139,16 +130,21 @@ public class Display extends JFrame
|
|||||||
{
|
{
|
||||||
return labdir;
|
return labdir;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class MazeControler extends JPanel
|
private class MazeControler extends JPanel
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
public MazeControler()
|
public MazeControler()
|
||||||
{
|
{
|
||||||
controlPanel = new JPanel();
|
controlPanel = new JPanel();
|
||||||
JButton button=new JButton("Resolve");
|
JButton button = new JButton("Resolve");
|
||||||
button.addActionListener(new ActionListener() {
|
button.addActionListener(new ActionListener()
|
||||||
|
{
|
||||||
public void actionPerformed(ActionEvent evt)
|
public void actionPerformed(ActionEvent evt)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -157,6 +153,7 @@ public class Display extends JFrame
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@SuppressWarnings("serial")
|
||||||
Action goNorth = new AbstractAction()
|
Action goNorth = new AbstractAction()
|
||||||
{
|
{
|
||||||
public void actionPerformed(ActionEvent evt)
|
public void actionPerformed(ActionEvent evt)
|
||||||
@@ -166,9 +163,11 @@ public class Display extends JFrame
|
|||||||
goNorth();
|
goNorth();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
JButton north = addDirection(this,"North", "UP", goNorth);
|
JButton north = addDirection(this, "North", "UP", goNorth);
|
||||||
|
|
||||||
Action goEast = new AbstractAction() {
|
@SuppressWarnings("serial")
|
||||||
|
Action goEast = new AbstractAction()
|
||||||
|
{
|
||||||
public void actionPerformed(ActionEvent evt)
|
public void actionPerformed(ActionEvent evt)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -176,10 +175,12 @@ public class Display extends JFrame
|
|||||||
goEast();
|
goEast();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
JButton east = addDirection(this,"East", "RIGHT", goEast);
|
|
||||||
|
|
||||||
|
JButton east = addDirection(this, "East", "RIGHT", goEast);
|
||||||
|
|
||||||
Action goWest = new AbstractAction() {
|
@SuppressWarnings("serial")
|
||||||
|
Action goWest = new AbstractAction()
|
||||||
|
{
|
||||||
public void actionPerformed(ActionEvent evt)
|
public void actionPerformed(ActionEvent evt)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -187,9 +188,11 @@ public class Display extends JFrame
|
|||||||
goWest();
|
goWest();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
JButton west = addDirection(this,"West", "LEFT", goWest);
|
JButton west = addDirection(this, "West", "LEFT", goWest);
|
||||||
|
|
||||||
Action goSouth = new AbstractAction() {
|
@SuppressWarnings("serial")
|
||||||
|
Action goSouth = new AbstractAction()
|
||||||
|
{
|
||||||
public void actionPerformed(ActionEvent evt)
|
public void actionPerformed(ActionEvent evt)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -197,22 +200,23 @@ public class Display extends JFrame
|
|||||||
goSouth();
|
goSouth();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
JButton south = addDirection(this,"South", "DOWN", goSouth);
|
JButton south = addDirection(this, "South", "DOWN", goSouth);
|
||||||
|
|
||||||
add(button,BorderLayout.CENTER);
|
add(button, BorderLayout.CENTER);
|
||||||
controlPanel.add(north,BorderLayout.NORTH);
|
controlPanel.add(north, BorderLayout.NORTH);
|
||||||
controlPanel.add(west,BorderLayout.WEST);
|
controlPanel.add(west, BorderLayout.WEST);
|
||||||
controlPanel.add(east,BorderLayout.EAST);
|
controlPanel.add(east, BorderLayout.EAST);
|
||||||
controlPanel.add(south,BorderLayout.SOUTH);
|
controlPanel.add(south, BorderLayout.SOUTH);
|
||||||
add(controlPanel,BorderLayout.NORTH);
|
add(controlPanel, BorderLayout.NORTH);
|
||||||
final JSlider slider=new JSlider(2,40);
|
final JSlider slider = new JSlider(2, 40);
|
||||||
slider.addChangeListener(new ChangeListener() {
|
slider.addChangeListener(new ChangeListener()
|
||||||
|
{
|
||||||
public void stateChanged(ChangeEvent e)
|
public void stateChanged(ChangeEvent e)
|
||||||
{
|
{
|
||||||
setWallSize(slider.getValue());
|
setWallSize(slider.getValue());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
add(slider,BorderLayout.EAST);
|
add(slider, BorderLayout.EAST);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -222,18 +226,18 @@ public class Display extends JFrame
|
|||||||
String actionName = "go" + direction;
|
String actionName = "go" + direction;
|
||||||
JButton button = new JButton(direction);
|
JButton button = new JButton(direction);
|
||||||
button.addActionListener(goAction);
|
button.addActionListener(goAction);
|
||||||
KeyStroke keystroke=KeyStroke.getKeyStroke(key);
|
KeyStroke keystroke = KeyStroke.getKeyStroke(key);
|
||||||
panel.getInputMap().put(keystroke,actionName);
|
panel.getInputMap().put(keystroke, actionName);
|
||||||
panel.getActionMap().put(actionName,goAction);
|
panel.getActionMap().put(actionName, goAction);
|
||||||
controlPanel.getInputMap().put(keystroke,actionName);
|
controlPanel.getInputMap().put(keystroke, actionName);
|
||||||
controlPanel.getActionMap().put(actionName,goAction);
|
controlPanel.getActionMap().put(actionName, goAction);
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class MazeComponent extends JComponent
|
private static class MazeComponent extends JComponent implements MazeCreationListener, MazeResolutionListener
|
||||||
implements MazeCreationListener,
|
|
||||||
MazeResolutionListener
|
|
||||||
{
|
{
|
||||||
|
private static final long serialVersionUID = 3163272907991176390L;
|
||||||
|
|
||||||
WallsProvider map;
|
WallsProvider map;
|
||||||
int width = 10;
|
int width = 10;
|
||||||
int height = 10;
|
int height = 10;
|
||||||
@@ -256,12 +260,13 @@ public class Display extends JFrame
|
|||||||
System.out.println("Exit found by human !");
|
System.out.println("Exit found by human !");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void goNorth()
|
void goNorth()
|
||||||
{
|
{
|
||||||
resetResolution();
|
resetResolution();
|
||||||
if ( (map.getWalls(sX,sY) & Brick.UP) == 0 )
|
if ((map.getWalls(sX, sY) & Brick.UP) == 0)
|
||||||
{
|
{
|
||||||
sY = sY -1;
|
sY = sY - 1;
|
||||||
// should redraw ...
|
// should redraw ...
|
||||||
invalidate();
|
invalidate();
|
||||||
repaint();
|
repaint();
|
||||||
@@ -274,9 +279,9 @@ public class Display extends JFrame
|
|||||||
void goSouth()
|
void goSouth()
|
||||||
{
|
{
|
||||||
resetResolution();
|
resetResolution();
|
||||||
if ( (map.getWalls(sX,sY) & Brick.DOWN) == 0 )
|
if ((map.getWalls(sX, sY) & Brick.DOWN) == 0)
|
||||||
{
|
{
|
||||||
sY =sY + 1;
|
sY = sY + 1;
|
||||||
// should redraw ...
|
// should redraw ...
|
||||||
invalidate();
|
invalidate();
|
||||||
repaint();
|
repaint();
|
||||||
@@ -289,7 +294,7 @@ public class Display extends JFrame
|
|||||||
void goEast()
|
void goEast()
|
||||||
{
|
{
|
||||||
resetResolution();
|
resetResolution();
|
||||||
if ( (map.getWalls(sX,sY) & Brick.RIGHT) == 0 )
|
if ((map.getWalls(sX, sY) & Brick.RIGHT) == 0)
|
||||||
{
|
{
|
||||||
sX = sX + 1;
|
sX = sX + 1;
|
||||||
// should redraw ...
|
// should redraw ...
|
||||||
@@ -303,7 +308,7 @@ public class Display extends JFrame
|
|||||||
void goWest()
|
void goWest()
|
||||||
{
|
{
|
||||||
resetResolution();
|
resetResolution();
|
||||||
if ( (map.getWalls(sX,sY) & Brick.LEFT) == 0 )
|
if ((map.getWalls(sX, sY) & Brick.LEFT) == 0)
|
||||||
{
|
{
|
||||||
sX = sX - 1;
|
sX = sX - 1;
|
||||||
// should redraw ...
|
// should redraw ...
|
||||||
@@ -318,22 +323,22 @@ public class Display extends JFrame
|
|||||||
public MazeComponent(WallsProvider map, int width, int height, int offsetX, int offsetY)
|
public MazeComponent(WallsProvider map, int width, int height, int offsetX, int offsetY)
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
this.map=map;
|
this.map = map;
|
||||||
this.width=width;
|
this.width = width;
|
||||||
this.height=height;
|
this.height = height;
|
||||||
this.offsetX=offsetX;
|
this.offsetX = offsetX;
|
||||||
this.offsetY=offsetY;
|
this.offsetY = offsetY;
|
||||||
setPreferredSize(new Dimension(1+2*offsetX+map.getWidth()*width,
|
setPreferredSize(new Dimension(1 + 2 * offsetX + map.getWidth() * width,
|
||||||
1+2*offsetY+map.getHeight()*height));
|
1 + 2 * offsetY + map.getHeight() * height));
|
||||||
gX = map.getWidth() -1;
|
gX = map.getWidth() - 1;
|
||||||
gY = map.getHeight() -1;
|
gY = map.getHeight() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWallSize(int size)
|
public void setWallSize(int size)
|
||||||
{
|
{
|
||||||
|
|
||||||
width=size;
|
width = size;
|
||||||
height=size;
|
height = size;
|
||||||
// should redraw ...
|
// should redraw ...
|
||||||
invalidate();
|
invalidate();
|
||||||
repaint();
|
repaint();
|
||||||
@@ -345,12 +350,13 @@ public class Display extends JFrame
|
|||||||
invalidate();
|
invalidate();
|
||||||
repaint();
|
repaint();
|
||||||
Object waiter = new Object();
|
Object waiter = new Object();
|
||||||
synchronized(waiter)
|
synchronized (waiter)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
try {
|
|
||||||
waiter.wait(10);
|
waiter.wait(10);
|
||||||
}
|
}
|
||||||
catch( InterruptedException e)
|
catch (InterruptedException e)
|
||||||
{
|
{
|
||||||
System.err.println("Interrupted !");
|
System.err.println("Interrupted !");
|
||||||
}
|
}
|
||||||
@@ -359,47 +365,56 @@ public class Display extends JFrame
|
|||||||
|
|
||||||
private void drawWalls(Graphics g, int x, int y, short walls, boolean full)
|
private void drawWalls(Graphics g, int x, int y, short walls, boolean full)
|
||||||
{
|
{
|
||||||
if ( (full) && (( walls & Brick.UP ) == Brick.UP )) g.drawLine(x, y, x+width, y);
|
if ((full) && ((walls & Brick.UP) == Brick.UP))
|
||||||
if ( ( walls & Brick.DOWN ) == Brick.DOWN ) g.drawLine(x, y+height, x+width, y+height);
|
g.drawLine(x, y, x + width, y);
|
||||||
if ( ( walls & Brick.RIGHT ) == Brick.RIGHT ) g.drawLine(x+width, y, x+width, y+height);
|
if ((walls & Brick.DOWN) == Brick.DOWN)
|
||||||
if ( (full) && (( walls & Brick.LEFT ) == Brick.LEFT )) g.drawLine(x, y, x, y+height);
|
g.drawLine(x, y + height, x + width, y + height);
|
||||||
|
if ((walls & Brick.RIGHT) == Brick.RIGHT)
|
||||||
|
g.drawLine(x + width, y, x + width, y + height);
|
||||||
|
if ((full) && ((walls & Brick.LEFT) == Brick.LEFT))
|
||||||
|
g.drawLine(x, y, x, y + height);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintComponent(Graphics g) {
|
protected void paintComponent(Graphics g)
|
||||||
|
{
|
||||||
super.paintComponent(g);
|
super.paintComponent(g);
|
||||||
int x = 0;
|
int x = 0;
|
||||||
int y = 0;
|
int y = 0;
|
||||||
short walls=0;
|
short walls = 0;
|
||||||
|
|
||||||
// try to display only visible part...
|
// try to display only visible part...
|
||||||
// should compute pX, pY, mX, mY based on clip...
|
// should compute pX, pY, mX, mY based on clip...
|
||||||
// Shape s=g.getClip();
|
// Shape s=g.getClip();
|
||||||
Rectangle r= g.getClipBounds();
|
Rectangle r = g.getClipBounds();
|
||||||
|
|
||||||
int mX = (int) ( (double) r.getWidth() / width);
|
int mX = (int) ((double) r.getWidth() / width);
|
||||||
int mY = (int) ( (double) r.getHeight() / height);
|
int mY = (int) ((double) r.getHeight() / height);
|
||||||
int pX = (int) ( (double) (r.getX() - offsetX) / width);
|
int pX = (int) ((double) (r.getX() - offsetX) / width);
|
||||||
int pY = (int) ( (double) (r.getY() - offsetY) / height);
|
int pY = (int) ((double) (r.getY() - offsetY) / height);
|
||||||
|
|
||||||
if ( pX < 0) pX = 0;
|
if (pX < 0)
|
||||||
if ( pY < 0) pY = 0;
|
pX = 0;
|
||||||
if ( pX >= map.getWidth()) return;
|
if (pY < 0)
|
||||||
if ( pY >= map.getHeight()) return;
|
pY = 0;
|
||||||
|
if (pX >= map.getWidth())
|
||||||
|
return;
|
||||||
|
if (pY >= map.getHeight())
|
||||||
|
return;
|
||||||
|
|
||||||
mX=mX+pX;
|
mX = mX + pX;
|
||||||
mY=mY+pY;
|
mY = mY + pY;
|
||||||
|
|
||||||
if ( mX > map.getWidth() )
|
if (mX > map.getWidth())
|
||||||
{
|
{
|
||||||
mX = map.getWidth();
|
mX = map.getWidth();
|
||||||
}
|
}
|
||||||
if ( mY > map.getHeight())
|
if (mY > map.getHeight())
|
||||||
{
|
{
|
||||||
mY = map.getHeight();
|
mY = map.getHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((sX == gX ) && (sY == gY ))
|
if ((sX == gX) && (sY == gY))
|
||||||
{
|
{
|
||||||
g.setColor(Color.red);
|
g.setColor(Color.red);
|
||||||
}
|
}
|
||||||
@@ -407,62 +422,62 @@ public class Display extends JFrame
|
|||||||
{
|
{
|
||||||
g.setColor(Color.blue);
|
g.setColor(Color.blue);
|
||||||
}
|
}
|
||||||
drawDot(g,new Position(sX,sY),pX,pY,mX,mY);
|
drawDot(g, new Position(sX, sY), pX, pY, mX, mY);
|
||||||
|
|
||||||
synchronized(lockChange)
|
synchronized (lockChange)
|
||||||
{
|
{
|
||||||
g.setColor(Color.red);
|
g.setColor(Color.red);
|
||||||
if ( current != null)
|
if (current != null)
|
||||||
{
|
{
|
||||||
drawDot(g,current,pX,pY,mX,mY);
|
drawDot(g, current, pX, pY, mX, mY);
|
||||||
}
|
}
|
||||||
if (solvedPath != null)
|
if (solvedPath != null)
|
||||||
{
|
{
|
||||||
for ( Position resolved : solvedPath )
|
for (Position resolved : solvedPath)
|
||||||
{
|
{
|
||||||
drawDot(g,resolved,pX,pY,mX,mY);
|
drawDot(g, resolved, pX, pY, mX, mY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g.setColor(Color.black);
|
g.setColor(Color.black);
|
||||||
for ( ; pY < mY ; pY ++)
|
for (; pY < mY; pY++)
|
||||||
{
|
{
|
||||||
for ( pX = 0; pX < mX ; pX ++)
|
for (pX = 0; pX < mX; pX++)
|
||||||
{
|
{
|
||||||
x=offsetX+pX*width;
|
x = offsetX + pX * width;
|
||||||
y=offsetY+pY*height;
|
y = offsetY + pY * height;
|
||||||
walls = map.getWalls(pX,pY);
|
walls = map.getWalls(pX, pY);
|
||||||
drawWalls(g,x,y,walls,(pX == 0) || (pY==0));
|
drawWalls(g, x, y, walls, (pX == 0) || (pY == 0));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawDot(Graphics g,Position dot, int pX, int pY, int mX, int mY)
|
private void drawDot(Graphics g, Position dot, int pX, int pY, int mX, int mY)
|
||||||
{
|
{
|
||||||
int radius = ( height > width ) ? width : height;
|
int radius = (height > width) ? width : height;
|
||||||
int a = radius / 4;
|
int a = radius / 4;
|
||||||
if (( dot.getX() >= pX ) && ( dot.getY() >= pY ) && ( dot.getX() < mX ) && ( dot.getY() < mY ) )
|
if ((dot.getX() >= pX) && (dot.getY() >= pY) && (dot.getX() < mX) && (dot.getY() < mY))
|
||||||
{
|
{
|
||||||
int x=offsetX+dot.getX()*width;
|
int x = offsetX + dot.getX() * width;
|
||||||
int y=offsetY+dot.getY()*height;
|
int y = offsetY + dot.getY() * height;
|
||||||
g.drawOval(x+1,y+1,radius-a,radius-a);
|
g.drawOval(x + 1, y + 1, radius - a, radius - a);
|
||||||
//g.drawLine(x+a,y+a,x+width-a,y+height-a);
|
// g.drawLine(x+a,y+a,x+width-a,y+height-a);
|
||||||
//g.drawLine(x+a,y+height-a,x+width-a,y+a);
|
// g.drawLine(x+a,y+height-a,x+width-a,y+a);
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int x=offsetX+pX*width;
|
int x = offsetX + pX * width;
|
||||||
int y=offsetY+pY*height;
|
int y = offsetY + pY * height;
|
||||||
g.drawLine(x+1,y+1,x+width-1,y+height-1);
|
g.drawLine(x + 1, y + 1, x + width - 1, y + height - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean notifySearch(Position pPosition)
|
public boolean notifySearch(Position pPosition)
|
||||||
{
|
{
|
||||||
synchronized(lockChange)
|
synchronized (lockChange)
|
||||||
{
|
{
|
||||||
current = pPosition;
|
current = pPosition;
|
||||||
}
|
}
|
||||||
@@ -480,9 +495,9 @@ public class Display extends JFrame
|
|||||||
|
|
||||||
public void notifyCompletion(LinkedList<Position> solvedPath)
|
public void notifyCompletion(LinkedList<Position> solvedPath)
|
||||||
{
|
{
|
||||||
LinkedList<Position> newPath = (LinkedList<Position>) solvedPath.clone();
|
LinkedList<Position> newPath = new LinkedList<>(solvedPath);
|
||||||
System.out.println("resolution completed");
|
System.out.println("resolution completed");
|
||||||
synchronized(lockChange)
|
synchronized (lockChange)
|
||||||
{
|
{
|
||||||
this.solvedPath = newPath;
|
this.solvedPath = newPath;
|
||||||
}
|
}
|
||||||
@@ -503,10 +518,11 @@ public class Display extends JFrame
|
|||||||
int W = 600;
|
int W = 600;
|
||||||
int H = 400;
|
int H = 400;
|
||||||
|
|
||||||
if ( pArgs.length > 0 )
|
if (pArgs.length > 0)
|
||||||
{
|
{
|
||||||
try {
|
try
|
||||||
model = new LabyModel("raw",new FileInputStream(pArgs[0]));
|
{
|
||||||
|
model = new LabyModel("raw", new FileInputStream(pArgs[0]));
|
||||||
}
|
}
|
||||||
catch (IOException io)
|
catch (IOException io)
|
||||||
{
|
{
|
||||||
@@ -515,74 +531,82 @@ public class Display extends JFrame
|
|||||||
|
|
||||||
int w = W / model.getWidth();
|
int w = W / model.getWidth();
|
||||||
int h = H / model.getHeight();
|
int h = H / model.getHeight();
|
||||||
if ( w < 5 ) w = 5;
|
if (w < 5)
|
||||||
if ( h < 5 ) h = 5;
|
w = 5;
|
||||||
MazeComponent comp = new MazeComponent(model,w,h,3,3);
|
if (h < 5)
|
||||||
Display display=new Display(model, comp);
|
h = 5;
|
||||||
|
MazeComponent comp = new MazeComponent(model, w, h, 3, 3);
|
||||||
|
Display display = new Display(model, comp);
|
||||||
model.setMazeListener(comp);
|
model.setMazeListener(comp);
|
||||||
display.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
display.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
display.setBounds(W,H,W,H);
|
display.setBounds(W, H, W, H);
|
||||||
display.setVisible(true);
|
display.setVisible(true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.out.println("enter width height and maxdepth");
|
System.out.println("enter width height and maxdepth");
|
||||||
MazeParamEditor params = new MazeParamEditor();
|
MazeParamEditor params = new MazeParamEditor(new File("lab"));
|
||||||
params.consoleRead();
|
params.read(new Scanner(System.in));
|
||||||
model = new LabyModel(params, new java.util.Random());
|
model = new LabyModel(params, new java.util.Random());
|
||||||
int w = W / params.getWidth();
|
int w = W / params.getWidth();
|
||||||
int h = H / params.getHeight();
|
int h = H / params.getHeight();
|
||||||
if ( w < 5 ) w = 5;
|
if (w < 5)
|
||||||
if ( h < 5 ) h = 5;
|
w = 5;
|
||||||
MazeComponent comp = new MazeComponent(model,w,h,3,3);
|
if (h < 5)
|
||||||
Display display=new Display(model,comp);
|
h = 5;
|
||||||
|
MazeComponent comp = new MazeComponent(model, w, h, 3, 3);
|
||||||
|
Display display = new Display(model, comp);
|
||||||
model.setMazeListener(comp);
|
model.setMazeListener(comp);
|
||||||
display.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
display.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
display.setBounds(W,H,W,H);
|
display.setBounds(W, H, W, H);
|
||||||
display.setVisible(true);
|
display.setVisible(true);
|
||||||
|
|
||||||
model.generateWithEntry(0, 0);
|
model.generateWithEntry(0, 0);
|
||||||
LinkedList<Position> exits = new LinkedList<Position>();
|
|
||||||
model.addEntryOrExit(-1,0);
|
model.addEntryOrExit(-1, 0);
|
||||||
model.addEntryOrExit(params.getWidth(),params.getHeight() -1);
|
model.addEntryOrExit(params.getWidth(), params.getHeight() - 1);
|
||||||
System.out.println("Generation completed");
|
System.out.println("Generation completed");
|
||||||
File outfile = new File(params.getSaveDir(), params.getName() + ".raw");
|
File outfile = new File(params.getSaveDir(), params.getName() + ".raw");
|
||||||
if ( ! outfile.exists())
|
if (!outfile.exists())
|
||||||
|
{
|
||||||
|
System.out.println("Saving to " + outfile + " ...");
|
||||||
|
try
|
||||||
{
|
{
|
||||||
System.out.println( "Saving to " + outfile + " ...");
|
|
||||||
try {
|
|
||||||
FileOutputStream out = new FileOutputStream(outfile);
|
FileOutputStream out = new FileOutputStream(outfile);
|
||||||
model.streamOut("raw",out);
|
model.streamOut("raw", out);
|
||||||
out.flush();
|
out.flush();
|
||||||
out.close();
|
out.close();
|
||||||
System.out.println( "... Done.");
|
System.out.println("... Done.");
|
||||||
}
|
}
|
||||||
catch (IOException io)
|
catch (IOException io)
|
||||||
{
|
{
|
||||||
io.printStackTrace(System.err);
|
io.printStackTrace(System.err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
System.out.println( "" + outfile + " already exists");
|
{
|
||||||
|
System.out.println("" + outfile + " already exists");
|
||||||
}
|
}
|
||||||
outfile = new File(params.getSaveDir(), params.getName() + ".stl");
|
outfile = new File(params.getSaveDir(), params.getName() + ".stl");
|
||||||
if ( ! outfile.exists())
|
if (!outfile.exists())
|
||||||
|
{
|
||||||
|
System.out.println("Saving to " + outfile + " ...");
|
||||||
|
try
|
||||||
{
|
{
|
||||||
System.out.println( "Saving to " + outfile + " ...");
|
|
||||||
try {
|
|
||||||
FileOutputStream out = new FileOutputStream(outfile);
|
FileOutputStream out = new FileOutputStream(outfile);
|
||||||
Wall3d.streamWallsOut(params.getName(),(WallsProvider) model,out);
|
Wall3d.streamWallsOut(params.getName(), (WallsProvider) model, out);
|
||||||
out.flush();
|
out.flush();
|
||||||
out.close();
|
out.close();
|
||||||
System.out.println( "... Done.");
|
System.out.println("... Done.");
|
||||||
}
|
}
|
||||||
catch (IOException io)
|
catch (IOException io)
|
||||||
{
|
{
|
||||||
io.printStackTrace(System.err);
|
io.printStackTrace(System.err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
System.out.println( "" + outfile + " already exists");
|
{
|
||||||
|
System.out.println("" + outfile + " already exists");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user