【问题标题】:What to put in my if statement在我的 if 语句中放入什么
【发布时间】:2014-05-19 02:21:27
【问题描述】:

好的,所以我创建了一个游戏,它运行良好,除了我不希望玩家在一次失败后获胜我希望他必须杀死 10 个敌人我创建了我的 spawnmore 方法,我知道我的问题只是不知道如何解决它,在我的 if 语句中,我有它说 if(dead

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();


    }

【问题讨论】:

    标签: java swing if-statement time timer


    【解决方案1】:

    如果我理解正确,您可以将 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();
    
    
    }
    

    【讨论】:

      猜你喜欢
      • 2015-08-18
      • 1970-01-01
      • 2021-11-19
      • 2013-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-02
      相关资源
      最近更新 更多