Java项目实现寻找迷宫出路

网友投稿 237 2022-12-06


Java项目实现寻找迷宫出路

本文实例为大家分享了java实现寻找迷宫出路的具体代码,供大家参考,具体内容如下

项目名称

寻找迷宫出路

项目描述

给定一个自定义迷宫,0表示能通过,1表示不能通过。通过程序找出正确的迷宫出路,并将正确的路线改为2输出。

代码实现

测试类

public class Test {

public static void main(String[] args) {

Maze maze = new Maze();

maze.begin();

}

}

主类:实现主方法

public class Maze {

private MazeNode[][] mazeNodes;

private int row;

private int col;

private Stack stack = new Stack<>();

private static Scanner scanner = new Scanner(System.in);

public Maze(){

System.out.println("请输入行列数");

row = scanner.nextInt();

col = scanner.nextInt();

mazeNodes = new MazeNode[row][col];

}

public void initValue(){

System.out.println("输入迷宫路径:");

for(int i=0;i

for(int j=0;j

// i j

mazeNodes[i][j] = new MazeNode(scanner.nextInt(),i,j);

}

}

}

//2. 根据当前节点的四个方向上面的value值

// 初始化当前节点的四个方向行走状态

public void initWayState(){

for(int i=0;i

for(int j=0;j

//i j

if(mazeNodes[i][j].getValue()==0){

//东 :看东边节点的值是0

if(j+1

// 将当前节点i j 的东边方向设置成可走状态

mazeNodes[i][j].setWayState(Constant.WAY_EAST,Constant.WAY_ABLE);

}

//西

if(j-1>0 && mazeNodes[i][j-1].getValue() == 0){

mazeNodes[i][j].setWayState(Constant.WAY_WEST,Constant.WAY_ABLE);

}

//南

if(i+1

mazeNodes[i][j].setWayState(Constant.WAY_SOUTH,Constant.WAY_ABLE);

}

//北

if(i-1>0 && mazeNodes[i-1][j].getValue() == 0){

mazeNodes[i][j].setWayState(Constant.WAY_NORTH,Constant.WAY_ABLE);

}

}

}

}

}

//走迷宫

public void goMaze(){

if(mazeNodes[0][0].getValue()!=0){

System.out.println("没有迷宫路径");

return;

}

stack.push(mazeNodes[0][0]);

while (!stack.isEmpty()) {//TODO:??????

MazeNode top = stack.peek();

//获取当前栈顶元素在二维数组中的行列坐标

int i = top.getI();

int j = top.getJ();

if(i == row-1 && j==col-1){

System.out.println("找到迷宫路径");

return;

}

//TODO:

if(mazeNodes[i][j].getWayState(Constant.WAY_SOUTH) == Constant.WAY_DISABLE &&

mazeNodes[i][j].getWayState(Constant.WAY_EAST) == Constant.WAY_DISABLE &&

mazeNodes[i][j].getWayState(Constant.WAY_NORTH) == Constant.WAY_DISABLE &&

mazeNodes[i][j].getWayState(Constant.WAY_WEST) == Constant.WAY_DISABLE){

stack.pop();

}

//东

else if (mazeNodes[i][j].getWayState(Constant.WAY_EAST)) {

stack.push(mazeNodes[i][j + 1]);

mazeNodes[i][j+1].setWayState(Constant.WAY_WEST,Constant.WAY_DISABLE);

mazeNodes[i][j].setWayState(Constant.WAY_EAST,Constant.WAY_DISABLE);

}//南

else if (mazeNodes[i][j].getWayState(Constant.WAY_SOUTH)) {

//如果南边方向可走,将南边节点进行入栈操作

stack.push(mazeNodes[i + 1][j]);

//封路1:将南边节点的回路(北边)方向封掉

mazeNodes[i+1][j].setWayState(Constant.WAY_NORTH,Constant.WAY_DISABLE);

//封路2:将当前节点i,j 走过的路封掉 TODO:

mazeNodes[i][j].setWayState(Constant.WAY_SOUTH,Constant.WAY_DISABLE);

}

//西

else if (mazeNodes[i][j].getWayState(Constant.WAY_WEST)) {

stack.push(mazeNodes[i][j - 1]);

mazeNodes[i][j-1].setWayState(Constant.WAY_EAST,Constant.WAY_DISABLE);

mazeNodes[i][j]cFErm.setWayState(Constant.WAY_WEST,Constant.WAY_DISABLE);

}

//北

else if (mazeNodes[i][j].getWayState(Constant.WAY_NORTH)) {

stack.push(mazeNodes[i - 1][j]);

mazeNodes[i-1][j].setWayState(Constant.WAY_SOUTH,Constant.WAY_DISABLE);

mazeNodes[i][j].setWayState(Constant.WAY_NORTH,Conshttp://tant.WAY_DISABLE);

}

// if(mazeNodes[i][j].getWayState(Constant.WAY_SOUTH) == Constant.WAY_DISABLE &&

// mazeNodes[i][j].getWayState(Constant.WAY_EAST) == Constant.WAY_DISABLE &&

// mazeNodes[i][j].getWayState(Constant.WAY_NORTH) == Constant.WAY_DISABLE &&

// mazeNodes[i][j].getWayState(Constant.WAY_WEST) == Constant.WAY_DISABLE){

// stack.pop();

// }

}

}

public void finish(){

while (!stack.isEmpty()) {

MazeNode top = stack.peek();

top.setValue(2);

stack.pop();

}

System.out.println("迷宫路径为:");

int i = 0, j = 0;

while (i

for (j = 0; j < col; j++) {

System.out.print(mazeNodes[i][j].getValue()+" ");

}

System.out.println();

i++;

}

}

public void begin(){

initValue();

initWayState();

goMaze();

finish();

}

// public void show(){

// for(int i=0;i

// for(int j=0;j

// System.out.print(mazeNodes[i][j].value+" ");

// }

// System.out.println();

// }

// }

}

MazeNode:结点类,用于迷宫结点

public class MazeNode {

private int i;

private int j;

private int value;

private boolean[] wayState;

public MazeNode(int value,int i,int j){

wayState = new boolean[Constant.WAYNUM];

this.value = value;

this.i = i;

this.j = j;

}

public int getValue() {

return value;

}

public void setWayState(int direction,boolean isAble) {

wayState[direction] = isAble;

}

public boolean getWayState(int direction) {

return wayState[direction];

}

public void setValue(int value){

this.value = value;

}

public int getI() {

return i;

}

public int getJ() {

return j;

}

}

Constant:常数类,方便使用

public class Constant {

public static final int WAYNUM = 4;

public static final int WAY_EAST = 0;

public static final int WAY_WEST = 1;

public static final int WAY_SOUTH = 2;

public static final int WAY_NORTH = 3;

public static final boolean WAY_ABLE = true;

public static final boolean WAY_DISABLE = false;

}

for(int j=0;j

// i j

mazeNodes[i][j] = new MazeNode(scanner.nextInt(),i,j);

}

}

}

//2. 根据当前节点的四个方向上面的value值

// 初始化当前节点的四个方向行走状态

public void initWayState(){

for(int i=0;i

for(int j=0;j

//i j

if(mazeNodes[i][j].getValue()==0){

//东 :看东边节点的值是0

if(j+1

// 将当前节点i j 的东边方向设置成可走状态

mazeNodes[i][j].setWayState(Constant.WAY_EAST,Constant.WAY_ABLE);

}

//西

if(j-1>0 && mazeNodes[i][j-1].getValue() == 0){

mazeNodes[i][j].setWayState(Constant.WAY_WEST,Constant.WAY_ABLE);

}

//南

if(i+1

mazeNodes[i][j].setWayState(Constant.WAY_SOUTH,Constant.WAY_ABLE);

}

//北

if(i-1>0 && mazeNodes[i-1][j].getValue() == 0){

mazeNodes[i][j].setWayState(Constant.WAY_NORTH,Constant.WAY_ABLE);

}

}

}

}

}

//走迷宫

public void goMaze(){

if(mazeNodes[0][0].getValue()!=0){

System.out.println("没有迷宫路径");

return;

}

stack.push(mazeNodes[0][0]);

while (!stack.isEmpty()) {//TODO:??????

MazeNode top = stack.peek();

//获取当前栈顶元素在二维数组中的行列坐标

int i = top.getI();

int j = top.getJ();

if(i == row-1 && j==col-1){

System.out.println("找到迷宫路径");

return;

}

//TODO:

if(mazeNodes[i][j].getWayState(Constant.WAY_SOUTH) == Constant.WAY_DISABLE &&

mazeNodes[i][j].getWayState(Constant.WAY_EAST) == Constant.WAY_DISABLE &&

mazeNodes[i][j].getWayState(Constant.WAY_NORTH) == Constant.WAY_DISABLE &&

mazeNodes[i][j].getWayState(Constant.WAY_WEST) == Constant.WAY_DISABLE){

stack.pop();

}

//东

else if (mazeNodes[i][j].getWayState(Constant.WAY_EAST)) {

stack.push(mazeNodes[i][j + 1]);

mazeNodes[i][j+1].setWayState(Constant.WAY_WEST,Constant.WAY_DISABLE);

mazeNodes[i][j].setWayState(Constant.WAY_EAST,Constant.WAY_DISABLE);

}//南

else if (mazeNodes[i][j].getWayState(Constant.WAY_SOUTH)) {

//如果南边方向可走,将南边节点进行入栈操作

stack.push(mazeNodes[i + 1][j]);

//封路1:将南边节点的回路(北边)方向封掉

mazeNodes[i+1][j].setWayState(Constant.WAY_NORTH,Constant.WAY_DISABLE);

//封路2:将当前节点i,j 走过的路封掉 TODO:

mazeNodes[i][j].setWayState(Constant.WAY_SOUTH,Constant.WAY_DISABLE);

}

//西

else if (mazeNodes[i][j].getWayState(Constant.WAY_WEST)) {

stack.push(mazeNodes[i][j - 1]);

mazeNodes[i][j-1].setWayState(Constant.WAY_EAST,Constant.WAY_DISABLE);

mazeNodes[i][j]cFErm.setWayState(Constant.WAY_WEST,Constant.WAY_DISABLE);

}

//北

else if (mazeNodes[i][j].getWayState(Constant.WAY_NORTH)) {

stack.push(mazeNodes[i - 1][j]);

mazeNodes[i-1][j].setWayState(Constant.WAY_SOUTH,Constant.WAY_DISABLE);

mazeNodes[i][j].setWayState(Constant.WAY_NORTH,Conshttp://tant.WAY_DISABLE);

}

// if(mazeNodes[i][j].getWayState(Constant.WAY_SOUTH) == Constant.WAY_DISABLE &&

// mazeNodes[i][j].getWayState(Constant.WAY_EAST) == Constant.WAY_DISABLE &&

// mazeNodes[i][j].getWayState(Constant.WAY_NORTH) == Constant.WAY_DISABLE &&

// mazeNodes[i][j].getWayState(Constant.WAY_WEST) == Constant.WAY_DISABLE){

// stack.pop();

// }

}

}

public void finish(){

while (!stack.isEmpty()) {

MazeNode top = stack.peek();

top.setValue(2);

stack.pop();

}

System.out.println("迷宫路径为:");

int i = 0, j = 0;

while (i

for (j = 0; j < col; j++) {

System.out.print(mazeNodes[i][j].getValue()+" ");

}

System.out.println();

i++;

}

}

public void begin(){

initValue();

initWayState();

goMaze();

finish();

}

// public void show(){

// for(int i=0;i

// for(int j=0;j

// System.out.print(mazeNodes[i][j].value+" ");

// }

// System.out.println();

// }

// }

}

MazeNode:结点类,用于迷宫结点

public class MazeNode {

private int i;

private int j;

private int value;

private boolean[] wayState;

public MazeNode(int value,int i,int j){

wayState = new boolean[Constant.WAYNUM];

this.value = value;

this.i = i;

this.j = j;

}

public int getValue() {

return value;

}

public void setWayState(int direction,boolean isAble) {

wayState[direction] = isAble;

}

public boolean getWayState(int direction) {

return wayState[direction];

}

public void setValue(int value){

this.value = value;

}

public int getI() {

return i;

}

public int getJ() {

return j;

}

}

Constant:常数类,方便使用

public class Constant {

public static final int WAYNUM = 4;

public static final int WAY_EAST = 0;

public static final int WAY_WEST = 1;

public static final int WAY_SOUTH = 2;

public static final int WAY_NORTH = 3;

public static final boolean WAY_ABLE = true;

public static final boolean WAY_DISABLE = false;

}

for(int j=0;j

//i j

if(mazeNodes[i][j].getValue()==0){

//东 :看东边节点的值是0

if(j+1

// 将当前节点i j 的东边方向设置成可走状态

mazeNodes[i][j].setWayState(Constant.WAY_EAST,Constant.WAY_ABLE);

}

//西

if(j-1>0 && mazeNodes[i][j-1].getValue() == 0){

mazeNodes[i][j].setWayState(Constant.WAY_WEST,Constant.WAY_ABLE);

}

//南

if(i+1

mazeNodes[i][j].setWayState(Constant.WAY_SOUTH,Constant.WAY_ABLE);

}

//北

if(i-1>0 && mazeNodes[i-1][j].getValue() == 0){

mazeNodes[i][j].setWayState(Constant.WAY_NORTH,Constant.WAY_ABLE);

}

}

}

}

}

//走迷宫

public void goMaze(){

if(mazeNodes[0][0].getValue()!=0){

System.out.println("没有迷宫路径");

return;

}

stack.push(mazeNodes[0][0]);

while (!stack.isEmpty()) {//TODO:??????

MazeNode top = stack.peek();

//获取当前栈顶元素在二维数组中的行列坐标

int i = top.getI();

int j = top.getJ();

if(i == row-1 && j==col-1){

System.out.println("找到迷宫路径");

return;

}

//TODO:

if(mazeNodes[i][j].getWayState(Constant.WAY_SOUTH) == Constant.WAY_DISABLE &&

mazeNodes[i][j].getWayState(Constant.WAY_EAST) == Constant.WAY_DISABLE &&

mazeNodes[i][j].getWayState(Constant.WAY_NORTH) == Constant.WAY_DISABLE &&

mazeNodes[i][j].getWayState(Constant.WAY_WEST) == Constant.WAY_DISABLE){

stack.pop();

}

//东

else if (mazeNodes[i][j].getWayState(Constant.WAY_EAST)) {

stack.push(mazeNodes[i][j + 1]);

mazeNodes[i][j+1].setWayState(Constant.WAY_WEST,Constant.WAY_DISABLE);

mazeNodes[i][j].setWayState(Constant.WAY_EAST,Constant.WAY_DISABLE);

}//南

else if (mazeNodes[i][j].getWayState(Constant.WAY_SOUTH)) {

//如果南边方向可走,将南边节点进行入栈操作

stack.push(mazeNodes[i + 1][j]);

//封路1:将南边节点的回路(北边)方向封掉

mazeNodes[i+1][j].setWayState(Constant.WAY_NORTH,Constant.WAY_DISABLE);

//封路2:将当前节点i,j 走过的路封掉 TODO:

mazeNodes[i][j].setWayState(Constant.WAY_SOUTH,Constant.WAY_DISABLE);

}

//西

else if (mazeNodes[i][j].getWayState(Constant.WAY_WEST)) {

stack.push(mazeNodes[i][j - 1]);

mazeNodes[i][j-1].setWayState(Constant.WAY_EAST,Constant.WAY_DISABLE);

mazeNodes[i][j]cFErm.setWayState(Constant.WAY_WEST,Constant.WAY_DISABLE);

}

//北

else if (mazeNodes[i][j].getWayState(Constant.WAY_NORTH)) {

stack.push(mazeNodes[i - 1][j]);

mazeNodes[i-1][j].setWayState(Constant.WAY_SOUTH,Constant.WAY_DISABLE);

mazeNodes[i][j].setWayState(Constant.WAY_NORTH,Conshttp://tant.WAY_DISABLE);

}

// if(mazeNodes[i][j].getWayState(Constant.WAY_SOUTH) == Constant.WAY_DISABLE &&

// mazeNodes[i][j].getWayState(Constant.WAY_EAST) == Constant.WAY_DISABLE &&

// mazeNodes[i][j].getWayState(Constant.WAY_NORTH) == Constant.WAY_DISABLE &&

// mazeNodes[i][j].getWayState(Constant.WAY_WEST) == Constant.WAY_DISABLE){

// stack.pop();

// }

}

}

public void finish(){

while (!stack.isEmpty()) {

MazeNode top = stack.peek();

top.setValue(2);

stack.pop();

}

System.out.println("迷宫路径为:");

int i = 0, j = 0;

while (i

for (j = 0; j < col; j++) {

System.out.print(mazeNodes[i][j].getValue()+" ");

}

System.out.println();

i++;

}

}

public void begin(){

initValue();

initWayState();

goMaze();

finish();

}

// public void show(){

// for(int i=0;i

// for(int j=0;j

// System.out.print(mazeNodes[i][j].value+" ");

// }

// System.out.println();

// }

// }

}

MazeNode:结点类,用于迷宫结点

public class MazeNode {

private int i;

private int j;

private int value;

private boolean[] wayState;

public MazeNode(int value,int i,int j){

wayState = new boolean[Constant.WAYNUM];

this.value = value;

this.i = i;

this.j = j;

}

public int getValue() {

return value;

}

public void setWayState(int direction,boolean isAble) {

wayState[direction] = isAble;

}

public boolean getWayState(int direction) {

return wayState[direction];

}

public void setValue(int value){

this.value = value;

}

public int getI() {

return i;

}

public int getJ() {

return j;

}

}

Constant:常数类,方便使用

public class Constant {

public static final int WAYNUM = 4;

public static final int WAY_EAST = 0;

public static final int WAY_WEST = 1;

public static final int WAY_SOUTH = 2;

public static final int WAY_NORTH = 3;

public static final boolean WAY_ABLE = true;

public static final boolean WAY_DISABLE = false;

}

mazeNodes[i][j].setWayState(Constant.WAY_SOUTH,Constant.WAY_ABLE);

}

//北

if(i-1>0 && mazeNodes[i-1][j].getValue() == 0){

mazeNodes[i][j].setWayState(Constant.WAY_NORTH,Constant.WAY_ABLE);

}

}

}

}

}

//走迷宫

public void goMaze(){

if(mazeNodes[0][0].getValue()!=0){

System.out.println("没有迷宫路径");

return;

}

stack.push(mazeNodes[0][0]);

while (!stack.isEmpty()) {//TODO:??????

MazeNode top = stack.peek();

//获取当前栈顶元素在二维数组中的行列坐标

int i = top.getI();

int j = top.getJ();

if(i == row-1 && j==col-1){

System.out.println("找到迷宫路径");

return;

}

//TODO:

if(mazeNodes[i][j].getWayState(Constant.WAY_SOUTH) == Constant.WAY_DISABLE &&

mazeNodes[i][j].getWayState(Constant.WAY_EAST) == Constant.WAY_DISABLE &&

mazeNodes[i][j].getWayState(Constant.WAY_NORTH) == Constant.WAY_DISABLE &&

mazeNodes[i][j].getWayState(Constant.WAY_WEST) == Constant.WAY_DISABLE){

stack.pop();

}

//东

else if (mazeNodes[i][j].getWayState(Constant.WAY_EAST)) {

stack.push(mazeNodes[i][j + 1]);

mazeNodes[i][j+1].setWayState(Constant.WAY_WEST,Constant.WAY_DISABLE);

mazeNodes[i][j].setWayState(Constant.WAY_EAST,Constant.WAY_DISABLE);

}//南

else if (mazeNodes[i][j].getWayState(Constant.WAY_SOUTH)) {

//如果南边方向可走,将南边节点进行入栈操作

stack.push(mazeNodes[i + 1][j]);

//封路1:将南边节点的回路(北边)方向封掉

mazeNodes[i+1][j].setWayState(Constant.WAY_NORTH,Constant.WAY_DISABLE);

//封路2:将当前节点i,j 走过的路封掉 TODO:

mazeNodes[i][j].setWayState(Constant.WAY_SOUTH,Constant.WAY_DISABLE);

}

//西

else if (mazeNodes[i][j].getWayState(Constant.WAY_WEST)) {

stack.push(mazeNodes[i][j - 1]);

mazeNodes[i][j-1].setWayState(Constant.WAY_EAST,Constant.WAY_DISABLE);

mazeNodes[i][j]cFErm.setWayState(Constant.WAY_WEST,Constant.WAY_DISABLE);

}

//北

else if (mazeNodes[i][j].getWayState(Constant.WAY_NORTH)) {

stack.push(mazeNodes[i - 1][j]);

mazeNodes[i-1][j].setWayState(Constant.WAY_SOUTH,Constant.WAY_DISABLE);

mazeNodes[i][j].setWayState(Constant.WAY_NORTH,Conshttp://tant.WAY_DISABLE);

}

// if(mazeNodes[i][j].getWayState(Constant.WAY_SOUTH) == Constant.WAY_DISABLE &&

// mazeNodes[i][j].getWayState(Constant.WAY_EAST) == Constant.WAY_DISABLE &&

// mazeNodes[i][j].getWayState(Constant.WAY_NORTH) == Constant.WAY_DISABLE &&

// mazeNodes[i][j].getWayState(Constant.WAY_WEST) == Constant.WAY_DISABLE){

// stack.pop();

// }

}

}

public void finish(){

while (!stack.isEmpty()) {

MazeNode top = stack.peek();

top.setValue(2);

stack.pop();

}

System.out.println("迷宫路径为:");

int i = 0, j = 0;

while (i

for (j = 0; j < col; j++) {

System.out.print(mazeNodes[i][j].getValue()+" ");

}

System.out.println();

i++;

}

}

public void begin(){

initValue();

initWayState();

goMaze();

finish();

}

// public void show(){

// for(int i=0;i

// for(int j=0;j

// System.out.print(mazeNodes[i][j].value+" ");

// }

// System.out.println();

// }

// }

}

MazeNode:结点类,用于迷宫结点

public class MazeNode {

private int i;

private int j;

private int value;

private boolean[] wayState;

public MazeNode(int value,int i,int j){

wayState = new boolean[Constant.WAYNUM];

this.value = value;

this.i = i;

this.j = j;

}

public int getValue() {

return value;

}

public void setWayState(int direction,boolean isAble) {

wayState[direction] = isAble;

}

public boolean getWayState(int direction) {

return wayState[direction];

}

public void setValue(int value){

this.value = value;

}

public int getI() {

return i;

}

public int getJ() {

return j;

}

}

Constant:常数类,方便使用

public class Constant {

public static final int WAYNUM = 4;

public static final int WAY_EAST = 0;

public static final int WAY_WEST = 1;

public static final int WAY_SOUTH = 2;

public static final int WAY_NORTH = 3;

public static final boolean WAY_ABLE = true;

public static final boolean WAY_DISABLE = false;

}

for (j = 0; j < col; j++) {

System.out.print(mazeNodes[i][j].getValue()+" ");

}

System.out.println();

i++;

}

}

public void begin(){

initValue();

initWayState();

goMaze();

finish();

}

// public void show(){

// for(int i=0;i

// for(int j=0;j

// System.out.print(mazeNodes[i][j].value+" ");

// }

// System.out.println();

// }

// }

}

MazeNode:结点类,用于迷宫结点

public class MazeNode {

private int i;

private int j;

private int value;

private boolean[] wayState;

public MazeNode(int value,int i,int j){

wayState = new boolean[Constant.WAYNUM];

this.value = value;

this.i = i;

this.j = j;

}

public int getValue() {

return value;

}

public void setWayState(int direction,boolean isAble) {

wayState[direction] = isAble;

}

public boolean getWayState(int direction) {

return wayState[direction];

}

public void setValue(int value){

this.value = value;

}

public int getI() {

return i;

}

public int getJ() {

return j;

}

}

Constant:常数类,方便使用

public class Constant {

public static final int WAYNUM = 4;

public static final int WAY_EAST = 0;

public static final int WAY_WEST = 1;

public static final int WAY_SOUTH = 2;

public static final int WAY_NORTH = 3;

public static final boolean WAY_ABLE = true;

public static final boolean WAY_DISABLE = false;

}

// for(int j=0;j

// System.out.print(mazeNodes[i][j].value+" ");

// }

// System.out.println();

// }

// }

}

MazeNode:结点类,用于迷宫结点

public class MazeNode {

private int i;

private int j;

private int value;

private boolean[] wayState;

public MazeNode(int value,int i,int j){

wayState = new boolean[Constant.WAYNUM];

this.value = value;

this.i = i;

this.j = j;

}

public int getValue() {

return value;

}

public void setWayState(int direction,boolean isAble) {

wayState[direction] = isAble;

}

public boolean getWayState(int direction) {

return wayState[direction];

}

public void setValue(int value){

this.value = value;

}

public int getI() {

return i;

}

public int getJ() {

return j;

}

}

Constant:常数类,方便使用

public class Constant {

public static final int WAYNUM = 4;

public static final int WAY_EAST = 0;

public static final int WAY_WEST = 1;

public static final int WAY_SOUTH = 2;

public static final int WAY_NORTH = 3;

public static final boolean WAY_ABLE = true;

public static final boolean WAY_DISABLE = false;

}

// System.out.print(mazeNodes[i][j].value+" ");

// }

// System.out.println();

// }

// }

}

MazeNode:结点类,用于迷宫结点

public class MazeNode {

private int i;

private int j;

private int value;

private boolean[] wayState;

public MazeNode(int value,int i,int j){

wayState = new boolean[Constant.WAYNUM];

this.value = value;

this.i = i;

this.j = j;

}

public int getValue() {

return value;

}

public void setWayState(int direction,boolean isAble) {

wayState[direction] = isAble;

}

public boolean getWayState(int direction) {

return wayState[direction];

}

public void setValue(int value){

this.value = value;

}

public int getI() {

return i;

}

public int getJ() {

return j;

}

}

Constant:常数类,方便使用

public class Constant {

public static final int WAYNUM = 4;

public static final int WAY_EAST = 0;

public static final int WAY_WEST = 1;

public static final int WAY_SOUTH = 2;

public static final int WAY_NORTH = 3;

public static final boolean WAY_ABLE = true;

public static final boolean WAY_DISABLE = false;

}


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:基于SpringBoot构建电商秒杀项目代码实例
下一篇:@ConfigurationProperties绑定配置信息至Array、List、Map、Bean的实现
相关文章

 发表评论

暂时没有评论,来抢沙发吧~