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

@@ -1,77 +1,60 @@
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)
{
direction=d;
position=p;
public DirectionPosition(short d, Position p) {
direction = d;
position = p;
}
short getDirection()
{
return direction;
public short getDirection() {
return direction;
}
void setDirection(short d)
{
direction = d;
public void setDirection(short d) {
direction = d;
}
Position getPosition()
{
return position;
public Position getPosition() {
return position;
}
public String toString()
{
if (position != null)
{
return position.toString();
}
return "?";
public String toString() {
if (position != null) {
return position.toString();
}
return "?";
}
// create a new DirectionPosition from this using one possible direction.
DirectionPosition moveToAdjacentDirection()
{
short pointingdirection = 0;
Position p = null;
if (LabyModel.isFlagSet(direction,LabyModel.RIGHT))
{
p = new Position(position.getX() + 1, position.getY());
pointingdirection |= 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))
{
p = new Position(position.getX(),position.getY() -1);
pointingdirection |= LabyModel.DOWN;
}
else if (LabyModel.isFlagSet(direction,LabyModel.DOWN))
{
p = new Position(position.getX(),position.getY() + 1);
pointingdirection |= LabyModel.UP;
}
else
{
p = position;
}
public DirectionPosition moveToAdjacentDirection() {
short pointingdirection = 0;
Position p = null;
if (LabyModel.isFlagSet(direction, LabyModel.RIGHT)) {
p = new Position(position.getX() + 1, position.getY());
pointingdirection |= 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)) {
p = new Position(position.getX(), position.getY() - 1);
pointingdirection |= LabyModel.DOWN;
} else if (LabyModel.isFlagSet(direction, LabyModel.DOWN)) {
p = new Position(position.getX(), position.getY() + 1);
pointingdirection |= LabyModel.UP;
} else {
p = position;
}
return new DirectionPosition((short) pointingdirection, p);
return new DirectionPosition((short) pointingdirection, p);
}
}