Commit 41362572 authored by Khoirunnisa Afifah's avatar Khoirunnisa Afifah
Browse files

Merge branch 'master' of...

Merge branch 'master' of http://gitlab.informatika.org/sinambelajunita/IF3230-Tugas-Besar-Sister-2015
parents e4841265 88bd7cc4
# APPLICATION NAME
By:
By: JARD TEAM
# HOW TO USE THE APPLICATION
1. Run the server
2. Run the client
Login/Sign Up:
- Enter the server ip address on IP Address text field
- Enter the server port on Port text field
- Enter your username on the username text field
- Enter your password on the password text field
- Press login/sign up
Move:
- Click somewhere on the map's cell
- Wait for the current time is equal to time
Get Item:
- Press Get item from your current position
Inventory:
- Press Inventory button
Mix Item:
- To mix item, you have to have minimal 3 item on each item
- Click any item you have for the first item
- Click any item you have for the second item
- Click reset to reset the mixture pre-process
Tradebox:
- Click on Tradebox button
Offer:
- Click any item you have for the first item
- Click any item you have for the second item
- Click reset to reset the mixture pre-process
- Click Offer
Find Item:
- Click any item you have for the first item
- Click find
- Click buy if you agree with the offer
Logout:
- Click Logout when you are finish
\ No newline at end of file
......@@ -38,6 +38,7 @@ public class ServerHandler{
request = new String(byt);
if(response != null) {
// request = request.substring(0,count);
ServerLogger.log("SERVER_THREAD", "Response : " + response);
synchronized(this){
addResponse(response);
}
......
......@@ -28,6 +28,7 @@ public class Map {
public Map(String token){
this.token = token;
map = new String[5][5];
}
public String[][] getMap(){
return map;
......@@ -74,29 +75,32 @@ public class Map {
int LIFEELIXIR = 7;
int MANACRYSTAL = 8;
int PHILSTONE = 9;
int result;
if (map[xPos][yPos].equals(Honey)) {
return HONEY;
result = HONEY;
} else if (map[xPos][yPos].equals(Herbs)) {
return HERBS;
result = HERBS;
} else if (map[xPos][yPos].equals(Clay)) {
return CLAY;
result = CLAY;
} else if (map[xPos][yPos].equals(Mineral)) {
return MINERAL;
result = MINERAL;
} else if (map[xPos][yPos].equals(Potion)) {
return POTION;
result = POTION;
} else if (map[xPos][yPos].equals(Incense)) {
return INCENSE;
result = INCENSE;
} else if (map[xPos][yPos].equals(Gems)) {
return GEMS;
result = GEMS;
} else if (map[xPos][yPos].equals(LifeElix)) {
return LIFEELIXIR;
result = LIFEELIXIR;
} else if (map[xPos][yPos].equals(Mana)) {
return MANACRYSTAL;
result = MANACRYSTAL;
} else if (map[xPos][yPos].equals(Stone)) {
return PHILSTONE;
result = PHILSTONE;
} else {
return -1;
result = -1;
}
setEmpty(xPos,yPos);
return result;
}
public void setEmpty(int x, int y)
{
......
......@@ -81,7 +81,8 @@ public class Message {
// System.out.println(receive("{\"method\":\"inventory\",\"token\":\"553cd35d3c892b2c6768f77d\"}"));
// System.out.println(login("ja","j"));
// System.out.println(receive("{\"method\": \"canceloffer\",\"token\": \"553cf0913c892b417db5bd82\",\"offer_token\": \"553cf11f3c892b417db5bd83\"}"));
System.out.println("cancel: " + cancelOffer("553cd35d3c892b2c6768f77d", "553cdce03c892b37e1ce2493"));
// System.out.println("cancel: " + cancelOffer("553cd35d3c892b2c6768f77d", "553cdce03c892b37e1ce2493"));
}
public static String callURL(String myURL) {
......@@ -203,14 +204,14 @@ public class Message {
{
String token = jsonObj.getString("token");
String offer_token = jsonObj.getString("offer_token");
sendAccept(token, offer_token);
response = sendAccept(token, offer_token);
break;
}
case "canceloffer":
{
String token = jsonObj.getString("token");
String offer_token = jsonObj.getString("offer_token");
cancelOffer(token, offer_token);
response = cancelOffer(token, offer_token);
break;
}
case "serverStatus":
......@@ -399,8 +400,6 @@ public class Message {
{
String response;
int honey = 0, herbs = 0, clay = 0, mineral = 0, potion = 0, incense = 0, gems = 0, elixir = 0, crystal = 0, stone = 0;
/* Get masing masing item dari database */
ArrayList<Integer> inv = Database.getInventory(token);
......@@ -564,15 +563,20 @@ public class Message {
y = jsonPosition.getInt("y");
item = Store.getMap(token).getItemIndex(x, y);
if(Database.addItemToInventory(token, item))
{
jsonObj.put("status", "ok");
jsonObj.put("item", item);
response = jsonObj.toString();
if(item != -1) {
if(Database.addItemToInventory(token, item))
{
jsonObj.put("status", "ok");
jsonObj.put("item", item);
response = jsonObj.toString();
}
else
{
response = fail("Pick Fail");
}
}
else
{
response = fail("Pick Fail");
else {
response = fail("Item has been taken");
}
} catch (JSONException ex) {
response = error();
......@@ -815,21 +819,24 @@ public class Message {
public static String cancelOffer(String token, String offer_token)
{
String response = null;
int result = Database.cancelOffer(token, offer_token);
if(result == 1)
{
return statusOKOnly();
response = statusOKOnly();
}
else if(result == 0)
{
return fail("Alrady Finished");
response = fail("Alrady Finished");
}
else if(result == -1)
{
return fail("Offer token not exist");
response = fail("Offer token not exist");
}
else
return error();
response = error();
ServerLogger.log("CLIENT_THREAD","Response canceloffer : " + response);
return response;
}
/**
* Fungsi yang mengembalikan status OK tanpa tambahan status lainnya
......
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