これはJavaで別のメソッドからメソッドを正しく呼び出す方法ですか? 基本攻撃修飾子を使用して攻撃を実行できるようにする、攻撃用のオーバーロードされたメソッドを作成する方法を誰かが説明できますか? actionPerformed は、適切な Java Swing スタイルでインスタンス化されたすべてのボタンの送信アクションを制御するメソッドです。コマンドはボタンに依存し、プログラムは RPG の最初の戦いをモデル化するのに役立ちます。攻撃関数は、すべてのブール関数を呼び出して、ボタン送信の結果のさまざまな可能性を受け取ります。actionPerformed 関数は、Jtable の hp 値を更新する Damage 関数を呼び出す必要があります。説明されている機能を示すコードが添付されています。誰かが私を助けてくれれば、コードのトラブルシューティングに関する支援が必要です。
public void actionPerformed(ActionEvent event)
{
String command = event.getActionCommand();
this.getRows(table);
rows = this.rows;
firstRow = rows[0];
lastRow = rows[1];
if(command == "Shield Bash") {
this.attack(firstRow, lastRow, command, table);
damage = this.damage;
this.damage(table, firstRow, damage);
}else if(command == "Run Threw") {
}else if(command == "React") {
this.attack(firstRow, lastRow, command, table);
damage = this.damage;
this.damage(table, firstRow, damage);
}else if (command == "Attack") {
this.attack(firstRow, lastRow, command, table);
damage = this.damage;
this.damage(table, firstRow, damage);
}else if (command == "Skill") {
}else if (command == "Heal") {
}else if (command == "Rest") {
}else if (command == "Skulk") {
}else {
}
}
public boolean block (JTable table, int defendersRow) {
defendersRow = this.defendersRow;
blockChanceObject = table.getValueAt(defendersRow, 15);
blockChance = (Integer) blockChanceObject;
blockRoll = generator.nextInt(100) + 1;
if(blockRoll < blockChance) {
blocked = true;
}
return blocked;
}
public boolean fumble (JTable table, int attackersRow) {
attackersRow = this.attackersRow;
fumbleChanceObject = table.getValueAt(attackersRow, 7);
fumbleChance = (Integer) fumbleChanceObject;
int fumbleRoll = generator.nextInt(100) + 1;
if (fumbleRoll < fumbleChance) {
fumbled = true;
}
return fumbled;
}
public boolean dodge (JTable table, int defendersRow) {
defendersRow = this.defendersRow;
dodgeChanceObject = table.getValueAt(defendersRow,12);
dodgeChance = (Integer) dodgeChanceObject;
dodgeRoll = generator.nextInt(100) + 1;
if (dodgeRoll < dodgeChance) {
dodged = true;
}
return dodged;
}
public boolean critical (JTable table, int attackersRow, int attackRoll) {
attackersRow = this.attackersRow;
attackRoll = this.attackRoll;
criticalChanceObject = table.getValueAt(attackersRow, 8);
criticalChance = (Integer) criticalChanceObject;
if (attackRoll >= criticalChance) {
criticaled = true;
}
return criticaled;
}
public int[] getRows(JTable table) {
rows[0] = table.getSelectedRow();
rowCount = table.getSelectedRowCount() - 1;
rows[1] = rows[0] + rowCount;
return rows;
}
public int attack(int firstRow, int lastRow, String command, JTable table) {
command = this.command;
firstRow = this.firstRow;
lastRow = this.lastRow;
table = this.table;
if (command == "Bludgeon" || command == "React" || command == "ShieldBash") {
attackersRow = this.lastRow;
defendersRow = this.firstRow;
}else if(command == "Attack" || command == "Skill") {
attackersRow = this.firstRow;
defendersRow = this.lastRow;
}else {
}
this.fumble(table, attackersRow);
if (fumbled == true) {
outputString = "fumbled";
}
attackRoll = generator.nextInt(100) + 1;
this.critical(table, attackersRow, attackRoll);
if (criticaled == true) {
outputString = "criticaled";
}
this.dodge(table, defendersRow);
if (dodged == true) {
outputString = "dodged";
}
this.block(table, defendersRow);
if (blocked == true) {
outputString = "blocked";
}
defenseRoll = generator.nextInt(100) + 1;
attackBaseObject = table.getValueAt(attackersRow, 6);
defenseBaseObject = table.getValueAt(defendersRow, 11);
attackBase = (Integer) attackBaseObject;
defenseBase = (Integer) defenseBaseObject;
attack = attackRoll + attackBase;
defense = defenseRoll + defenseBase;
minDamageObject = table.getValueAt(attackersRow, 9);
minDamage = (Integer) minDamageObject;
maxDamageObject = table.getValueAt(attackersRow, 10);
maxDamage = (Integer) maxDamageObject;
damage = generator.nextInt((maxDamage - minDamage))+minDamage;
if (criticaled == true) {
damage = maxDamage * 2;
}else if (attack >= (defense + 50)) {
damage = damage * 2;
}else if (attack >= defense) {
damage = damage;
}else {
damage = 0;
}
this.outputSelection(outputString, attackersRow, defendersRow, table, command, damage);
return damage;
}
private void damage(JTable table, int defendersRow, int damage) {
damage = this.damage;
defendersRow = this.defendersRow;
hpObject = table.getValueAt(defendersRow, 3);
hp = (Integer) hpObject;
hp = hp - damage;
table.setValueAt(hp, defendersRow, 3);
}
private void outputSelection(String outputString, int attackersRow, int defendersRow, JTable table, String command, int damage) {