Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. package wumpus.logic;
  2.  
  3. import java.io.FileNotFoundException;
  4. import java.io.FileReader;
  5. import java.io.IOException;
  6. import java.util.ArrayList;
  7. import java.util.List;
  8.  
  9. import org.json.simple.JSONArray;
  10. import org.json.simple.JSONObject;
  11. import org.json.simple.parser.JSONParser;
  12. import org.json.simple.parser.ParseException;
  13.  
  14. public class Dungeon {
  15. private static List<List<Tile>> dungeon;
  16. private static long size;
  17.  
  18. public static List<List<Tile>> getDungeon() {
  19. return dungeon;
  20. }
  21.  
  22. public static void setDungeon(List<List<Tile>> dungeon) {
  23. Dungeon.dungeon = dungeon;
  24. }
  25.  
  26. public static long getSize() {
  27. return size;
  28. }
  29.  
  30. public static void setSize(long size) {
  31. Dungeon.size = size;
  32. }
  33.  
  34. public Dungeon() {
  35.  
  36. }
  37.  
  38. public Dungeon(String mapName) throws ParseException {
  39. JSONParser jsonParser = new JSONParser();
  40. List<Tile> rows = new ArrayList<>();
  41. long rowNumber = 0;
  42. long colNumber = 0;
  43. try {
  44. Object object = jsonParser.parse(
  45. new FileReader("C:\\Users\\James\\eclipse-workspace\\wumpus\\src\\main\\resources\\" + mapName));
  46. JSONObject jsonObject = (JSONObject) object;
  47. Dungeon.size = (long) jsonObject.get("size");
  48. JSONArray array = (JSONArray) jsonObject.get("dungeon");
  49. for (Object object2 : array) {
  50. if (rowNumber == size) {
  51. rows.add(new Tile(rowNumber, colNumber, (long) object2));
  52. dungeon.add(rows);
  53. rows.clear();
  54. rowNumber = 0;
  55. colNumber = 0;
  56. }
  57. rows.add(new Tile(rowNumber, colNumber, (long) object2));
  58. rowNumber += 1;
  59. colNumber += 1;
  60. }
  61. } catch (FileNotFoundException e) {
  62. e.printStackTrace();
  63. } catch (IOException e) {
  64. e.printStackTrace();
  65. }
  66. }
  67.  
  68. public void drawDungeon() {
  69. for (List<Tile> list : dungeon) {
  70. for (Tile tile : list) {
  71. System.out.println(tile.getValue() + " ");
  72. }
  73. System.out.println("");
  74. }
  75. }
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement