package org.academiadecodigo.bootcamp11.sniperelite;

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

public abstract class Enemy extends GameObject {
     private int health;
     private boolean dead;
     private String status;
     private ObjectType type;

     public Enemy(ObjectType type) {
         this.dead = false;
         this.health = 100;
         this.type = type;
         changeStatus("<< spawned " + this + " >>");
     }

     public boolean isDead() {
         return this.dead;
     }

     public static boolean isEnemy(GameObject object) {
         return (object instanceof Enemy);
     }

     public ObjectType getType() {
         return this.type;
     }

     public void takeDamage(int damage) {
         this.health -= damage;
         changeStatus("-- " + this + " took " + damage + " damage --");
         if (health <= 0) {
             this.dead = true;
             changeStatus("-- " + this + " died --");
         }
     }

     public void changeStatus(String message) {
         this.status = message;
     }

     public abstract boolean hit(int damage);

     @Override
     public String getMessage() {
         if (this.status == null) {
             this.status = "-- " + this + " is still alive with " + this.health + "HP --";
         }
         String current = this.status;
         this.status = null;
         return current;
     }

    @Override
    public String toString() {
        return this.type.toString();
    }
}
