implémentation interfaces done
This commit is contained in:
1 parent
36dd8ff805
commit
676d159b1d
6 files changed
+124
-15
No files matched your search
@@ -4,6 +4,8 @@ public class ABox extends Box{
|
|||||||
public ABox (String label, int x, int y, Maze maze) {
|
public ABox (String label, int x, int y, Maze maze) {
|
||||||
|
|
||||||
super(label,x,y,maze) ;
|
super(label,x,y,maze) ;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -10,12 +10,77 @@ public abstract class Box
|
|||||||
private List<Box> neighbourList ;
|
private List<Box> neighbourList ;
|
||||||
|
|
||||||
public Box (String label, int x, int y, Maze maze) {
|
public Box (String label, int x, int y, Maze maze) {
|
||||||
|
|
||||||
this.label = label ;
|
this.label = label ;
|
||||||
this.x = x ;
|
this.x = x ;
|
||||||
this.y = y ;
|
this.y = y ;
|
||||||
this.maze = maze ;
|
this.maze = maze ;
|
||||||
|
|
||||||
if (x != 0 && y != 0 && x != maze.getDimensionX() && y != maze.getDimensionY()) {
|
if (x != 0 && y != 0 && x != maze.getDimensionX() && y != maze.getDimensionY()) {
|
||||||
this.neighbourList.add(maze.getMaze()[x+1][y]) ;
|
this.neighbourList.add(maze.getMaze()[x+1][y]) ;
|
||||||
|
this.neighbourList.add(maze.getMaze()[x-1][y]) ;
|
||||||
|
this.neighbourList.add(maze.getMaze()[x][y+1]) ;
|
||||||
|
this.neighbourList.add(maze.getMaze()[x][y-1]) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x == 0) {
|
||||||
|
this.neighbourList.add(maze.getMaze()[x+1][y]) ;
|
||||||
|
|
||||||
|
if (y == maze.getDimensionY()) {
|
||||||
|
this.neighbourList.add(maze.getMaze()[x][y-1]) ;
|
||||||
|
}
|
||||||
|
else if (y == 0) {
|
||||||
|
this.neighbourList.add(maze.getMaze()[x][y+1]) ;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.neighbourList.add(maze.getMaze()[x][y-1]) ;
|
||||||
|
this.neighbourList.add(maze.getMaze()[x][y+1]) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y == 0) {
|
||||||
|
this.neighbourList.add(maze.getMaze()[x][y+1]) ;
|
||||||
|
|
||||||
|
if (x == maze.getDimensionX()) {
|
||||||
|
this.neighbourList.add(maze.getMaze()[x-1][y]) ;
|
||||||
|
}
|
||||||
|
else if (x == 0) {
|
||||||
|
this.neighbourList.add(maze.getMaze()[x+1][y]) ;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.neighbourList.add(maze.getMaze()[x-1][y]) ;
|
||||||
|
this.neighbourList.add(maze.getMaze()[x+1][y]) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y == maze.getDimensionY()) {
|
||||||
|
this.neighbourList.add(maze.getMaze()[x][y-1]) ;
|
||||||
|
|
||||||
|
if (x == maze.getDimensionX()) {
|
||||||
|
this.neighbourList.add(maze.getMaze()[x-1][y]) ;
|
||||||
|
}
|
||||||
|
else if (x == 0) {
|
||||||
|
this.neighbourList.add(maze.getMaze()[x+1][y]) ;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.neighbourList.add(maze.getMaze()[x-1][y]) ;
|
||||||
|
this.neighbourList.add(maze.getMaze()[x+1][y]) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x == maze.getDimensionX()) {
|
||||||
|
this.neighbourList.add(maze.getMaze()[x-1][y]) ;
|
||||||
|
|
||||||
|
if (y == maze.getDimensionY()) {
|
||||||
|
this.neighbourList.add(maze.getMaze()[x][y-1]) ;
|
||||||
|
}
|
||||||
|
else if (y == 0) {
|
||||||
|
this.neighbourList.add(maze.getMaze()[x][y+1]) ;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.neighbourList.add(maze.getMaze()[x][y-1]) ;
|
||||||
|
this.neighbourList.add(maze.getMaze()[x][y+1]) ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,6 +90,18 @@ public abstract class Box
|
|||||||
}
|
}
|
||||||
return false ;
|
return false ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isWalkable() {
|
||||||
|
return true ;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Box> getNeighbourList() {
|
||||||
|
return neighbourList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNeighbourList(List<Box> neighbourList) {
|
||||||
|
this.neighbourList = neighbourList;
|
||||||
|
}
|
||||||
|
|
||||||
public int getX() {
|
public int getX() {
|
||||||
return x;
|
return x;
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
|
|
||||||
public class EBox extends Box{
|
public class EBox extends Box{
|
||||||
|
|
||||||
|
|
||||||
public EBox (String label, int x, int y, Maze maze) {
|
public EBox (String label, int x, int y, Maze maze) {
|
||||||
|
|
||||||
super(label,x,y,maze) ;
|
super(label,x,y,maze) ;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,13 @@
|
|||||||
import java.util.Iterator;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class Maze
|
public class Maze
|
||||||
implements GraphInterface{
|
implements GraphInterface{
|
||||||
|
|
||||||
int dimensionX ;
|
private int dimensionX ;
|
||||||
int dimensionY ;
|
private int dimensionY ;
|
||||||
int[][] maze ;
|
private Box[][] maze ;
|
||||||
|
|
||||||
public Maze(int dimensionX, int dimensionY, int[][] maze) {
|
public Maze(Box[][] maze) {
|
||||||
|
|
||||||
this.maze = maze ;
|
this.maze = maze ;
|
||||||
this.dimensionX = maze.length ;
|
this.dimensionX = maze.length ;
|
||||||
@@ -16,14 +15,37 @@ public class Maze
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCost(Box start, Box end) {
|
public int getCost(VertexInterface start, VertexInterface end) {
|
||||||
|
|
||||||
|
Box startBox = (Box) start ;
|
||||||
|
Box endBox = (Box) end ;
|
||||||
|
|
||||||
|
if (startBox.getNeighbourList().contains(endBox)) {
|
||||||
|
if (startBox.isWalkable() & endBox.isWalkable()) {
|
||||||
|
return 1 ;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return 0 ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getVertexNumber() {
|
public int getVertexNumber() {
|
||||||
|
return dimensionX*dimensionY ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ArrayList<VertexInterface> getVertexes() {
|
||||||
|
ArrayList<VertexInterface> vertexList = new ArrayList<VertexInterface>() ;
|
||||||
|
for (int i = 0 ; i <= dimensionX ; i++) {
|
||||||
|
for (int j = 0 ; j <= dimensionY ; j++) {
|
||||||
|
vertexList.add(maze[i][j]) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return vertexList ;
|
||||||
|
}
|
||||||
|
|
||||||
public int getDimensionX() {
|
public int getDimensionX() {
|
||||||
return dimensionX;
|
return dimensionX;
|
||||||
}
|
}
|
||||||
@@ -40,15 +62,13 @@ public class Maze
|
|||||||
this.dimensionY = dimensionY;
|
this.dimensionY = dimensionY;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int[][] getMaze() {
|
public Box[][] getMaze() {
|
||||||
return maze;
|
return maze;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMaze(int[][] maze) {
|
public void setMaze(Box[][] maze) {
|
||||||
this.maze = maze;
|
this.maze = maze;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -6,4 +6,6 @@ public interface VertexInterface {
|
|||||||
|
|
||||||
public String getLabel() ;
|
public String getLabel() ;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,18 @@
|
|||||||
|
|
||||||
public class WBox extends Box {
|
public class WBox extends Box {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public WBox (String label, int x, int y, Maze maze) {
|
public WBox (String label, int x, int y, Maze maze) {
|
||||||
|
|
||||||
super(label,x,y,maze) ;
|
super(label,x,y,maze) ;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isWalkable() {
|
||||||
|
return false ;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user