При попытке сделать ролик игры в кости TTRPG программа не отображает содержимое, несмотря на отсутствие ошибок.JAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 При попытке сделать ролик игры в кости TTRPG программа не отображает содержимое, несмотря на отсутствие ошибок.

Сообщение Anonymous »

Я пытаюсь сделать игру в кости TTRPG с помощью Java в приложении Java FX. Пока что у меня так: программа пропускает блок try и ничего не показывает на экране, консоль ошибок не показывает. Вы можете помочь мне? Я пишу это для личного проекта. Я тоже студент, поэтому мало что знаю о программировании и стараюсь максимально избегать использования ИИ.
public class DiceController {

@FXML
Label rollResult, separatedDice;
@FXML
TextField diceNotationField;
@FXML
Button diceRollButton;

public void roll() {
try {

// get text from field
String diceNotation = diceNotationField.getText();

// Use a regex tp detect dice notation
Pattern regex = Pattern.compile("(\\d+)?d(\\d+)(?:([\\+\\*\\/\\-])(\\d+))?");
Matcher m = regex.matcher(diceNotation);

String diceQuantity = "";
String diceSize = "";
String diceSign = "";
String diceModifier = "";

// Call Random to create a random number
Random rand = new Random();

// if the dice quantity is null is set to 1
if (diceQuantity == null || diceQuantity.isEmpty()) {
diceQuantity = "1";
}

// regex matcher check
if (!m.matches()) {
rollResult.setText("Intruduce a valid dice notation");
} else if (m.matches()) {
diceQuantity = m.group(1);
diceSize = m.group(2);

// Create an array to store the result of each dice
int diceResultArray[] = new int[Integer.parseInt(diceQuantity)];

// this variable will generate a random number rolling the dice
int randomResultInDice = 0;

// this variable stores the total result
int total = 0;

for (int i = 0; i < Integer.parseInt(diceQuantity); i++) {
// generates a random number on the dice,
randomResultInDice = rand.nextInt(1, Integer.parseInt(diceSize) + 1);
// stores the separate values of each dice's results in an array
diceResultArray = randomResultInDice;
// sums the result of the separate dice
total += randomResultInDice;
}

// if there's no sign the string stays empty, else, the regex group is
// recognized and the corresponding operation is performed
if (diceSign == null || diceSign.isEmpty() && diceModifier == null || diceModifier.isEmpty()) {
diceSign = "";
diceModifier = "";
} else {
diceSign = m.group(3);
diceModifier = m.group(4);

// stores the total result of the dice plus the operation corresponding to the
// modifier
int totalMod = 0;

switch (diceSign) {
case "+":
totalMod = total + Integer.parseInt(diceModifier);
rollResult.setText(String.valueOf(totalMod));
separatedDice.setText(String.valueOf(Arrays.toString(diceResultArray)));
break;
case "-":
totalMod = total - Integer.parseInt(diceModifier);
rollResult.setText(String.valueOf(totalMod));
separatedDice.setText(String.valueOf(Arrays.toString(diceResultArray)));
break;
case "*":
totalMod = total * Integer.parseInt(diceModifier);
rollResult.setText(String.valueOf(totalMod));
separatedDice.setText(String.valueOf(Arrays.toString(diceResultArray)));
break;
case "/":
if (Integer.parseInt(diceModifier) != 0) {
totalMod = total / Integer.parseInt(diceModifier);
rollResult.setText(String.valueOf(totalMod));
separatedDice.setText(String.valueOf(Arrays.toString(diceResultArray)));
} else {
totalMod = total;
rollResult.setText(String.valueOf(total));
}

break;
default:
rollResult.setText(String.valueOf(total));
separatedDice.setText(String.valueOf(Arrays.toString(diceResultArray)));
break;
}
}

}

} catch (Exception e) {
rollResult.setText(e.toString());
System.out.println(e);
}
}
}

Файл FXML:

























































Подробнее здесь: https://stackoverflow.com/questions/798 ... here-are-n
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»