题目如图片:
处理的办法及代码:
1、迷宫中每个元素,有值、行、列,用一个类写入。
public class MazeNode {
private int value;//值
private int i;//x
private int j;//y
private boolean []wayState;//状态
public MazeNode(int value,int i,int j) {
this.value=value;
this.i=i;
this.j=j ;
wayState=new boolean[Contant.INITSIZE];
}
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
public void setI(int i) {
this.i = i;
}
public void setJ(int j) {
this.j = j;
}
public int getI() {
return i;
}
public int getJ() {
return j;
}
public boolean getWayState(int direction) {
return wayState[direction];
}
public void setWayState(int direction,boolean isAble) {
wayState[direction] = isAble;
}
}
2、然后进行分析,每个迷宫中元素其实是有其特性的。我们利用可以利用接口来实现。
四个方向 :上、下、左、右;
两个状态:可走、不可走
//接口里的方向
public interface Contant {
public static final int INITSIZE = 4;
public static final int WAY_EAST = 0;