0

我正在尝试制作一个小弹出游戏。我已经添加了这个故事,一切都很好,直到我添加了这段代码:

    Object[] choices = null;
    Object[] options = { "Caitlyn", "Warwick", "Teemo", "Olaf", "Ashe" };
      int select = JOptionPane.showOptionDialog(null, "Who do you want to fight against?", "Champion selection",
            JOptionPane.CLOSED_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, action
            );

现在,这些选项出现在出现的每个选项对话框上。我该如何解决?

这是我的代码

Object[] choices = null;
    Object[] options = { "Caitlyn", "Warwick", "Teemo", "Olaf", "Ashe" };
      int select = JOptionPane.showOptionDialog(null, "Who do you want to fight against?", "Champion selection",
            JOptionPane.CLOSED_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, action
            );

      switch (select)
        {
        case 0: 
            int cait = 0;
            cait++;
            JOptionPane.showMessageDialog(null, "You will be fighting against the following champion:" + " " + caitlyn.Champion + "  " + "\n She is level" + "  " + caitlyn.Level + " " + "\n And she is a " + caitlyn.Type + "-Champion");

            JOptionPane.showMessageDialog(null, "You have started with 2000HP, Caitlyn has 1700HP.");

            // health

            newchamp.health = 2000;
            caitlyn.enemyhealth = 1700;

            //begin

            Object[] choices1 = null;
            Object[] options1 = { "Criticals", "Pure Damage", "Heal 300 points", "Flee" };
              int action = JOptionPane.showOptionDialog(null, "What will you do?", "action",
                    JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE,
                    null, options, options[0]);

            switch (action)
            {
            case 0: 
                int Criticals = (int) (Math.random()*500);
                Criticals++;
                caitlyn.enemyhealth = (caitlyn.enemyhealth-Criticals);
                JOptionPane.showMessageDialog(null, "Caitlyn now has" +" " + caitlyn.enemyhealth + "HP left");
                break;
            case 1:
                int PureDamage = (int) (Math.random()*300);
                PureDamage++;
                caitlyn.enemyhealth = (caitlyn.enemyhealth-PureDamage);
                JOptionPane.showMessageDialog(null, "Caitlyn now has" + " " + caitlyn.enemyhealth + "HP left");
                break;
            case 2:
                int heal = 300;
                heal++;
                newchamp.health = (newchamp.health+heal);
                JOptionPane.showMessageDialog(null,  "You now have"+ " " + newchamp.health + "HP points!");
                break;
            case 3:
                String flee;
                JOptionPane.showMessageDialog(null, "You failed to flee the battle, better luck next round!");
                break;

            }

            JOptionPane.showMessageDialog(null, "It's Caitlyn's turn now!");
            JOptionPane.showMessageDialog(null, "Caitlyn used a damaging attack!");

            int enemyDamage = (int) (Math.random()*350);
            newchamp.health = (newchamp.health - enemyDamage);
            JOptionPane.showMessageDialog(null, "You now have" + " " + newchamp.health +" "+ " HP Left");

            JOptionPane.showMessageDialog(null, "It's your turn again!");


            Object[] choices2 = null;
            Object[] options2 = { "Criticals", "Pure Damage", "Heal 300 points", "Flee" };
              int action1 = JOptionPane.showOptionDialog(null, "What will you do?", "action",
                    JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE,
                    null, options, options[0]);

            switch (action1)
            {
            case 0: 
                int Criticals = (int) (Math.random()*700);
                Criticals++;
                caitlyn.enemyhealth = (caitlyn.enemyhealth-Criticals);
                JOptionPane.showMessageDialog(null, "Caitlyn now has" +" " + caitlyn.enemyhealth + "HP left");
                break;
            case 1:
                int PureDamage = (int) (Math.random()*300);
                PureDamage++;
                caitlyn.enemyhealth = (caitlyn.enemyhealth-PureDamage);
                JOptionPane.showMessageDialog(null, "Caitlyn now has" + " " + caitlyn.enemyhealth + "HP left");
                break;
            case 2:
                int heal = 300;
                heal++;
                newchamp.health = (newchamp.health+heal);
                JOptionPane.showMessageDialog(null,  "You now have"+ " " + newchamp.health + "HP points!");
                break;
            case 3:
                String flee;
                JOptionPane.showMessageDialog(null,"You have failed to flee the battle, better luck next round!");
                break;

            }
            JOptionPane.showMessageDialog(null, "It's Caitlyn's turn again!");
            JOptionPane.showMessageDialog(null, "Caitlyn hit a critical!");

            int enemyDamage1 = (int) (Math.random()*650);
            newchamp.health = (newchamp.health - enemyDamage);
            JOptionPane.showMessageDialog(null, "You now have" + " " + newchamp.health +" "+ " HP Left");
            if (caitlyn.enemyhealth < newchamp.health){
                JOptionPane.showMessageDialog(null, "Caitlyn is too injured by your strength to continue this battle. You are victorious!");
            }
            else
                JOptionPane.showMessageDialog(null, "You are too injured to continue this battle. You are defeated.");
            break;
        case 1:
            int war = 0;
            war++;
            JOptionPane.showMessageDialog(null, "Warwick is still being made. This window will now exit the program.");
            break;
        case 2:
            int teem = 0;
            teem++;
            JOptionPane.showMessageDialog(null, "Teemo is still being made. This window will now exit the program.");
            break;
        case 3:
            int ola = 0;
            ola++;
            JOptionPane.showMessageDialog(null, "Olaf is still being made. This window will now exit the program.");
            break;
        case 4:
            int ash = 0;
            ash++;
            JOptionPane.showMessageDialog(null, "Ashe is still being made. This window will now exit the program.");
            break;
        }

    }


}
4

1 回答 1

1

您是否注意到这部分代码

Object[] choices2 = null;
        Object[] options2 = { "Criticals", "Pure Damage", "Heal 300 points", "Flee" };
          int action1 = JOptionPane.showOptionDialog(null, "What will you do?", "action",
                JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE,
                null, **options**, options[0]);

** 表示可能的问题。不应该options2吗?(还有一些其他地方可能有同样的错误)

于 2013-02-21T14:12:24.310 回答