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) {
|
||||
|
||||
super(label,x,y,maze) ;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -10,12 +10,77 @@ public abstract class Box
|
||||
private List<Box> neighbourList ;
|
||||
|
||||
public Box (String label, int x, int y, Maze maze) {
|
||||
|
||||
this.label = label ;
|
||||
this.x = x ;
|
||||
this.y = y ;
|
||||
this.maze = maze ;
|
||||
|
||||
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 ;
|
||||
}
|
||||
|
||||
public boolean isWalkable() {
|
||||
return true ;
|
||||
}
|
||||
|
||||
public List<Box> getNeighbourList() {
|
||||
return neighbourList;
|
||||
}
|
||||
|
||||
public void setNeighbourList(List<Box> neighbourList) {
|
||||
this.neighbourList = neighbourList;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
|
||||
public class EBox extends Box{
|
||||
|
||||
|
||||
public EBox (String label, int x, int y, Maze maze) {
|
||||
|
||||
super(label,x,y,maze) ;
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +1,13 @@
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Maze
|
||||
implements GraphInterface{
|
||||
|
||||
int dimensionX ;
|
||||
int dimensionY ;
|
||||
int[][] maze ;
|
||||
private int dimensionX ;
|
||||
private int dimensionY ;
|
||||
private Box[][] maze ;
|
||||
|
||||
public Maze(int dimensionX, int dimensionY, int[][] maze) {
|
||||
public Maze(Box[][] maze) {
|
||||
|
||||
this.maze = maze ;
|
||||
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() {
|
||||
|
||||
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() {
|
||||
return dimensionX;
|
||||
}
|
||||
@@ -40,15 +62,13 @@ public class Maze
|
||||
this.dimensionY = dimensionY;
|
||||
}
|
||||
|
||||
public int[][] getMaze() {
|
||||
public Box[][] getMaze() {
|
||||
return maze;
|
||||
}
|
||||
|
||||
public void setMaze(int[][] maze) {
|
||||
public void setMaze(Box[][] maze) {
|
||||
this.maze = maze;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -6,4 +6,6 @@ public interface VertexInterface {
|
||||
|
||||
public String getLabel() ;
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user