请问Java中debug和run的结果不同该怎么解决
洛酒 2017-12-21 11:10:01 Java实践的作业我写的是一个联机的飞行棋,然后现在投掷到6时点击飞机应该起飞,debug时一切正常飞机确实起飞了,但是run时就没有反应,请问下是为什么
部分代码:
// 投掷骰子
JButton PlayButton = new JButton(Pplay);
PlayButton.setBounds(855, 180, 150, 50);
PlayButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
int rand = (int) (Math.random() * 6);
diceLable.setIcon(RandomDice[rand]);
gameControl.setStep(rand);
gameControl.setTypePlane(TypePlane);
gameControl.setLine(gameData.getLine(GameDispose.COLORARRAY[TypePlane % 4]));
TypePlane++;
PlayButton.setVisible(false);
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
diceLable.setIcon(resultDice[rand]);
PlayButton.setVisible(true);
PlaneMove();
}
}, 2000);
}
});
// 飞机移动
public void PlaneMove() {
int TypeOfPlane = gameControl.getTypePlane();
int StepOfPlane = gameControl.getStep();
Plane[] ChoosePlane = new Plane[4];
for (int i = 0; i < 4; i++)
ChoosePlane[i] = planes[TypeOfPlane][i];
// 添加鼠标监听
for (Plane p1 : ChoosePlane)
p1.addMouseListener();
while (true) {
// 当玩家选择了要移动的飞机时
//int current = gameData.getNumberOfCurrentPlane();
if (gameData.getNumberOfCurrentPlane() != -1) {
// 移动选中的飞机
gameControl.movePlane(gameData.getNumberOfCurrentPlane(), StepOfPlane, ChoosePlane[gameData.getNumberOfCurrentPlane()]);
// 重置当前选中飞机编号为-1
gameData.setNumberOfCurrentPlane(-1);
// 移除鼠标监听
for (Plane p2 : ChoosePlane)
p2.removeMouseListener();
break;
}
}
}
// 移动飞机
public void movePlane(int index, int stepOfPlanes, Plane plane) {
// 飞机在停机坪
if (plane.getLoc() == -2) {
//if (stepOfPlanes == 6)
FrameGame.PlaneStart(this.typePlane, index);
}
// 飞机起飞位置
public static void PlaneStart(int type, int index) {
if (type == 0)
planes[0][index].setLocation(156, 704);
else if (type == 1)
planes[1][index].setLocation(16, 159);
else if (type == 2)
planes[2][index].setLocation(561, 17);
else if (type == 3)
planes[3][index].setLocation(702, 562);
planes[type][index].setLoc(-1);
}