public class Animation extends Action{
    private int repeatCount;

    /**
     * Constructs an Action object with specified characteristics.
     * In the base program, this is not called directly.
     * Instead, the encapsulated 'create' method are used to create specific kinds.
     *
     * @param entity       The entity enacting the action.
     * @param repeatCount  The number of animation repeats. A zero indicates indefinite repeats.
     */
    public Animation(Entity entity, int repeatCount) {
        super(entity);
        this.repeatCount = repeatCount;
    }

    public int getRepeatCount() {
        return repeatCount;
    }

    public void setRepeatCount(int repeatCount) {
        this.repeatCount = repeatCount;
    }

    @Override
    public void execute(EventScheduler scheduler) {
        if (getEntity() instanceof animatable) {
            animatable aim = (animatable) getEntity();
            aim.updateImage();

            if (repeatCount != 1) {
                scheduler.scheduleEvent(getEntity(), new Animation(this.getEntity(), Math.max(this.repeatCount - 1, 0)), aim.getAnimationPeriod());
            }
        }
    }
}
