Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package wumpus.logic;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.List;
- import org.json.simple.JSONArray;
- import org.json.simple.JSONObject;
- import org.json.simple.parser.JSONParser;
- import org.json.simple.parser.ParseException;
- public class Dungeon {
- private static List<List<Tile>> dungeon;
- private static long size;
- public static List<List<Tile>> getDungeon() {
- return dungeon;
- }
- public static void setDungeon(List<List<Tile>> dungeon) {
- Dungeon.dungeon = dungeon;
- }
- public static long getSize() {
- return size;
- }
- public static void setSize(long size) {
- Dungeon.size = size;
- }
- public Dungeon() {
- }
- public Dungeon(String mapName) throws ParseException {
- JSONParser jsonParser = new JSONParser();
- List<Tile> rows = new ArrayList<>();
- long rowNumber = 0;
- long colNumber = 0;
- try {
- Object object = jsonParser.parse(
- new FileReader("C:\\Users\\James\\eclipse-workspace\\wumpus\\src\\main\\resources\\" + mapName));
- JSONObject jsonObject = (JSONObject) object;
- Dungeon.size = (long) jsonObject.get("size");
- JSONArray array = (JSONArray) jsonObject.get("dungeon");
- for (Object object2 : array) {
- if (rowNumber == size) {
- rows.add(new Tile(rowNumber, colNumber, (long) object2));
- dungeon.add(rows);
- rows.clear();
- rowNumber = 0;
- colNumber = 0;
- }
- rows.add(new Tile(rowNumber, colNumber, (long) object2));
- rowNumber += 1;
- colNumber += 1;
- }
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public void drawDungeon() {
- for (List<Tile> list : dungeon) {
- for (Tile tile : list) {
- System.out.println(tile.getValue() + " ");
- }
- System.out.println("");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement