0
我正在研究一组代码,在每个“转向”(转弯时是所有3匹马都转过去)之后,相位上升了1.但是,当我运行它并输出相位最后总是会回到0.在这种情况下实施阶段计数的最佳方式是什么?在while语句中实现一个计数
while (horse1.getLocation() <= 250 && horse2.getLocation() <= 250 && horse3.getLocation() <= 250){
int phase = 0;
horse1.move(phase);
horse2.move(phase);
horse3.move(phase);
horse1.location++;
horse2.location++;
horse3.location++;
phase++;
}
将'int phase = 0;'移到循环外部。您每次迭代都将其重置为0。 –