我正在尝试在每次重生之间生成第二次延迟但没有运气的僵尸,即使使用计时器也没有延迟,并且似乎正在循环,但是我不确定自己做错了什么吗? ??
任何人都可以帮助的人,<3
public class Zombie extends GameObject{
Rectangle[] zombies = new Rectangle[60];
Timer timer = new Timer();
public Zombie(float x, float y, ID id, SpriteSheet ss) {
super(x, y, id, ss);
Delay();
}
public void Delay(){
timer.schedule(task, 0, 1000);
}
TimerTask task = new TimerTask(){
public void run(){
for(int i = 0; i < zombies.length; i++){
Random rand = new Random();
int result = rand.nextInt(6);
if(result == 0){
x = 1000;
y = 200;
}
if(result == 1){
x = 100;
y = 200;
}
if(result == 2){
x = 100;
y = 600;
}
if(result == 3){
x = 1000;
y = 600;
}
if(result == 4){
x = 100;
y = 900;
}
if(result == 5){
x = 1000;
y = 900;
}
zombies[i] = new Rectangle((int)x, (int)y, 32, 48);
if(i >= zombies.length){
task.cancel();
}
}
}
};
public void tick() {
}
public void render(Graphics g) {
for(int i = 0; i < zombies.length; i++){
g.setColor(Color.YELLOW);
g.fillRect((int)zombies[i].x, (int)zombies[i].y, 32, 48);
}
}
public Rectangle getBounds() {
return new Rectangle((int)x, (int)y, 32, 48);
}
}
答案 0 :(得分:0)
查看以下更改。我尚未对此进行测试,但我认为它会起作用。我添加了spawnedZombies计数器并删除了for循环。我还更改了停止计时器任务的条件。
我同意迈克尔的评论,即您在僵尸类中有60个僵尸,这是令人困惑的,但这是另一种讨论:)
<label for="name">Name:</label>
<input type="text" id="name" name="name" required
minlength="4" maxlength="8" size="10" runat="server">