0

I'm working on a practice program based on a tabletop game and I ran into a snag where my code is not dividing the value correctly, or really at all.

public void damageCalculation(int successfulWounds, Unit a, Unit b) {
    int damageDealt = successfulWounds * a.getDamageDealt();

    b.woundsTaken = b.woundsTaken + damageDealt;

    killModels(b.woundsTaken, b);
    System.out.printf("After kill units: %s\n", b.unitSize);
    System.out.printf("Does the unit have lingering wounds: %s\n", b.woundsTaken);
}

private void killModels(int bDamageTaken, Unit b) {
    //For every bit of damage where damage is equal to the defender's wound stat, kill a model
    int killed = (bDamageTaken / b.wounds);

    b.unitSize = b.unitSize - killed;
    b.woundsTaken = bDamageTaken % b.wounds;

    System.out.printf("Killed %s models\n", killed);
}

so the killed variable is supposed to have the amount of damage taken divided by the wounds statistic of an enum class object. The result that I get would make sense if the b.wounds characteristic is 1 but if it is any other number, it returns bDamageTaken / 1 essentially.

What am I missing/have I not considered?

Dan
  • 153
  • 1
  • 1
  • 8
  • I checked the above-linked answer and it was not really helpful. I'm not looking for taking the value of killed and subtracting it from the number of individual guys in the unit. I need whole numbers. I think that I didn't properly explain how the damage is supposed to work, my bad. Let me explain, when a unit takes a hit, for each hit, the unit takes damage equal to the attack characteristic of the attacking unit. That value is the total wounds of damage being applied to the unit. The total wounds of the unit is equal to the wounds characteristic multiplied by the units. – Dan Feb 02 '18 at 17:52
  • Essentially, the wounds are the hp for the individual model in the unit. So if the unit's wounds characteristic is 2, it takes 2 damage in order to remove a model from the unit. – Dan Feb 02 '18 at 17:56

0 Answers0