create lab directory in parent

abstract MazeParams to be able to set them easily
doit.sh support new class creation
updated README

Signed-off-by: philippe lhardy <philippe@pavilionartlogiciel>
This commit is contained in:
philippe lhardy
2015-02-18 21:06:37 +01:00
parent 894e5c7970
commit 7d8ce42c15
5 changed files with 151 additions and 23 deletions

View File

@@ -82,6 +82,66 @@ public class Display extends JFrame
maze.setWallSize(size);
}
private static class MazeParamEditor
implements MazeParams
{
int width;
int height;
int maxdepth;
File labdir;
String name;
public MazeParamEditor()
{
name=null;
labdir = new File("lab");
}
public MazeParamEditor(File saveDir)
{
name=null;
labdir = saveDir;
}
public void consoleRead()
{
Scanner console = new Scanner(System.in);
width = console.nextInt();
height = console.nextInt();
maxdepth = console.nextInt();
}
public int getWidth()
{
return width;
}
public int getHeight()
{
return height;
}
public int getMaxDepth()
{
return maxdepth;
}
public String getName()
{
if (name == null)
{
name="lab" + width + "x" + height;
}
return name;
}
public File getSaveDir()
{
return labdir;
}
}
private class MazeControler extends JPanel
{
public MazeControler()
@@ -466,14 +526,12 @@ public class Display extends JFrame
}
else
{
System.out.println("enter width height and maxdepth");
Scanner console = new Scanner(System.in);
int width = console.nextInt();
int height = console.nextInt();
int maxdepth = console.nextInt();
model = new LabyModel(width, height,maxdepth, new java.util.Random());
int w = W / width;
int h = H / height;
System.out.println("enter width height and maxdepth");
MazeParamEditor params = new MazeParamEditor();
params.consoleRead();
model = new LabyModel(params, new java.util.Random());
int w = W / params.getWidth();
int h = H / params.getHeight();
if ( w < 5 ) w = 5;
if ( h < 5 ) h = 5;
MazeComponent comp = new MazeComponent(model,w,h,3,3);
@@ -486,10 +544,9 @@ public class Display extends JFrame
model.generateWithEntry(0, 0);
LinkedList<Position> exits = new LinkedList<Position>();
model.addEntryOrExit(-1,0);
model.addEntryOrExit(width,height -1);
model.addEntryOrExit(params.getWidth(),params.getHeight() -1);
System.out.println("Generation completed");
String name="lab" + width + "x" + height;
File outfile = new File(new File("lab"), name + ".raw");
File outfile = new File(params.getSaveDir(), params.getName() + ".raw");
if ( ! outfile.exists())
{
System.out.println( "Saving to " + outfile + " ...");
@@ -508,13 +565,13 @@ public class Display extends JFrame
else {
System.out.println( "" + outfile + " already exists");
}
outfile = new File(new File("lab"),name + ".stl");
outfile = new File(params.getSaveDir(), params.getName() + ".stl");
if ( ! outfile.exists())
{
System.out.println( "Saving to " + outfile + " ...");
try {
FileOutputStream out = new FileOutputStream(outfile);
Wall3d.streamWallsOut(name,(WallsProvider) model,out);
Wall3d.streamWallsOut(params.getName(),(WallsProvider) model,out);
out.flush();
out.close();
System.out.println( "... Done.");

View File

@@ -74,6 +74,15 @@ implements WallsProvider
t= new short[width][height];
}
public LabyModel(MazeParams params, Random random){
this.width=params.getWidth();
this.height=params.getHeight();
this.maxdepth=params.getMaxDepth();
this.random = random;
// CLEAR == 0 and array is initialized with 0s
t= new short[width][height];
}
public LabyModel(String pFormat, InputStream pIn)
throws IOException
{

View File

@@ -0,0 +1,24 @@
package org.artisanlogiciel.games;
import java.io.File;
/**
MazeParams was autogenerated by ./generate_newclass.sh
**/
public interface MazeParams
{
public int getWidth();
public int getHeight();
public int getMaxDepth();
/**
@return name of Maze, used for creating filename at saving time
*/
public String getName();
/**
@return directory owning where to save a maze
*/
public File getSaveDir();
}