90 lines
1.9 KiB
Java
90 lines
1.9 KiB
Java
package letzplay.core;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class GameEngine implements Trigger {
|
|
private LevelSystem lvlSys;
|
|
private List<Quest> quests;
|
|
private List<String> state;
|
|
|
|
|
|
private GameEngine() {
|
|
lvlSys = LevelSystem.getInstance();
|
|
quests = new ArrayList<>();
|
|
state = new ArrayList<>();
|
|
}
|
|
|
|
public static GameEngine getInstance() {
|
|
return new GameEngine();
|
|
}
|
|
|
|
public void initQuests(List<Quest> qs) {
|
|
this.quests = qs;
|
|
}
|
|
|
|
private void finishQuest(Quest q) {
|
|
if (q.progression().done == q.progression().of && !q.finished()) {
|
|
q.setFinished();
|
|
lvlSys.addExperience(q.getGainExp());
|
|
}
|
|
}
|
|
|
|
public List<Quest> availableQuests() {
|
|
List<Quest> result = new ArrayList<>();
|
|
for (Quest q : quests
|
|
) {
|
|
if (q.getMinLvl() <= lvlSys.currentLvl() && !q.finished()) {
|
|
result.add(q);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public List<Quest> doneQuests() {
|
|
List<Quest> result = new ArrayList<>();
|
|
for (Quest q : quests
|
|
) {
|
|
if (q.finished()) {
|
|
result.add(q);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public int currentLvl() {
|
|
return lvlSys.currentLvl();
|
|
}
|
|
|
|
public float currentExp() {
|
|
return lvlSys.currentExperience();
|
|
}
|
|
|
|
|
|
public void update() {
|
|
for (Quest q : quests
|
|
) {
|
|
if (q.getMinLvl() <= lvlSys.currentLvl()) {
|
|
finishQuest(q);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return lvlSys.toString() + "\n " + quests.toString();
|
|
}
|
|
|
|
@Override
|
|
public void trigger(String msg) {
|
|
state.add(msg);
|
|
for (Quest q : quests) {
|
|
q.trigger(msg);
|
|
}
|
|
}
|
|
|
|
public List<String> getState() {
|
|
return state;
|
|
}
|
|
}
|