Commit f21b714f authored by Akhmad Fakhoni Listiyan Dede's avatar Akhmad Fakhoni Listiyan Dede
Browse files

Message sampai field ok

parent c8f2daca
......@@ -82,7 +82,7 @@ public class Database {
// addItemToInventory("553b64d23c892b2d5b772c74", 4);
// addItemToInventory("553b64d23c892b2d5b772c74", 4);
System.out.println(saveOfferToTradeBox("553b64d23c892b2d5b772c74", 4, 3, 5, 1));
System.out.println(saveOfferToTradeBox("553b64d23c892b2d5b772c74", 2, 2, 4, 3));
}
......
......@@ -105,21 +105,58 @@ public class Message {
try
{
jsonObj = new JSONObject(jsonString);
if(jsonObj.getString("method").equals("login"))
{
String username = jsonObj.getString("username");
String password = jsonObj.getString("password");
response = login(username,password);
}
else if(jsonObj.getString("method").equals("signup"))
{
String username = jsonObj.getString("username");
String password = jsonObj.getString("password");
response = signup(username, password);
}
else if(jsonObj.getString("method").equals("serverStatus"))
{
response = serverStatus(jsonString);
switch (jsonObj.getString("method")) {
case "login":
{
String username = jsonObj.getString("username");
String password = jsonObj.getString("password");
response = login(username,password);
break;
}
case "signup":
{
String username = jsonObj.getString("username");
String password = jsonObj.getString("password");
response = signup(username, password);
break;
}
case "inventory":
{
String token = jsonObj.getString("token");
response = getInventory(token);
break;
}
case "mixitem":
{
String token = jsonObj.getString("token");
int item1 = jsonObj.getInt("item1");
int item2 = jsonObj.getInt("item2");
response = mixItem(token, item1, item2);
break;
}
case "map":
{
String token = jsonObj.getString("token");
response = getMap(token);
break;
}
case "move":
{
String token = jsonObj.getString("token");
int xGoal = jsonObj.getInt("x");
int yGoal = jsonObj.getInt("y");
response = move(token, xGoal, yGoal);
break;
}
case "field":
{
String token = jsonObj.getString("token");
response = pickField(token);
break;
}
case "serverStatus":
response = serverStatus(jsonString);
break;
}
if(log)
System.out.println(jsonObj);
......@@ -396,10 +433,11 @@ public class Message {
//If(token OK)
JSONObject jsonObj = new JSONObject();
String [][] map = Store.getMap();
jsonObj.put("status", "ok");
jsonObj.put("name", "Bandar Behari"); /* Ini name darimana? */
jsonObj.put("width", 4);
jsonObj.put("height", 4);
jsonObj.put("name", "Go Go Go"); /* Ini name darimana? */
jsonObj.put("width", map.length);
jsonObj.put("height", map[0].length);
response = jsonObj.toString();
} catch (JSONException ex) {
response = error();
......@@ -444,18 +482,16 @@ public class Message {
JSONObject jsonPosition = Database.getCurrentPosition(token);
int x = 0;
int y = 0;
try {
x = jsonPosition.getInt("x");
y = jsonPosition.getInt("y");
} catch (JSONException ex) {
Logger.getLogger(Message.class.getName()).log(Level.SEVERE, null, ex);
}
String [][] map = Store.getMap();
int item = Store.getItemIndex(x, y);
int item;
String response;
try {
x = jsonPosition.getInt("x");
y = jsonPosition.getInt("y");
item = Store.getItemIndex(x, y);
if(Database.addItemToInventory(token, item))
{
jsonObj.put("status", "ok");
......
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