Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在我的if语句中输入什么_Java_Swing_If Statement_Time_Timer - Fatal编程技术网

Java 在我的if语句中输入什么

Java 在我的if语句中输入什么,java,swing,if-statement,time,timer,Java,Swing,If Statement,Time,Timer,好吧,我已经创建了一个游戏,它运行得非常完美,除了我不希望玩家在一次失败后获胜我希望他必须杀死10个敌人好吧,我创建了我的spawnmore方法,我知道问题我只是不知道如何修复它,在我的if语句中我说如果(死亡

好吧,我已经创建了一个游戏,它运行得非常完美,除了我不希望玩家在一次失败后获胜我希望他必须杀死10个敌人好吧,我创建了我的spawnmore方法,我知道问题我只是不知道如何修复它,在我的if语句中我说如果(死亡<10),然后做我的事情,当我每次只想做一次的时候,如果你明白我的意思的话,我的方法是,谢谢

public void spawnMore(){
        int delay = 1000;


        Timer time = new Timer(delay, new ActionListener(){

            public void actionPerformed(ActionEvent e){

                if(WizardCells[BadGuy.getx()][BadGuy.gety()].getIcon() != null){
                    return;
                }


                if(WizardCells[BadGuy.getx()][BadGuy.gety()].getIcon() == null){
                    dead += 1;
                }

                if(dead < 10){
                    int where = (int)(10 + Math.random() *9);
                    BadGuy.spawnEnemy(where, where);
                    move();

                }
            }
        });
        time.start();


    }
public void spawnemore(){
int延迟=1000;
计时器时间=新计时器(延迟,新ActionListener(){
已执行的公共无效操作(操作事件e){
if(WizardCells[BadGuy.getx()][BadGuy.gety()].getIcon()!=null){
返回;
}
if(WizardCells[BadGuy.getx()][BadGuy.gety()].getIcon()==null){
死亡+=1;
}
如果(死<10){
int其中=(int)(10+Math.random()*9);
坏人。敌人(哪里,哪里);
move();
}
}
});
time.start();
}

如果我理解正确,您可以将If语句移到前面的If语句中:

public void spawnMore(){
    int delay = 1000;


    Timer time = new Timer(delay, new ActionListener(){

        public void actionPerformed(ActionEvent e){

            if(WizardCells[BadGuy.getx()][BadGuy.gety()].getIcon() != null){
                return;
            }


            if(WizardCells[BadGuy.getx()][BadGuy.gety()].getIcon() == null){
                dead += 1;

                if(dead < 10){
                    int where = (int)(10 + Math.random() *9);
                    BadGuy.spawnEnemy(where, where);
                    move();
                }
            }

        }
    });
    time.start();


}
public void spawnemore(){
int延迟=1000;
计时器时间=新计时器(延迟,新ActionListener(){
已执行的公共无效操作(操作事件e){
if(WizardCells[BadGuy.getx()][BadGuy.gety()].getIcon()!=null){
返回;
}
if(WizardCells[BadGuy.getx()][BadGuy.gety()].getIcon()==null){
死亡+=1;
如果(死<10){
int其中=(int)(10+Math.random()*9);
坏人。敌人(哪里,哪里);
move();
}
}
}
});
time.start();
}