Я - новый программист, делающий игру в данный момент, но мне трудно решить, как разрешить людям выбирать роль, каждая роль имеет разные значения для ущерба здоровью и т. Д., Но я хотел, чтобы это было в цикле, так что если это было неправильно набрал, он просто снова задаст вопрос, есть ли лучшие способы сделать это, чтобы я мог получить доступ к переменным везде в моем коде?
int damage;
int health;
int speed;
int x = 0;
while(x == 0) {
String role;
System.out.println("Would you like to select a knight, wizard, or rogue? If you would like more information on class tpye: info(class) with no spaces.");
role = user_input.next();
if (role.equalsIgnoreCase("infoknight")) {
System.out.println("You start with a normal sword. The knight has 15 health, 10 damage, and 5 speed");
}else if(role.equalsIgnoreCase("infowizard")){
System.out.println("You start with a normal wand. The wizard has 10 health 10 damage and 10 speed and is the most balanced class to start with");
}else if(role.equalsIgnoreCase("inforogue")) {
System.out.println("You start with a normal dagger. The rogue has 10 health, 5 damge, and 15 speed and is the most difficult class to start with\n");
}else if(role.equalsIgnoreCase("knight")) {
System.out.println("You selected a knight!\nYou will start with a wooden sword.");
damage = 10;
health = 15;
speed = 5;
x = 1;
}else if(role.equalsIgnoreCase("Wizard")) {
System.out.println("You selected a wizard!\n You will start with a old wand.");
damage = 10;
health = 10;
speed = 10;
x = 1;
}else if(role.equalsIgnoreCase("rogue")) {
System.out.println("You selected a rogue!\nYou will start with a dull dagger");
damage = 5;
health = 10;
speed = 15;
x = 1;
}else {
System.out.println("Incorrectly typed please try again");
}
}