对象应该根据经过的时间(在追逐或分散之间切换)改变模式(运动算法)。我创建了一个while循环,但对象仅以一种模式(追逐)移动,这很奇怪,因为我最初将它设置为分散。
private static int seconds=0;
private static boolean ghostalive;
protected static final int chaseMode = 0;
protected static final int scatterMode = 1;
protected static final int frightenedMode = 2;
static int mode; //initially ghost start in scatterMode
public Ghost(int x, int y, Maze maze){
super(x, y, maze);
futureDirection = 0;
timer = 0;
mode = getMode();
}
public static int getMode(){
mode=setMode();
return mode;
}
//LEVEL 1
//scatter for 7s
//chase for 20s
//scatter for 7s
//chase for 20s
//scatter for 5s
//chase for 20s
//scatter for 5s
//chase indefinite
public static int setMode(){
while(ghostalive){
mode = scatterMode;
if(seconds>7)
mode = chaseMode;//chaseMode=true;
if(seconds>27)
mode = scatterMode;
if(seconds>34)
mode = chaseMode;
if(seconds>54)
mode = scatterMode;
if(seconds>59)
mode = chaseMode;
if(seconds>79)
mode = scatterMode;
if(seconds>84)
mode = chaseMode;
seconds++;
}
return mode;
}