用java在7*7格子上虚拟建立4个连续3格子,为什么又是出现死循环,哪里出错了,新人求解 第一个类
public class playTextDriver{
public static void main(String[] args){
play a=new play();
a.setRandomLocations();
}
}
第二个类
public class play{
private int [][] locations=new int[7][7];
private int x,y;
private int direction;
do{
boolean goOnMakeDirection;
do
{
makeDirection();
//System.out.println("direction="+direction);
int j=0;
for(j=0;j<4;j++){
if(direction==text[j])
break;}
if(j==4)
goOnMakeDirection=false;
else
goOnMakeDirection=true;
}
while(goOnMakeDirection);
switch(direction)
{
case 0:rightDir=rightDirection(x,y-1,x,y-2);text[0]=0;break;
case 1:rightDir=rightDirection(x,y+1,x,y+2);text[1]=1;break;
case 2:rightDir=rightDirection(x-1,y,x-2,y);text[2]=2;break;
case 3:rightDir=rightDirection(x+1,y,x+2,y);text[3]=3;break;
}
//************************************
private void addNewDotCom(){//根据给定的坐标和方向,添加3个连续的坐标
locations[x][y]=-1;
switch(direction)
{
case 0:locations[x][y-1]=-1;locations[x][y-2]=-1;break;
case 1:locations[x][y+1]=-1;locations[x][y+2]=-1;break;
case 2:locations[x-1][y]=-1;locations[x-2][y]=-1;break;
case 3:locations[x+1][y]=-1;locations[x+2][y]=-1;break;
}