import javax.swing.*;
import java.awt.event.*; //Needed for action event listeners for the buttons
class DnDFormulator extends JFrame
{
public static boolean criticalStrikeTrueOrFalse;
int MA = 0; //Main Attribute - Attack Formula
int WR = 0; //Weapon Roll - Attack Formula
int PBA = 0; //Passive Bonus - Attack Formula
int BD = 0; //Base Damage - Attack Formula
int CON = 0; //Constitution - Defence Formula
int ARM = 0; //Armor - Defense Formula
int PBD = 0; //Passive Bonus - Defense Formula
int SD = 0; //Spell Damage - Magic Formula
int INT = 0; //Intellect - Magic Formula
int PBM = 0; //Passive Bonus - Magic Formula
int SP = 0; //Spell power - Magic Formula
int HP = 0; //Healing Power = Magic Frmula
public static double AFO = 0.0; //Attack Formula Output
public static double DFO = 0.0; //Defence Formula Output
public static double MFO = 0.0; //Magic Formula Output
public static JTextArea magicFormulaSpellDamage = new JTextArea("", 1, 4); //String, Rows, Columns
public static JTextArea magicFormulaIntellect = new JTextArea("", 1, 4); //String, Rows, Columns
public static JTextArea magicFormulaPassiveBonus = new JTextArea("", 1, 4); //String, Rows, Columns
public static JTextArea magicFormulaSpellPower = new JTextArea("", 1, 4); //String, Rows, Columns
public static JTextArea magicFormulaHealingPower = new JTextArea("", 1, 4); //String, Rows, Columns
public static JTextArea attackFormulaOutput = new JTextArea("", 1, 4); //String, Rows, Columns
public static JTextArea defenceFormulaOutput = new JTextArea("", 1, 4); //String, Rows, Columns
public static JTextArea magicFormulaOutput = new JTextArea("", 1, 4); //String, Rows, Columns
public static JLabel attackFormulaLabel1 = new JLabel("Main Attribute");
public static JLabel attackFormulaLabel2 = new JLabel("Weapon Roll");
public static JLabel attackFormulaLabel3 = new JLabel("Passive Bonus");
public static JLabel attackFormulaLabel4 = new JLabel("Base Damage");
public static JLabel defenceFormulaLabel1 = new JLabel("Constitution");
public static JLabel defenceFormulaLabel2 = new JLabel("Armor");
public static JLabel defenceFormulaLabel3 = new JLabel("Passive Bonus");
public static JLabel criticalStrikeLabel1 = new JLabel("Crit?");
public static JLabel magicFormulaLabel1 = new JLabel("Spell Damage");
public static JLabel magicFormulaLabel2 = new JLabel("Intellect");
public static JLabel magicFormulaLabel3 = new JLabel("Passive Bonus");
public static JLabel magicFormulaLabel4 = new JLabel("Spell Power");
public static JLabel magicFormulaLabel5 = new JLabel("Healing Power");
public static JLabel attackFormulaOutputLabel = new JLabel("A Output");
public static JLabel defenceFormulaOutputLabel = new JLabel("D Output");
public static JLabel magicFormulaOutputLabel = new JLabel("M Output");
public static JLabel attackFormulaLineLabel = new JLabel("AF");
public static JLabel defenceFormulaLineLabel = new JLabel("DF");
public static JLabel magicFormulaLineLabel = new JLabel("MF");
public static JTextArea attackFormulaMainAttribute = new JTextArea("", 1, 4); //String, Rows, Columns
public static JTextArea attackFormulaWeaponRoll = new JTextArea("", 1, 4); //String, Rows, Columns
public static JTextArea attackFormulaPassiveBonus = new JTextArea("", 1, 4); //String, Rows, Columns
public static JTextArea attackFormulaBaseDamage = new JTextArea("", 1, 4); //String, Rows, Columns
public static JTextArea defenceFormulaConstitution = new JTextArea("", 1, 4); //String, Rows, Columns
public static JTextArea defenceFormulaArmor = new JTextArea("", 1, 4); //String, Rows, Columns
public static JTextArea defenceFormulaPassiveBonus = new JTextArea("", 1, 4); //String, Rows, Columns
public static JRadioButton criticalStrikeTrue = new JRadioButton("True"); //Creates a radio button that says True beside it.
public static JRadioButton criticalStrikeFalse = new JRadioButton("False"); //Creates a radio button that says False beside it.
public static void main(String args[])
{
JFrame frame = new JFrame();
JPanel panel = new JPanel();
frame.setTitle("DnD Formulator");
frame.setSize(640, 480); //Sets the size of the game window
frame.setLocationRelativeTo(null); //Centers the window on the users screen.
frame.setResizable(false); //Makes it so that the user cannot resize the JFrame.
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.getContentPane().add(panel);
panel.setLayout(null); //Makes it so you can manually positon everything using XY coords.
frame.setVisible(true); //Makes the JFrame, also known ass gameWindow visible to the user.
ButtonGroup criticalButtonGroup = new ButtonGroup(); //Creates a group so that we can group together radio buttons.
criticalButtonGroup.add(criticalStrikeTrue); //Adds the criticalStrikeTrue radio button to be added to the criticalButtonGroup.
criticalButtonGroup.add(criticalStrikeFalse); //Adds the criticalStrikeFalse radio button to be added to the criticalButtonGroup.
criticalStrikeFalse.setSelected(true); //Sets the criticalStrikeFalse radio button to be selected automatically.
JButton calculateButton = new JButton("Calculate!");
panel.add(calculateButton);
panel.add(attackFormulaMainAttribute);
panel.add(attackFormulaWeaponRoll);
panel.add(attackFormulaPassiveBonus);
panel.add(attackFormulaBaseDamage);
panel.add(defenceFormulaConstitution);
panel.add(defenceFormulaArmor);
panel.add(defenceFormulaPassiveBonus);
panel.add(criticalStrikeTrue);
panel.add(criticalStrikeFalse);
panel.add(magicFormulaSpellDamage);
panel.add(magicFormulaIntellect);
panel.add(magicFormulaPassiveBonus);
panel.add(magicFormulaSpellPower);
panel.add(magicFormulaHealingPower);
panel.add(attackFormulaOutput);
panel.add(defenceFormulaOutput);
panel.add(magicFormulaOutput);
panel.add(attackFormulaLabel1);
panel.add(attackFormulaLabel2);
panel.add(attackFormulaLabel3);
panel.add(attackFormulaLabel4);
panel.add(defenceFormulaLabel1);
panel.add(defenceFormulaLabel2);
panel.add(defenceFormulaLabel3);
panel.add(criticalStrikeLabel1);
panel.add(magicFormulaLabel1);
panel.add(magicFormulaLabel2);
panel.add(magicFormulaLabel3);
panel.add(magicFormulaLabel4);
panel.add(magicFormulaLabel5);
panel.add(attackFormulaOutputLabel);
panel.add(defenceFormulaOutputLabel);
panel.add(magicFormulaOutputLabel);
panel.add(attackFormulaLineLabel);
panel.add(defenceFormulaLineLabel);
panel.add(magicFormulaLineLabel);
attackFormulaMainAttribute.setBounds(50, 50, 50, 20); //X position, Y Position, Length in pixels, Height in pixels.
attackFormulaWeaponRoll.setBounds(140, 50, 50, 20); //X position, Y Position, Length in pixels, Height in pixels.
attackFormulaPassiveBonus.setBounds(230, 50, 50, 20); //X position, Y Position, Length in pixels, Height in pixels.
attackFormulaBaseDamage.setBounds(320, 50, 50, 20); //X position, Y Position, Length in pixels, Height in pixels.
defenceFormulaConstitution.setBounds(50, 90, 50, 20); //X position, Y Position, Length in pixels, Height in pixels.
defenceFormulaArmor.setBounds(140, 90, 50, 20); //X position, Y Position, Length in pixels, Height in pixels.
defenceFormulaPassiveBonus.setBounds(230, 90, 50, 20); //X position, Y Position, Length in pixels, Height in pixels.
criticalStrikeTrue.setBounds(50, 120, 80, 20); //X position, Y Position, Length in pixels, Height in pixels.
criticalStrikeFalse.setBounds(130, 120, 80, 20); //X position, Y Position, Length in pixels, Height in pixels.
magicFormulaSpellDamage.setBounds(50, 160, 50, 20); //X position, Y Position, Length in pixels, Height in pixels.
magicFormulaIntellect.setBounds(140, 160, 50, 20); //X position, Y Position, Length in pixels, Height in pixels.
magicFormulaPassiveBonus.setBounds(230, 160, 50, 20); //X position, Y Position, Length in pixels, Height in pixels.
magicFormulaSpellPower.setBounds(320, 160, 50, 20); //X position, Y Position, Length in pixels, Height in pixels.
magicFormulaHealingPower.setBounds(410, 160, 50, 20); //X position, Y Position, Length in pixels, Height in pixels.
attackFormulaOutput.setBounds(50, 250, 50, 20); //X position, Y Position, Length in pixels, Height in pixels.
defenceFormulaOutput.setBounds(140, 250, 50, 20); //X position, Y Position, Length in pixels, Height in pixels.
magicFormulaOutput.setBounds(230, 250, 50, 20); //X position, Y Position, Length in pixels, Height in pixels.
attackFormulaOutput.setEditable(false); //Makes it so that the user cannot type in this JTextArea
defenceFormulaOutput.setEditable(false); //Makes it so that the user cannot type in this JTextArea
magicFormulaOutput.setEditable(false); //Makes it so that the user cannot type in this JTextArea
attackFormulaMainAttribute.setText("0");
attackFormulaWeaponRoll.setText("0");
attackFormulaPassiveBonus.setText("0");
attackFormulaBaseDamage.setText("0");
defenceFormulaConstitution.setText("0");
defenceFormulaArmor.setText("0");
defenceFormulaPassiveBonus.setText("0");
magicFormulaSpellDamage.setText("0");
magicFormulaIntellect.setText("0");
magicFormulaPassiveBonus.setText("0");
magicFormulaSpellPower.setText("0");
magicFormulaHealingPower.setText("0");
attackFormulaOutput.setText("0");
defenceFormulaOutput.setText("0");
magicFormulaOutput.setText("0");
attackFormulaLabel1.setBounds(50, 30, 100, 20); //X position, Y Position, Length in pixels, Height in pixels.
attackFormulaLabel2.setBounds(140, 30, 100, 20); //X position, Y Position, Length in pixels, Height in pixels.
attackFormulaLabel3.setBounds(230, 30, 100, 20); //X position, Y Position, Length in pixels, Height in pixels.
attackFormulaLabel4.setBounds(320, 30, 100, 20); //X position, Y Position, Length in pixels, Height in pixels.
defenceFormulaLabel1.setBounds(50, 70, 100, 20); //X position, Y Position, Length in pixels, Height in pixels.
defenceFormulaLabel2.setBounds(140, 70, 100, 20); //X position, Y Position, Length in pixels, Height in pixels.
defenceFormulaLabel3.setBounds(230, 70, 100, 20); //X position, Y Position, Length in pixels, Height in pixels.
criticalStrikeLabel1.setBounds(20, 120, 100, 20); //X position, Y Position, Length in pixels, Height in pixels.
magicFormulaLabel1.setBounds(50, 140, 100, 20); //X position, Y Position, Length in pixels, Height in pixels.
magicFormulaLabel2.setBounds(140, 140, 100, 20); //X position, Y Position, Length in pixels, Height in pixels.
magicFormulaLabel3.setBounds(230, 140, 100, 20); //X position, Y Position, Length in pixels, Height in pixels.
magicFormulaLabel4.setBounds(320, 140, 100, 20); //X position, Y Position, Length in pixels, Height in pixels.
magicFormulaLabel5.setBounds(410, 140, 100, 20); //X position, Y Position, Length in pixels, Height in pixels.
attackFormulaOutputLabel.setBounds(50, 230, 100, 20); //X position, Y Position, Length in pixels, Height in pixels.
defenceFormulaOutputLabel.setBounds(140, 230, 100, 20); //X position, Y Position, Length in pixels, Height in pixels.
magicFormulaOutputLabel.setBounds(230, 230, 100, 20); //X position, Y Position, Length in pixels, Height in pixels.
attackFormulaLineLabel.setBounds(30, 50, 100, 20); //X position, Y Position, Length in pixels, Height in pixels.
defenceFormulaLineLabel.setBounds(30, 90, 100, 20); //X position, Y Position, Length in pixels, Height in pixels.
magicFormulaLineLabel.setBounds(30, 160, 100, 20); //X position, Y Position, Length in pixels, Height in pixels.
calculateButton.setBounds(50, 400, 100, 20);
calculateButton.setFocusPainted(false);
calculateButton.addActionListener(new ActionListener() { //Action listener for the newGameButton
public void actionPerformed(ActionEvent e) {
DnDFormulator DnDFormulator = new DnDFormulator();
DnDFormulator.attackCalculationMethod();
DnDFormulator.defenceCalculationMethod();
DnDFormulator.magicCalculationMethod();
attackFormulaOutput.setText(""+AFO+"");
defenceFormulaOutput.setText(""+DFO+"");
magicFormulaOutput.setText(""+MFO+"");
}});
}
public double attackCalculationMethod()
{
String AF1 = attackFormulaMainAttribute.getText();
String AF2 = attackFormulaWeaponRoll.getText();
String AF3 = attackFormulaPassiveBonus.getText();
String AF4 = attackFormulaBaseDamage.getText();
MA = Integer.parseInt(AF1);
WR = Integer.parseInt(AF2);
PBA = Integer.parseInt(AF3);
BD = Integer.parseInt(AF4);
if ( criticalStrikeTrue.isSelected() )
AFO = ( ( ( MA / 2 ) + WR + PBA + BD ) * 2 );
else
AFO = ( ( MA / 2 ) + WR + PBA + BD);
return AFO;
}
public double defenceCalculationMethod()
{
String DF1 = defenceFormulaConstitution.getText();
String DF2 = defenceFormulaArmor.getText();
String DF3 = defenceFormulaPassiveBonus.getText();
CON = Integer.parseInt(DF1);
ARM = Integer.parseInt(DF2);
PBD = Integer.parseInt(DF3);
criticalStrikeTrueOrFalse = criticalStrikeTrue.isSelected();
if ( criticalStrikeTrue.isSelected() )
DFO = ( ( (CON / 3) + ARM + PBD ) * 2 );
else
DFO = ( (CON / 3) + ARM + PBD );
return DFO;
}
public double magicCalculationMethod()
{
String MF1 = magicFormulaSpellDamage.getText();
String MF2 = magicFormulaIntellect.getText();
String MF3 = magicFormulaPassiveBonus.getText();
String MF4 = magicFormulaSpellPower.getText();
String MF5 = magicFormulaHealingPower.getText();
SD = Integer.parseInt(MF1);
INT = Integer.parseInt(MF2);
PBM = Integer.parseInt(MF3);
SP = Integer.parseInt(MF4);
HP = Integer.parseInt(MF5);
int SHP = 1;
if ( SP == 0 )
SHP = HP;
else
SHP = SP;
if ( PBM == 0)
PBM = 1;
criticalStrikeTrueOrFalse = criticalStrikeTrue.isSelected();
if ( criticalStrikeTrue.isSelected() )
MFO = ( ( ( ( SD + ( INT / 2 ) ) * PBM ) * ( SHP / 2 ) ) * 2 );
else
MFO = ( ( ( SD + ( INT / 2 ) ) * PBM ) * ( SHP / 2 ) );
return MFO;
}
}