Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sample.edu.missouriwestern.cpozo.monsters;
- public abstract class Entity implements Comparable<Entity> {
- String symbol = "â‡ï¸";// https://emojipedia.org sparkle
- static private int nextID = 10001;
- double strength = 0.0; // 1. is normal human strength
- double aggressiveness = 0.0; //1.0 is human in combat situation. Must not be > 1.0
- protected String attackMessage = "attacks generically";
- protected String passiveMessage = "stares into space";
- //individual characteristics
- private int id;
- private double health;
- private double stamina = 0.0;
- public Entity() {
- id = nextID;
- nextID++;
- }
- public int getId(){
- return id;
- }
- public void setHealth(double health) {
- this.health = health;
- if (health > 1.0)
- this.health = 1.0;
- if (health < 0.)
- this.health = 0;
- }
- public void setStamina(double stamina) {
- this.stamina = (stamina > 0.10) ? stamina : 0.10;
- }
- public String getSymbol(){
- return symbol;
- }
- public double getHealth() {
- return health;
- }
- public void subtractHealth(double delta) {
- double delta2 = Math.abs(delta); //prevents adding negative health;
- health -= delta2;
- }
- public void subtractStamina(double delta) {
- double delta2 = Math.abs(delta);
- stamina = (stamina - delta2 > 0.10) ? (stamina - delta) : 0.10;
- }
- public String getAttackMessage() {
- return attackMessage;
- }
- public String getPassiveMessage() {
- return passiveMessage;
- }
- public double getAggressiveness() {
- return aggressiveness;
- }
- public double getStamina() {
- return stamina;
- }
- private int round(double x) {
- return (int) Math.round(x * 100);
- }
- public String toString() {
- return String.format("%8s %s %6d (%3d%%/%3d/%3d)", symbol, getName(), id,
- round(getHealth()), round(stamina), round(aggressiveness));
- }
- public boolean isDead() {
- return health <= 0.0;
- }
- public double getStrength() {
- return strength;
- }
- public String getName() {
- String fullName = String.format("%s", getClass());
- int lastPeriod = fullName.lastIndexOf(".");
- String shortName = fullName.substring(lastPeriod + 1);
- return shortName;
- }
- //equals and hasCode were generated automatically, using only the id field.
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof Entity)) return false;
- Entity that = (Entity) o;
- return id == that.id;
- }
- @Override
- public int hashCode() {
- return id;
- }
- public int compareTo(Entity other) {
- return this.id - other.id;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement