Commit 761076f6 authored by Rafi Ramadhan's avatar Rafi Ramadhan
Browse files

update field

parent c19d82de
......@@ -260,18 +260,34 @@ public class MethodHandler {
return JSONValue.toJSONString(response);
}
public boolean isMoving(String username) throws SQLException {
DBHandler db = new DBHandler();
boolean walking = false;
Long arrival = db.getTime(username);
if(System.currentTimeMillis() < arrival) {
walking = true;
}
System.out.println(walking);
return walking;
}
public String Move(String input) throws ParseException, SQLException {
JSONParse parse = new JSONParse();
Map response = new LinkedHashMap();
DBHandler db = new DBHandler();
Long time = System.currentTimeMillis()+10000;
Long time = System.currentTimeMillis()+30000;
String token = parse.parseJSON(input, "token");
String username = session.get(searchToken(token)).getUsername();
Long x = parse.parseIntJSON(input, "x");
Long y = parse.parseIntJSON(input, "y");
System.out.println(width); System.out.println(height);
if(x<width && y<height) {
if(x<width && y<height && !isMoving(username)) {
System.out.println(session.get(0).getToken());
int index = searchToken(token);
db.setPosX(session.get(index).getUsername(), x);
db.setPosY(session.get(index).getUsername(), y);
......@@ -291,6 +307,7 @@ public class MethodHandler {
JSONParse parse = new JSONParse();
DBHandler db = new DBHandler();
Map response = new LinkedHashMap();
int item = -999;
String token = parse.parseJSON(input, "token");
String username = session.get(searchToken(token)).getUsername();
......@@ -299,9 +316,15 @@ public class MethodHandler {
String s = field_map.getJSONArray(y).getString(x);
System.out.println(s);
int item = db.pickItem(s);
response = parse.fieldJSON(token, item, true);
if (!s.equals("") && !isMoving(username)) {
item = db.pickItem(s);
response = parse.fieldJSON(token, item, true);
db.addInventory(username, item);
field_map.getJSONArray(y).put(x, "");
}
else {
response = parse.fieldJSON(token, item, false);
}
System.out.println(JSONValue.toJSONString(response));
return JSONValue.toJSONString(response);
}
......
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