PickableObject.java 995 B

1234567891011121314151617181920212223242526272829303132333435
  1. package eu.oschl.textadventure.objects;
  2. import java.util.Optional;
  3. /**
  4. * Represents an object in the game that can be picked up by the player.
  5. * This class serves as a base for all pickable objects, providing common properties and methods.
  6. *
  7. * @author Ondřej Schlaichert
  8. */
  9. public abstract class PickableObject extends GameObject {
  10. private final String iconImagePath;
  11. public PickableObject(String name, String description, String iconImagePath) {
  12. super(name, description);
  13. this.iconImagePath = iconImagePath;
  14. }
  15. public PickableObject(String name, String description) {
  16. super(name, description);
  17. this.iconImagePath = null;
  18. }
  19. public Optional<String> getIconImagePath() {
  20. return Optional.ofNullable(iconImagePath);
  21. }
  22. /**
  23. * Picks up the object and adds it to the player's inventory.
  24. * @return true if the object was successfully picked up, false otherwise
  25. */
  26. public abstract boolean pickUp();
  27. }