// Class for initializing values for each Goblin trait
public class Goblin {
    // Initialize all trait variables
    private String name;
    private int HP;
    private int DMG;
    private double hitChance;

    // Get methods for each trait value
    public String getName() {
        return name;
    }

    public int getHP() {
        return HP;
    }

    public int getDMG() {
        return DMG;
    }

    public double getHitChance() {
        return hitChance;
    }

    public boolean isAlive() {
        if (this.HP > 0) {
            return true;
        } else {
            return false;
        }
    }


    // Set methods for each trait value
    public void setName(String newName) {
        this.name = newName;
    }

    public void setHP(int newHP) {
        this.HP = newHP;
    }

    public void takeDMG(int takenDamage) {
        this.HP -= takenDamage;
    }

    public void setDMG(int newDMG) {
        this.DMG = newDMG;
    }

    public void setHitChance(double newHitChance) {
        this.hitChance = newHitChance;
    }
}
// Math import for randomization
import java.lang.Math;

// Class that simulates the outcome of fights between 2 goblins
public class Duel {
    // Method that simulates each goblin's attack. Every attack either leads to a miss or some amount damage to a goblin.
    public static void attack(Goblin attackerGoblin, Goblin attackeeGoblin) {
        System.out.println(attackerGoblin.getName() + " attacks " + attackeeGoblin.getName() + "!");
        if (Math.random() < attackerGoblin.getHitChance()) {
            attackeeGoblin.takeDMG(attackerGoblin.getDMG());
            System.out.println(attackerGoblin.getName() + " hits!");
            System.out.println(attackeeGoblin.getName() + " takes " + attackerGoblin.getDMG() + " damage");
        } else {
            System.out.println(attackerGoblin.getName() + " misses...");
        }

        System.out.println(attackeeGoblin.getName() + " HP: " + attackeeGoblin.getHP());
        System.out.println();
    }

    // Start up method that runs as long as both goblins are alive
    public static void fight(Goblin goblin1, Goblin goblin2) {
        while (goblin1.isAlive() && goblin2.isAlive()) {
            
            attack(goblin1, goblin2);

            if (!goblin1.isAlive()) {
                System.out.println(goblin1.getName() + " has perished");
                break;
            }

            attack(goblin2, goblin1);

            if (!goblin2.isAlive()) {
                System.out.println(goblin2.getName() + " has perished");
                break;
            }
        }
    }

    public static void main(String[] args) {
        Goblin goblin1 = new Goblin();
        goblin1.setName("Satoru Gojo");
        goblin1.setHP(10);
        goblin1.setDMG(3);
        goblin1.setHitChance(0.85);

        Goblin goblin2 = new Goblin();
        goblin2.setName("Toji Fushiguro");
        goblin2.setHP(12);
        goblin2.setDMG(2);
        goblin2.setHitChance(0.75);

        fight(goblin1, goblin2);
    }
}

Duel.main(null);
Satoru Gojo attacks Toji Fushiguro!
Satoru Gojo hits!
Toji Fushiguro takes 3 damage
Toji Fushiguro HP: 9

Toji Fushiguro attacks Satoru Gojo!
Toji Fushiguro hits!
Satoru Gojo takes 2 damage
Satoru Gojo HP: 8

Satoru Gojo attacks Toji Fushiguro!
Satoru Gojo hits!
Toji Fushiguro takes 3 damage
Toji Fushiguro HP: 6

Toji Fushiguro attacks Satoru Gojo!
Toji Fushiguro hits!
Satoru Gojo takes 2 damage
Satoru Gojo HP: 6

Satoru Gojo attacks Toji Fushiguro!
Satoru Gojo hits!
Toji Fushiguro takes 3 damage
Toji Fushiguro HP: 3

Toji Fushiguro attacks Satoru Gojo!
Toji Fushiguro misses...
Satoru Gojo HP: 6

Satoru Gojo attacks Toji Fushiguro!
Satoru Gojo hits!
Toji Fushiguro takes 3 damage
Toji Fushiguro HP: 0

Toji Fushiguro attacks Satoru Gojo!
Toji Fushiguro hits!
Satoru Gojo takes 2 damage
Satoru Gojo HP: 4

Toji Fushiguro has perished