From 7d8ce42c156883912c039a68d80f0387eb80fbe8 Mon Sep 17 00:00:00 2001 From: philippe lhardy Date: Wed, 18 Feb 2015 21:06:37 +0100 Subject: [PATCH] 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 --- README | 24 ++++-- doit.sh | 34 +++++++- java/org/artisanlogiciel/games/Display.java | 83 ++++++++++++++++--- java/org/artisanlogiciel/games/LabyModel.java | 9 ++ .../org/artisanlogiciel/games/MazeParams.java | 24 ++++++ 5 files changed, 151 insertions(+), 23 deletions(-) create mode 100644 java/org/artisanlogiciel/games/MazeParams.java diff --git a/README b/README index d6e8217..49aa30a 100644 --- a/README +++ b/README @@ -1,3 +1,4 @@ + This is a personal project to generate a 2D maze using in depth path generation. this can generate a stl file, overall goal was to print it with a 3D printer, i didn't test it yet ( even if i actualy have a 3D printer ). @@ -10,10 +11,18 @@ there is a console gui menu base with ./doit.sh run it by : -cd java -make display -( it will compile and run it ). -it ask fro three integers : +________Linux distribution_____________________ + +mkdir github +cd github +git clone https://github.com/artlog/labystl.git +cd labystl.git +./doit.sh +ant +run +_______________________________________________ + +it ask for three integers : X Y maxpath @@ -23,9 +32,11 @@ ex : will generate a 10x10 labyrinth with trying to fork a different path every 7 steps. -then it saves labyrinth under java/lab directory under two format : +then it saves labyrinth under lab or java/lab (depending if run or test respectively) directory under two format : - one reusable by this tool that contains all solutions. ( .lab ) -- one in stl that can be viewed with blender or sliced with slic3r to feed a 3D printer ( not yet tested ). +- one in stl that can : + - be viewed with blender + - or sliced with slic3r to feed a 3D printer ( not yet tested ). buttons left,right,up,left can be used to walk the labyrinth. resolve will display solution. and there is a control for sizing cells. @@ -36,4 +47,3 @@ Entry of labyrinth is upper left corner, exit is lower right ( this is different BUGS are numerous, and every bug was cleverly designed to drive you mad. DOCUMENTATION is self contained in code an in my brain. - diff --git a/doit.sh b/doit.sh index 61f5ce5..1a4cf8b 100755 --- a/doit.sh +++ b/doit.sh @@ -1,5 +1,19 @@ #!/bin/bash +setup() +{ + if [[ ! -d java ]] + then + echo "[FATAL] this tools $0 is intended to be run within laby project. Missing java directory." >&2 + exit 1 + fi + if [[ ! -d lab ]] + then + echo "[INFO] Creating directory lab to save default lab created" + mkdir lab + fi +} + do_code() { background=$1 @@ -127,15 +141,17 @@ done if [[ -z $DIALOG ]] then - echo "no console gui support (within $possible_console_gui) => no menus " + echo "[ERROR] no console gui support (no dialog tool found within $possible_console_gui) => no menus " >&2 exit 1 fi +setup + action=initial while [[ $action != quit ]] do - action=$($DIALOG --menu "Ultra Light IDE" 20 80 12 run "Run it" clean "Clean All" ant "Ant build" test "Test it" readme "Read me" code "Code" codebg "Code in background" deb "Debian package" properties "Edit Properties" quit "Quit" 3>&1 1>&2 2>&3) + action=$($DIALOG --menu "Ultra Light IDE" 20 80 12 run "Run it" clean "Clean All" ant "Ant build" test "Test it" readme "Read me" code "Code" codebg "Code in background" deb "Debian package" properties "Edit Properties" create "Create a new class" quit "Quit" 3>&1 1>&2 2>&3) if [[ $action == run ]] then @@ -166,9 +182,21 @@ do do_code $action elif [[ $action == readme ]] then - $DIALOG --textbox README 20 80 + $DIALOG --textbox README 40 80 --scrolltext elif [[ $action == properties ]] then edit_properties project_params + elif [[ $action == create ]] + then + newclass=$($DIALOG --inputbox "Enter new class name" 10 80 "NewClass" 3>&1 1>&2 2>&3) + if [[ $? = 0 ]] + then + if [[ -n $newclass ]] + then + pushd java + make work/$newclass + popd + fi + fi fi done diff --git a/java/org/artisanlogiciel/games/Display.java b/java/org/artisanlogiciel/games/Display.java index 18285dd..15f31ed 100644 --- a/java/org/artisanlogiciel/games/Display.java +++ b/java/org/artisanlogiciel/games/Display.java @@ -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 exits = new LinkedList(); 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."); diff --git a/java/org/artisanlogiciel/games/LabyModel.java b/java/org/artisanlogiciel/games/LabyModel.java index f0b4cfc..9f5e650 100644 --- a/java/org/artisanlogiciel/games/LabyModel.java +++ b/java/org/artisanlogiciel/games/LabyModel.java @@ -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 { diff --git a/java/org/artisanlogiciel/games/MazeParams.java b/java/org/artisanlogiciel/games/MazeParams.java new file mode 100644 index 0000000..7850c79 --- /dev/null +++ b/java/org/artisanlogiciel/games/MazeParams.java @@ -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(); + +}