From cddbd5f2d6c614a263359bb97a3308d37900ebfe Mon Sep 17 00:00:00 2001 From: philippe lhardy Date: Sat, 2 Dec 2017 17:56:27 +0100 Subject: [PATCH] add reset button + title default to 20x20 maze --- java/org/artisanlogiciel/games/Display.java | 39 +++++++++++++++++++-- lang/LabelsBundle.properties | 3 +- lang/LabelsBundle_fr.properties | 3 +- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/java/org/artisanlogiciel/games/Display.java b/java/org/artisanlogiciel/games/Display.java index 118e821..1b3587f 100644 --- a/java/org/artisanlogiciel/games/Display.java +++ b/java/org/artisanlogiciel/games/Display.java @@ -63,7 +63,7 @@ public class Display extends JFrame Display(LabyModel model,int W, int H, MazeParams params) { - super("Maze display"); + super(labels.getString("title")); if (params != null) { // fixedParams = new MazeParamsFixed(params.getSaveDir(),params.getWidth(),params.getHeight(),params.getMaxDepth()); @@ -114,6 +114,7 @@ public class Display extends JFrame maze.resetWallsProvider(model); model.setMazeListener(maze); + // we are in GUI event thread, need to release it and do it outside. new Thread() { public void run() { @@ -122,6 +123,27 @@ public class Display extends JFrame model.addEntryOrExit(params.getWidth(), params.getHeight() - 1); } }.start(); + } + } + + void resetModel() + { + // recreate labyrinth + if (params != null) + { + params = controler.getSettings().getParams(); + model = new LabyModel(params, new java.util.Random()); + maze.resetWallsProvider(model); + model.setMazeListener(maze); + + + // we are in GUI event thread, need to release it and do it outside. + new Thread() { + public void run() { + maze.changed(null,null,model); + } + }.start(); + } } @@ -208,8 +230,19 @@ public class Display extends JFrame { recreateModel(); } - }); + }); add(buttonCreate); + + JButton buttonReset = new JButton("reset");//labels.getString("reset")); + buttonReset.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent evt) + { + resetModel(); + } + }); + add(buttonReset); + } if ( params != null ) { @@ -1044,7 +1077,7 @@ public class Display extends JFrame } else { - MazeParamsFixed params = new MazeParamsFixed(new File("lab"),60,60,15); + MazeParamsFixed params = new MazeParamsFixed(new File("lab"),20,20,12); model = new LabyModel(params, new java.util.Random()); setupDisplay(model,W,H,params); diff --git a/lang/LabelsBundle.properties b/lang/LabelsBundle.properties index 4d64dff..c1691a5 100644 --- a/lang/LabelsBundle.properties +++ b/lang/LabelsBundle.properties @@ -8,4 +8,5 @@ west = West resolve = Resolve create = Create save = Save -quit = Quit \ No newline at end of file +quit = Quit +title = A Maz ing \ No newline at end of file diff --git a/lang/LabelsBundle_fr.properties b/lang/LabelsBundle_fr.properties index e0f4637..a85b857 100644 --- a/lang/LabelsBundle_fr.properties +++ b/lang/LabelsBundle_fr.properties @@ -8,4 +8,5 @@ west = Ouest resolve = Résoudre create = Créer save = Sauver -quit = Quitter \ No newline at end of file +quit = Quitter +title = La Bireinte \ No newline at end of file