move Display in gui package
- and some code indentation
This commit is contained in:
@@ -34,7 +34,7 @@
|
||||
<!-- Put everything in ${build} into the artloglaby-${distversion}.jar file ( ${DSTAMP} not used yet )-->
|
||||
<jar jarfile="${dist}/lib/artloglaby-${distversion}.jar" basedir="${build}">
|
||||
<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"/>
|
||||
</manifest>
|
||||
<fileset dir="lang" includes="**" />
|
||||
|
||||
@@ -1,73 +1,56 @@
|
||||
package org.artisanlogiciel.games;
|
||||
|
||||
/**
|
||||
DirectionPosition
|
||||
|
||||
record direction and position ( direction as defined in LabyModel ).
|
||||
* DirectionPosition
|
||||
* <p>
|
||||
* record direction and position ( direction as defined in LabyModel ).
|
||||
**/
|
||||
public class DirectionPosition
|
||||
{
|
||||
public class DirectionPosition {
|
||||
private short direction;
|
||||
private Position position;
|
||||
|
||||
// (direction,position)
|
||||
DirectionPosition(short d, Position p)
|
||||
{
|
||||
public DirectionPosition(short d, Position p) {
|
||||
direction = d;
|
||||
position = p;
|
||||
}
|
||||
|
||||
short getDirection()
|
||||
{
|
||||
public short getDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
void setDirection(short d)
|
||||
{
|
||||
public void setDirection(short d) {
|
||||
direction = d;
|
||||
}
|
||||
|
||||
Position getPosition()
|
||||
{
|
||||
public Position getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
if (position != null)
|
||||
{
|
||||
public String toString() {
|
||||
if (position != null) {
|
||||
return position.toString();
|
||||
}
|
||||
return "?";
|
||||
}
|
||||
|
||||
// create a new DirectionPosition from this using one possible direction.
|
||||
DirectionPosition moveToAdjacentDirection()
|
||||
{
|
||||
public DirectionPosition moveToAdjacentDirection() {
|
||||
short pointingdirection = 0;
|
||||
Position p = null;
|
||||
if (LabyModel.isFlagSet(direction,LabyModel.RIGHT))
|
||||
{
|
||||
if (LabyModel.isFlagSet(direction, LabyModel.RIGHT)) {
|
||||
p = new Position(position.getX() + 1, position.getY());
|
||||
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());
|
||||
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);
|
||||
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);
|
||||
pointingdirection |= LabyModel.UP;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
p = position;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,10 @@
|
||||
package org.artisanlogiciel.games;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Collections;
|
||||
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
|
||||
* on based on adjacent paths. each position (x,y) stores what move can be done
|
||||
|
||||
@@ -3,7 +3,7 @@ package org.artisanlogiciel.games;
|
||||
/**
|
||||
* MazeCreationListener
|
||||
**/
|
||||
interface MazeCreationListener
|
||||
public interface MazeCreationListener
|
||||
{
|
||||
void changed(Position cornerleft, Position cornerright, WallsProvider provider);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.artisanlogiciel.games;
|
||||
package org.artisanlogiciel.games.maze.gui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.image.BufferedImage;
|
||||
@@ -31,7 +31,7 @@ import javax.swing.*;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
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.util.UTF8Control;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.artisanlogiciel.games.maze.gui;
|
||||
|
||||
import org.artisanlogiciel.games.Display;
|
||||
import org.artisanlogiciel.games.MazeParams;
|
||||
import org.artisanlogiciel.games.MazeParamsFixed;
|
||||
|
||||
|
||||
@@ -12,8 +12,7 @@ import java.io.IOException;
|
||||
/**
|
||||
* 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
|
||||
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}}};
|
||||
@@ -34,51 +33,37 @@ public class Wall3d
|
||||
|
||||
int triangle[][][] = null;
|
||||
|
||||
public Wall3d(int t[][][])
|
||||
{
|
||||
public Wall3d(int 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);
|
||||
}
|
||||
|
||||
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;
|
||||
triangle = new int[12][3][3];
|
||||
int[] factor = {xl, yl, zl};
|
||||
int[] translate = {dx, dy, dz};
|
||||
for (int i = 0; i < 12; i++)
|
||||
{
|
||||
for (int i = 0; i < 12; i++) {
|
||||
// point in a triangle
|
||||
for (int p = 0; p < 3; p++)
|
||||
{
|
||||
for (int p = 0; p < 3; p++) {
|
||||
short uaxis = 0;
|
||||
for (int axis = 0; axis < 2; axis++)
|
||||
{
|
||||
for (int axis = 0; axis < 2; axis++) {
|
||||
short caxis = AXIS[i / 2][axis];
|
||||
if (caxis > 0)
|
||||
{
|
||||
if (caxis > 0) {
|
||||
f = 1;
|
||||
}
|
||||
else if (caxis < 0)
|
||||
{
|
||||
} else if (caxis < 0) {
|
||||
f = -1;
|
||||
caxis = (short) -caxis;
|
||||
}
|
||||
uaxis |= caxis;
|
||||
if (caxis == X)
|
||||
{
|
||||
if (caxis == X) {
|
||||
caxis = 0;
|
||||
}
|
||||
else if (caxis == Y)
|
||||
{
|
||||
} else if (caxis == Y) {
|
||||
caxis = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
caxis = 2;
|
||||
}
|
||||
// if ( f == 0 )
|
||||
@@ -89,16 +74,11 @@ public class Wall3d
|
||||
// " , " + BASE[i%4][p][axis] );
|
||||
triangle[i][p][caxis] = translate[caxis] + BASE[i % 4][p][axis] * f * factor[caxis];
|
||||
}
|
||||
if ((uaxis & X) == 0)
|
||||
{
|
||||
if ((uaxis & X) == 0) {
|
||||
uaxis = 0;
|
||||
}
|
||||
else if ((uaxis & Y) == 0)
|
||||
{
|
||||
} else if ((uaxis & Y) == 0) {
|
||||
uaxis = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
uaxis = 2;
|
||||
}
|
||||
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 t[][][] = new int[12][3][3];
|
||||
|
||||
for (int i = 0; i < 12; i++)
|
||||
{
|
||||
for (int i = 0; i < 12; i++) {
|
||||
// point in a triangle
|
||||
for (int p = 0; p < 3; p++)
|
||||
{
|
||||
for (int axis = 0; axis < 3; axis++)
|
||||
{
|
||||
for (int p = 0; p < 3; p++) {
|
||||
for (int axis = 0; axis < 3; 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 = "";
|
||||
for (int t = 0; t < 12; t++)
|
||||
{
|
||||
for (int t = 0; t < 12; t++) {
|
||||
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";
|
||||
for (int a = 0; a < 3; a++)
|
||||
{
|
||||
for (int a = 0; a < 3; a++) {
|
||||
// s+=" t "+ t + " p " + p + " a " + a + "=" +
|
||||
// triangle[t][p][a];
|
||||
s += " " + triangle[t][p][a];
|
||||
@@ -151,16 +123,14 @@ public class Wall3d
|
||||
return s;
|
||||
}
|
||||
|
||||
public static void prepare()
|
||||
{
|
||||
public static void prepare() {
|
||||
System.out.println(South.toString());
|
||||
System.out.println(East.toString());
|
||||
System.out.println(North.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 height = provider.getHeight();
|
||||
int xl = 10;
|
||||
@@ -170,36 +140,28 @@ public class Wall3d
|
||||
// WARNING DOWN - UP reversed ( in 2D Y is oriented to lower, in 3D it
|
||||
// is to upper ).
|
||||
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);
|
||||
if ((walls & Brick.UP) != 0)
|
||||
{
|
||||
if ((walls & Brick.UP) != 0) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
for (int y = 0; y < height; 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());
|
||||
}
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
for (int x = 0; x < width; x++) {
|
||||
// south and east
|
||||
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());
|
||||
}
|
||||
if ((walls & Brick.RIGHT) != 0)
|
||||
{
|
||||
if ((walls & Brick.RIGHT) != 0) {
|
||||
stream.write(new Wall3d(East, x * xl, y * yl, 0).toString().getBytes());
|
||||
}
|
||||
short path = provider.getPath(x, y);
|
||||
@@ -209,9 +171,7 @@ public class Wall3d
|
||||
// if ( ( (x+y) % 2) == 0 )
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -220,8 +180,7 @@ public class Wall3d
|
||||
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);
|
||||
int xl = console.nextInt();
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
<!-- 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}">
|
||||
<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"/>
|
||||
</manifest>
|
||||
<fileset dir="lang" includes="**" />
|
||||
|
||||
Reference in New Issue
Block a user