implémentation interfaces done

This commit is contained in:
antograb committed 2017-11-23 11:44:15 +01:00
1 parent 36dd8ff805
commit 676d159b1d
6 files changed
+124 -15

No files matched your search

+2
View File
@@ -4,6 +4,8 @@ public class ABox extends Box{
public ABox (String label, int x, int y, Maze maze) {
super(label,x,y,maze) ;
}
}
+78 -1
View File
@@ -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 -1
View File
@@ -1,11 +1,11 @@
public class EBox extends Box{
public EBox (String label, int x, int y, Maze maze) {
super(label,x,y,maze) ;
}
}
+32 -12
View File
@@ -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;
}
}
+2
View File
@@ -6,4 +6,6 @@ public interface VertexInterface {
public String getLabel() ;
}
+9 -1
View File
@@ -1,10 +1,18 @@
public class WBox extends Box {
public WBox (String label, int x, int y, Maze maze) {
super(label,x,y,maze) ;
}
@Override
public boolean isWalkable() {
return false ;
}
}