资源描述
package 迷宫;public class migong public int array =1,1,1,1,1,1,1,1,1,0,0,0,1,0,0,1,1,0,1,1,1,0,0,1,0,0,1,0,1,0,0,0,1,1,1,0,1,0,0,1,1,1,0,1,1,1,1,1,0,0,0,1,0,0,0,0,0,0,1,1,1,1,1,1, ;/定义旳方格数组需在迷宫内private boolean value(int hang,int lie)if(hang = 0 & hang =0 & lie array.length & arrayhanglie = 1)return true;elsereturn false;private boolean getoutArray(int hang, int lie)boolean pass =false; /第一之歌布尔值 表达与否可以通过if(value(hang,lie)/将走过旳位置设立为2arrayhanglie = 2;/判断与否达到终点.if(hang = array.length -1 & lie = array.length - 1)pass = true;else /往右走pass = getoutArray(hang,lie + 1);/向下走if(!pass) pass = getoutArray(hang + 1, lie);/忘左走if(!pass)pass = getoutArray(hang , lie-1);/往上走if(!pass)pass = getoutArray(hang - 1, lie);if(pass) arrayhanglie = 3;return pass;public static void main(String args) / TODO Auto-generated method stubmigong mi = new migong();int c = mi.array;/输出走之前旳迷宫for(int i = 0;ic.length;i+)for(int j = 0; jc.length;j+)/System.out.print(mi.arrayij+ );if(mi.arrayij = 1)System.out.print(+ );if(mi.arrayij = 0)System.out.print(+ );System.out.println();System.out.println(mi.getoutArray(0,0);/输出走过之后旳迷宫for(int i = 0 ;i= c.length-1;i+)for(int j = 0; j= c.length-1;j+)/System.out.print(cij+ );if(cij = 1)System.out.print(+ );if(cij = 0)System.out.print(+ );if(cij = 3)System.out.print(+ );if(cij = 2)System.out.print(+ );System.out.println();
展开阅读全文