package org.academiadecodigo.bootcamp.sniperelite.gameobject.barrel;

import org.academiadecodigo.bootcamp.sniperelite.Destroyable;
import org.academiadecodigo.bootcamp.sniperelite.gameobject.GameObject;

/**
 * MIT License
 * (c) 2017 Ricardo Constantino
 */

public class Barrel extends GameObject implements Destroyable {
    private int maxDamage;
    private boolean destroyed;
    private BarrelType type;

    public Barrel(BarrelType type) {
        this.type = type;
        this.maxDamage = type.getMaxDamage();
        this.destroyed = false;
    }

    @Override
    public boolean isDestroyed() {
        return this.destroyed;
    }

    @Override
    public void hit(int damage) {
        this.maxDamage = damage < this.maxDamage ? this.maxDamage - damage : 0;

        if (this.maxDamage == 0) {
            this.destroyed = true;
        }
    }

    @Override
    public String getMessage() {
        return "I'm a little " + type.toString() + " barrel, short and stout. Boom boom boom, boom boom boom.";
    }
}
