Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- /**
- * A class to handle all living, breathing creatures
- */
- public class Entity {
- private String name;
- private int HP;
- private int MaxHP; //Sets itself to whatever HP is on creation
- private int STR;
- private int hunger; //Current hunger, starts at 100
- private double mood; //Current mood value
- private double moodMult; //Increase or decreases depending on external factors, used to determine mood
- private boolean isAlive;
- private ArrayList<Item> contains = new ArrayList<>(); //Inventory
- /**
- * Constructor for Entity
- *
- * @param name The String name of this Entity
- * @param HP This Entity' initial HP, set to MaxHP as well
- * @param STR The Entity's physical strength
- */
- public Entity(String name, int HP, int STR) {
- this.name = name;
- this.HP = HP;
- this.MaxHP = HP;
- this.STR = STR;
- this.hunger = 100;
- this.mood = 100;
- this.isAlive = true;
- }
- /**
- * Returns the contents of an Entity's inventory
- */
- public void inventory() {
- System.out.println("The " + name + " contains: ");
- if (contains.size() > 0) { //If there's at least one Item in the inventory
- for (int i = 0; i < contains.size(); ) { //Then print all the items
- System.out.println(contains.get(i));
- i++;
- }
- } else {
- System.out.println("Nothing"); //If there's no items in the inventory say "nothing"
- }
- }
- /**
- * Places an Item into the Entity's inventory
- *
- * @param that What Item is being added to the inventory
- */
- public void ItemGet(Item that) {
- if (isAlive != false) {
- System.out.println(name + " has picked up " + that);
- contains.add(that);
- } else {
- System.out.println(name + " cannot pickup the " + that + " because " + name + " is dead.");
- }
- }
- /**
- * Removes an Item into the Entity's inventory
- *
- * @param that What Item is being removed from the inventory
- */
- public void ItemDrop(Item that) {
- if (isAlive != false) {
- System.out.println(name + " has dropped " + that);
- contains.remove(that);
- } else {
- System.out.println(name + " cannot drop the " + that + " because " + name + " is dead.");
- }
- }
- /**
- * Represents a passage of time, instructs Entity to update hunger, mood, etc.
- */
- public void update() {
- if (this.isAlive != false) //While this Entity is alive
- {
- this.hunger -= 5;
- this.mood -= moodMult;
- System.out.println("Hunger: " + hunger + " Mood: " + mood);
- hunger();
- mood();
- } else {
- System.out.println(name + " is dead.");
- }
- }
- /**
- * Handles the hunger of Entity, updates String to represent the Entity's hunger
- * turns "isAlive" to false if hunger drops to zero or below
- */
- private void hunger() {
- if (this.hunger >= 90) {
- System.out.println(name + " isn't hungry");
- moodMult = 0.5;
- } else if (this.hunger <= 85 && this.hunger >= 60) {
- moodMult = 0.5;
- System.out.println(name + " is getting fairly hungry");
- } else if (this.hunger < 60 && this.hunger >= 40) {
- moodMult = 1.0;
- System.out.println(name + " is very hungry");
- } else if (this.hunger < 40 && this.hunger >= 20) {
- System.out.println(name + " is extremely hungry");
- moodMult = 5.0;
- } else if (this.hunger <= 0) {
- this.isAlive = false;
- System.out.println(name + " has died of starvation.");
- } else {
- moodMult = 10.0;
- System.out.println(name + " is starving!");
- }
- }
- /**
- * Handles the mood of an Entity
- */
- private void mood() {
- if (this.mood >= 90) {
- System.out.println(name + " is very happy");
- } else if (this.mood <= 89 && this.mood >= 60) {
- System.out.println(name + " is happy");
- } else if (this.mood < 60 && this.mood >= 40) {
- System.out.println(name + " is feeling a little uncomfortable");
- } else if (this.mood < 40 && this.mood >= 20) {
- System.out.println(name + " is feeling sad");
- } else if (this.mood <= 0) {
- this.isAlive = false;
- System.out.println(name + " is devoid of happiness.");
- } else {
- System.out.println(name + " is incredibly depressed!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement