From 157ceabc59f7473671646ce2d213005746065c68 Mon Sep 17 00:00:00 2001 From: David Hermann Date: Wed, 18 Jan 2023 19:32:30 +0100 Subject: [PATCH] Edited TravelEngine, added getLocationList and locationExist method --- .../org/bitbiome/classes/TravelEngine.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/bitbiome/classes/TravelEngine.java b/src/main/java/org/bitbiome/classes/TravelEngine.java index ec21dde..26a84a1 100644 --- a/src/main/java/org/bitbiome/classes/TravelEngine.java +++ b/src/main/java/org/bitbiome/classes/TravelEngine.java @@ -2,13 +2,19 @@ package org.bitbiome.classes; import org.bitbiome.entities.Location; import org.bitbiome.entities.Player; +import org.json.JSONArray; + +import java.util.ArrayList; public class TravelEngine { - private Location location; + private JSONArray locations; + JsonParser jp; private Player player; public TravelEngine(Player player) { + jp = new JsonParser(); + locations = jp.getJSONObject("../gameconfig.json").getJSONArray("locations"); this.player = player; } @@ -20,4 +26,17 @@ public class TravelEngine { return player; } + public JSONArray getLocationList() { + return locations; + } + + public boolean locationExists(String name) { + boolean found = false; + for (int i = 0; i < locations.length(); i++) + if (locations.getJSONObject(i).getString("name").equals(name)) { + found = true; + } + return found; + } + }