Is this how to properly call a method from another method in java? Can someone describe how to create an overloaded method for attack that would allow me to run attack with a base attack modifier? actionPerformed is the method that is the controlling the submit actions of all the buttons that are instantiated in proper java swing style. The command is button dependent and the program is to help model the first fight of an rpg. The attack function calls all the boolean functions to receive various possibilities for the outcome of the button submission. The actionPerformed function should then call the damage function which should update the hp value in the Jtable. The code that demonstrates the functions described is attached. I need some assistance on code troubleshooting if anyone could help me it would be greatly appreciated.
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) {