move Display in gui package

- and some code indentation
This commit is contained in:
philippe lhardy
2020-10-11 15:30:28 +02:00
parent 9ec3cf0d01
commit 0f1a15916c
8 changed files with 93 additions and 158 deletions

View File

@@ -34,7 +34,7 @@
<!-- Put everything in ${build} into the artloglaby-${distversion}.jar file ( ${DSTAMP} not used yet )--> <!-- Put everything in ${build} into the artloglaby-${distversion}.jar file ( ${DSTAMP} not used yet )-->
<jar jarfile="${dist}/lib/artloglaby-${distversion}.jar" basedir="${build}"> <jar jarfile="${dist}/lib/artloglaby-${distversion}.jar" basedir="${build}">
<manifest> <manifest>
<attribute name="Main-Class" value="org.artisanlogiciel.games.Display"/> <attribute name="Main-Class" value="org.artisanlogiciel.games.maze.gui.Display"/>
<attribute name="Class-Path" value="libs/${artgraphicslib}.jar"/> <attribute name="Class-Path" value="libs/${artgraphicslib}.jar"/>
</manifest> </manifest>
<fileset dir="lang" includes="**" /> <fileset dir="lang" includes="**" />

View File

@@ -1,73 +1,56 @@
package org.artisanlogiciel.games; package org.artisanlogiciel.games;
/** /**
DirectionPosition * DirectionPosition
* <p>
record direction and position ( direction as defined in LabyModel ). * record direction and position ( direction as defined in LabyModel ).
**/ **/
public class DirectionPosition public class DirectionPosition {
{
private short direction; private short direction;
private Position position; private Position position;
// (direction,position) // (direction,position)
DirectionPosition(short d, Position p) public DirectionPosition(short d, Position p) {
{
direction = d; direction = d;
position = p; position = p;
} }
short getDirection() public short getDirection() {
{
return direction; return direction;
} }
void setDirection(short d) public void setDirection(short d) {
{
direction = d; direction = d;
} }
Position getPosition() public Position getPosition() {
{
return position; return position;
} }
public String toString() public String toString() {
{ if (position != null) {
if (position != null)
{
return position.toString(); return position.toString();
} }
return "?"; return "?";
} }
// create a new DirectionPosition from this using one possible direction. // create a new DirectionPosition from this using one possible direction.
DirectionPosition moveToAdjacentDirection() public DirectionPosition moveToAdjacentDirection() {
{
short pointingdirection = 0; short pointingdirection = 0;
Position p = null; Position p = null;
if (LabyModel.isFlagSet(direction,LabyModel.RIGHT)) if (LabyModel.isFlagSet(direction, LabyModel.RIGHT)) {
{
p = new Position(position.getX() + 1, position.getY()); p = new Position(position.getX() + 1, position.getY());
pointingdirection |= LabyModel.LEFT; pointingdirection |= LabyModel.LEFT;
} } else if (LabyModel.isFlagSet(direction, LabyModel.LEFT)) {
else if (LabyModel.isFlagSet(direction,LabyModel.LEFT))
{
p = new Position(position.getX() - 1, position.getY()); p = new Position(position.getX() - 1, position.getY());
pointingdirection |= LabyModel.RIGHT; pointingdirection |= LabyModel.RIGHT;
} } else if (LabyModel.isFlagSet(direction, LabyModel.UP)) {
else if (LabyModel.isFlagSet(direction,LabyModel.UP))
{
p = new Position(position.getX(), position.getY() - 1); p = new Position(position.getX(), position.getY() - 1);
pointingdirection |= LabyModel.DOWN; pointingdirection |= LabyModel.DOWN;
} } else if (LabyModel.isFlagSet(direction, LabyModel.DOWN)) {
else if (LabyModel.isFlagSet(direction,LabyModel.DOWN))
{
p = new Position(position.getX(), position.getY() + 1); p = new Position(position.getX(), position.getY() + 1);
pointingdirection |= LabyModel.UP; pointingdirection |= LabyModel.UP;
} } else {
else
{
p = position; p = position;
} }

View File

@@ -1,16 +1,10 @@
package org.artisanlogiciel.games; package org.artisanlogiciel.games;
import java.io.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Collections;
import java.util.Random; import java.util.Random;
import java.io.OutputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.DataOutputStream;
import java.io.DataInputStream;
/** /**
* Model of labyrinth storing only paths not walls. wall are regenerated later * Model of labyrinth storing only paths not walls. wall are regenerated later
* on based on adjacent paths. each position (x,y) stores what move can be done * on based on adjacent paths. each position (x,y) stores what move can be done

View File

@@ -3,7 +3,7 @@ package org.artisanlogiciel.games;
/** /**
* MazeCreationListener * MazeCreationListener
**/ **/
interface MazeCreationListener public interface MazeCreationListener
{ {
void changed(Position cornerleft, Position cornerright, WallsProvider provider); void changed(Position cornerleft, Position cornerright, WallsProvider provider);
} }

View File

@@ -1,4 +1,4 @@
package org.artisanlogiciel.games; package org.artisanlogiciel.games.maze.gui;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
@@ -31,7 +31,7 @@ import javax.swing.*;
import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener;
import org.artisanlogiciel.games.maze.gui.MazeSettings; import org.artisanlogiciel.games.*;
import org.artisanlogiciel.games.stl.Wall3d; import org.artisanlogiciel.games.stl.Wall3d;
import org.artisanlogiciel.util.UTF8Control; import org.artisanlogiciel.util.UTF8Control;

View File

@@ -1,6 +1,5 @@
package org.artisanlogiciel.games.maze.gui; package org.artisanlogiciel.games.maze.gui;
import org.artisanlogiciel.games.Display;
import org.artisanlogiciel.games.MazeParams; import org.artisanlogiciel.games.MazeParams;
import org.artisanlogiciel.games.MazeParamsFixed; import org.artisanlogiciel.games.MazeParamsFixed;

View File

@@ -12,8 +12,7 @@ import java.io.IOException;
/** /**
* Wall3d to create walls in 3d for stl conversion South, West North East... * Wall3d to create walls in 3d for stl conversion South, West North East...
**/ **/
public class Wall3d public class Wall3d {
{
// 4 triangles in 2 dim space reused 3 times // 4 triangles in 2 dim space reused 3 times
final static int BASE[][][] = {{{0, 0}, {1, 0}, {0, 1}}, {{1, 0}, {1, 1}, {0, 1}}, final static int BASE[][][] = {{{0, 0}, {1, 0}, {0, 1}}, {{1, 0}, {1, 1}, {0, 1}},
{{0, 0}, {1, 0}, {1, 1}}, {{0, 0}, {1, 1}, {0, 1}}}; {{0, 0}, {1, 0}, {1, 1}}, {{0, 0}, {1, 1}, {0, 1}}};
@@ -34,51 +33,37 @@ public class Wall3d
int triangle[][][] = null; int triangle[][][] = null;
public Wall3d(int t[][][]) public Wall3d(int t[][][]) {
{
triangle = t; triangle = t;
} }
public Wall3d(Wall3d origin, int dx, int dy, int dz) public Wall3d(Wall3d origin, int dx, int dy, int dz) {
{
triangle = origin.translate(dx, dy, dz); triangle = origin.translate(dx, dy, dz);
} }
Wall3d(int xl, int yl, int zl, int dx, int dy, int dz) Wall3d(int xl, int yl, int zl, int dx, int dy, int dz) {
{
int f = 0; int f = 0;
triangle = new int[12][3][3]; triangle = new int[12][3][3];
int[] factor = {xl, yl, zl}; int[] factor = {xl, yl, zl};
int[] translate = {dx, dy, dz}; int[] translate = {dx, dy, dz};
for (int i = 0; i < 12; i++) for (int i = 0; i < 12; i++) {
{
// point in a triangle // point in a triangle
for (int p = 0; p < 3; p++) for (int p = 0; p < 3; p++) {
{
short uaxis = 0; short uaxis = 0;
for (int axis = 0; axis < 2; axis++) for (int axis = 0; axis < 2; axis++) {
{
short caxis = AXIS[i / 2][axis]; short caxis = AXIS[i / 2][axis];
if (caxis > 0) if (caxis > 0) {
{
f = 1; f = 1;
} } else if (caxis < 0) {
else if (caxis < 0)
{
f = -1; f = -1;
caxis = (short) -caxis; caxis = (short) -caxis;
} }
uaxis |= caxis; uaxis |= caxis;
if (caxis == X) if (caxis == X) {
{
caxis = 0; caxis = 0;
} } else if (caxis == Y) {
else if (caxis == Y)
{
caxis = 1; caxis = 1;
} } else {
else
{
caxis = 2; caxis = 2;
} }
// if ( f == 0 ) // if ( f == 0 )
@@ -89,16 +74,11 @@ public class Wall3d
// " , " + BASE[i%4][p][axis] ); // " , " + BASE[i%4][p][axis] );
triangle[i][p][caxis] = translate[caxis] + BASE[i % 4][p][axis] * f * factor[caxis]; triangle[i][p][caxis] = translate[caxis] + BASE[i % 4][p][axis] * f * factor[caxis];
} }
if ((uaxis & X) == 0) if ((uaxis & X) == 0) {
{
uaxis = 0; uaxis = 0;
} } else if ((uaxis & Y) == 0) {
else if ((uaxis & Y) == 0)
{
uaxis = 1; uaxis = 1;
} } else {
else
{
uaxis = 2; uaxis = 2;
} }
triangle[i][p][uaxis] = translate[uaxis] + AXIS[i / 2][2] * factor[uaxis]; triangle[i][p][uaxis] = translate[uaxis] + AXIS[i / 2][2] * factor[uaxis];
@@ -106,18 +86,14 @@ public class Wall3d
} }
} }
public int[][][] translate(int dx, int dy, int dz) public int[][][] translate(int dx, int dy, int dz) {
{
int[] translate = {dx, dy, dz}; int[] translate = {dx, dy, dz};
int t[][][] = new int[12][3][3]; int t[][][] = new int[12][3][3];
for (int i = 0; i < 12; i++) for (int i = 0; i < 12; i++) {
{
// point in a triangle // point in a triangle
for (int p = 0; p < 3; p++) for (int p = 0; p < 3; p++) {
{ for (int axis = 0; axis < 3; axis++) {
for (int axis = 0; axis < 3; axis++)
{
t[i][p][axis] = translate[axis] + triangle[i][p][axis]; t[i][p][axis] = translate[axis] + triangle[i][p][axis];
} }
} }
@@ -127,19 +103,15 @@ public class Wall3d
} }
/** /**
write triangles as stl text * write triangles as stl text
**/ **/
public String toString() public String toString() {
{
String s = ""; String s = "";
for (int t = 0; t < 12; t++) for (int t = 0; t < 12; t++) {
{
s += "facet normal 0 0 0\nouter loop\n"; s += "facet normal 0 0 0\nouter loop\n";
for (int p = 0; p < 3; p++) for (int p = 0; p < 3; p++) {
{
s += "vertex"; s += "vertex";
for (int a = 0; a < 3; a++) for (int a = 0; a < 3; a++) {
{
// s+=" t "+ t + " p " + p + " a " + a + "=" + // s+=" t "+ t + " p " + p + " a " + a + "=" +
// triangle[t][p][a]; // triangle[t][p][a];
s += " " + triangle[t][p][a]; s += " " + triangle[t][p][a];
@@ -151,16 +123,14 @@ public class Wall3d
return s; return s;
} }
public static void prepare() public static void prepare() {
{
System.out.println(South.toString()); System.out.println(South.toString());
System.out.println(East.toString()); System.out.println(East.toString());
System.out.println(North.toString()); System.out.println(North.toString());
System.out.println(West.toString()); System.out.println(West.toString());
} }
public static void streamWallsOut(String name, LabyModel provider, OutputStream stream) throws IOException public static void streamWallsOut(String name, LabyModel provider, OutputStream stream) throws IOException {
{
int width = provider.getWidth(); int width = provider.getWidth();
int height = provider.getHeight(); int height = provider.getHeight();
int xl = 10; int xl = 10;
@@ -170,36 +140,28 @@ public class Wall3d
// WARNING DOWN - UP reversed ( in 2D Y is oriented to lower, in 3D it // WARNING DOWN - UP reversed ( in 2D Y is oriented to lower, in 3D it
// is to upper ). // is to upper ).
stream.write(("solid " + name + "\n").getBytes()); stream.write(("solid " + name + "\n").getBytes());
for (int x = 0; x < width; x++) for (int x = 0; x < width; x++) {
{
short walls = provider.getWalls(x, 0); short walls = provider.getWalls(x, 0);
if ((walls & Brick.UP) != 0) if ((walls & Brick.UP) != 0) {
{
stream.write(new Wall3d(South, x * xl, 0, 0).toString().getBytes()); stream.write(new Wall3d(South, x * xl, 0, 0).toString().getBytes());
} }
if ((walls & Brick.LEFT) != 0) if ((walls & Brick.LEFT) != 0) {
{
stream.write(new Wall3d(West, x * xl, 0, 0).toString().getBytes()); stream.write(new Wall3d(West, x * xl, 0, 0).toString().getBytes());
} }
} }
for (int y = 0; y < height; y++) for (int y = 0; y < height; y++) {
{
short walls = provider.getWalls(0, y); short walls = provider.getWalls(0, y);
if ((walls & Brick.LEFT) != 0) if ((walls & Brick.LEFT) != 0) {
{
stream.write(new Wall3d(West, 0, y * yl, 0).toString().getBytes()); stream.write(new Wall3d(West, 0, y * yl, 0).toString().getBytes());
} }
for (int x = 0; x < width; x++) for (int x = 0; x < width; x++) {
{
// south and east // south and east
walls = provider.getWalls(x, y); walls = provider.getWalls(x, y);
if ((walls & Brick.DOWN) != 0) if ((walls & Brick.DOWN) != 0) {
{
stream.write(new Wall3d(North, x * xl, y * yl, 0).toString().getBytes()); stream.write(new Wall3d(North, x * xl, y * yl, 0).toString().getBytes());
} }
if ((walls & Brick.RIGHT) != 0) if ((walls & Brick.RIGHT) != 0) {
{
stream.write(new Wall3d(East, x * xl, y * yl, 0).toString().getBytes()); stream.write(new Wall3d(East, x * xl, y * yl, 0).toString().getBytes());
} }
short path = provider.getPath(x, y); short path = provider.getPath(x, y);
@@ -209,9 +171,7 @@ public class Wall3d
// if ( ( (x+y) % 2) == 0 ) // if ( ( (x+y) % 2) == 0 )
stream.write(new Wall3d(LowGround, x * xl, y * yl, 0).toString().getBytes()); stream.write(new Wall3d(LowGround, x * xl, y * yl, 0).toString().getBytes());
} } else {
else
{
stream.write(new Wall3d(HighGround, x * xl, y * yl, 0).toString().getBytes()); stream.write(new Wall3d(HighGround, x * xl, y * yl, 0).toString().getBytes());
} }
} }
@@ -220,8 +180,7 @@ public class Wall3d
stream.write("endsolid wall\n\n".getBytes()); stream.write("endsolid wall\n\n".getBytes());
} }
public static void main(String args[]) public static void main(String args[]) {
{
Scanner console = new Scanner(System.in); Scanner console = new Scanner(System.in);
int xl = console.nextInt(); int xl = console.nextInt();

View File

@@ -34,7 +34,7 @@
<!-- Put everything in ${build} into the artloglaby-0.1.jar file ( ${DSTAMP} not used yet )--> <!-- Put everything in ${build} into the artloglaby-0.1.jar file ( ${DSTAMP} not used yet )-->
<jar jarfile="${dist}/lib/artloglaby-0.1.jar" basedir="${build}"> <jar jarfile="${dist}/lib/artloglaby-0.1.jar" basedir="${build}">
<manifest> <manifest>
<attribute name="Main-Class" value="org.artisanlogiciel.games.Display"/> <attribute name="Main-Class" value="org.artisanlogiciel.games.maze.gui.Display"/>
<attribute name="Class-Path" value="artgaphics-0.1.0.jar"/> <attribute name="Class-Path" value="artgaphics-0.1.0.jar"/>
</manifest> </manifest>
<fileset dir="lang" includes="**" /> <fileset dir="lang" includes="**" />