gpt4 book ai didi

java - JOptionPane.showOptionDialog 不工作

转载 作者:行者123 更新时间:2023-12-01 14:49:44 26 4
gpt4 key购买 nike

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

    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;
}

}


}

最佳答案

你注意到这部分代码了吗

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 吗? (还有一些其他地方也可能出现同样的错误)

关于java - JOptionPane.showOptionDialog 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15004083/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com