基本上我为网络游戏做了一个计时器转,所以如果计时器命中0,转弯将被给予另一个玩家。如果玩家移动并且计时器仍未达到0,则计数将从10重置。我不知道我的计时器出错了。
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
counter++;
if(counter % second == 0){
System.out.println("Times Up");
TimeOut();
}
if(command.startsWith("BOX1")) {
counter=0;
counter++;
}
if(command.startsWith("BOX2")) {
counter=0;
counter++;
}
if(command.startsWith("BOX3")) {
counter=0;
counter++;
}
if(command.startsWith("BOX4")) {
counter=0;
counter++;
}
if(command.startsWith("BOX5")) {
counter=0;
counter++;
}
if(command.startsWith("BOX6")) {
counter=0;
counter++;
}
if(command.startsWith("BOX7")) {
counter=0;
counter++;
}
if(command.startsWith("BOX8")) {
counter=0;
counter++;
}
if(command.startsWith("BOX9")) {
counter=0;
counter++;
}
else{
System.out.println("Time left:" + (second - (counter %second)) );
}
}
}, 3000, 3000);
因此,当我的服务器接收BOX1(客户端移动)时,定时器应该为0并再次递增,但我的计数器卡在1