Commit b602b364 authored by unknown's avatar unknown
Browse files

add map.json handler in map.java

parent 5f43d399
......@@ -194,7 +194,7 @@ public class EndpointMethod {
return resultJson.toString();
}
public String move(String token, int x, int y) {
public static String move(String token, int x, int y) {
JSONObject resultJson = new JSONObject();
JSONParser parser = new JSONParser();
try {
......
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Fauzan Hilmi
*/
public class Map {
public static String name;
public static long width;
public static long height;
public static String matrix[][];
public static void load() {
JSONParser parser = new JSONParser();
try {
String basePath = new File("").getAbsolutePath();
Object obj = parser.parse(new FileReader(basePath + "//map.json"));
if(obj!=null) {
JSONObject map = (JSONObject) obj;
name = (String) map.get("name");
width = (long) map.get("width");
height = (long) map.get("height");
matrix = new String[(int)height][(int)width];
JSONArray mapRow = (JSONArray) map.get("map");
for(int i=0; i<height; i++) {
JSONArray mapCol = (JSONArray) mapRow.get(i);
for(int j=0; j<width; j++) {
matrix[i][j] = (String) mapCol.get(j);
}
}
/*for(int i=0; i<height; i++) {
for(int j=0; j<width; j++) {
matrix[i][j] = mapMatrix.
}
}*/
}
} catch (IOException ex) {
Logger.getLogger(Map.class.getName()).log(Level.SEVERE, null, ex);
} catch (ParseException ex) {
Logger.getLogger(Map.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static void main(String argv[]) {
Map.load();
System.out.println(Map.name);
System.out.println(Map.height);
System.out.println(Map.width);
for(int i=0; i<Map.height; i++) {
for(int j=0; j<Map.width; j++) {
System.out.print(Map.matrix[i][j]+" ");
}
System.out.println("");
}
}
}
......@@ -19,6 +19,5 @@ class TCPServer {
public static void main(String argv[]) throws Exception {
ConnectionHandler CH = new ConnectionHandler();
CH.start();
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment