BookLogic.java
package io.github.some_example_name;
/**
* <code>BookLogic</code> contains core logic for Book interaction.
* <p>
* Made for unit testing.
*/
public class BookLogic {
private boolean searched = false;
private boolean showQuiz = false;
private float messageTimer = 0f;
private final float messageDuration;
/**
* Constructs BookLogic with a given message duration.
*
* @param messageDuration how long the quiz message should be active
*/
public BookLogic(float messageDuration) {
this.messageDuration = messageDuration;
}
/**
* Marks the book as searched and triggers quiz.
*/
public void search() {
if (!searched) {
searched = true;
showQuiz = true;
messageTimer = 0f;
}
}
/**
* Updates internal timers.
*
* @param delta time elapsed since last frame
*/
public void update(float delta) {
if (showQuiz) {
messageTimer += delta;
if (messageTimer >= messageDuration) {
showQuiz = false;
}
}
}
public boolean isSearched() {
return searched;
}
public boolean shouldShowQuiz() {
return showQuiz;
}
}