Commit da414405 authored by Susanti Gojali's avatar Susanti Gojali
Browse files

field player added

parent 58490f01
......@@ -444,6 +444,9 @@
<Properties>
<Property name="text" type="java.lang.String" value="Field"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="fieldButtonActionPerformed"/>
</Events>
</Component>
<Container class="javax.swing.JPanel" name="playerPanel">
<Properties>
......
......@@ -345,6 +345,11 @@ public class MainPage extends javax.swing.JFrame {
});
fieldButton.setText("Field");
fieldButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
fieldButtonActionPerformed(evt);
}
});
playerPanel.setAutoscrolls(true);
playerPanel.setPreferredSize(new java.awt.Dimension(584, 10));
......@@ -990,10 +995,11 @@ public class MainPage extends javax.swing.JFrame {
if(response.get("status").equals("ok")) {
showMessage("Register success");
}else{
}else if(response.get("status").equals("fail")) {
showMessage(response.getString("description"));
}else{
showMessage(response.getString("status"));
}
} catch (Exception ex) {
showMessage("Server does not respond. Please try again later..");
System.out.println("Register Exception");
......@@ -1005,9 +1011,8 @@ public class MainPage extends javax.swing.JFrame {
String username =usernameLoginTextField.getText();
String password =passwordLoginField.getText();
JSONObject response;
try {
response = client.login(username, password);
JSONObject response = client.login(username, password);
if(response.getString("status").equals("ok")) {
client.token = response.getString("token");
......@@ -1041,8 +1046,10 @@ public class MainPage extends javax.swing.JFrame {
CardLayout cl = (CardLayout) MainPanel.getLayout();
cl.show(MainPanel, "MapCard");
} else {
} else if(response.getString("status").equals("fail")){
showMessage(response.getString("description"));
} else {
showMessage(response.getString("status "));
}
} catch (Exception ex) {
showMessage("Server does not respond. Please try again later..");
......@@ -1064,9 +1071,9 @@ public class MainPage extends javax.swing.JFrame {
try{
int xInt=Integer.parseInt(positionX);
int yInt=Integer.parseInt(positionY);
JSONObject response;
try {
response = client.move(xInt, yInt);
JSONObject response = client.move(xInt, yInt);
if(response.getString("status").equals("ok")) {
Long timeLong=response.getLong("time");
......@@ -1101,6 +1108,30 @@ public class MainPage extends javax.swing.JFrame {
}
}//GEN-LAST:event_moveButtonActionPerformed
private void fieldButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fieldButtonActionPerformed
if(time.after(currentTime)) { //player is moving
showMessage("You are still moving..");
} else{
try {
JSONObject response = client.field();
if(response.getString("status").equals("ok")){
showMessage("You got item "+response.getInt("item")+"!");
}else if(response.getString("status").equals("fail")){
showMessage(response.getString("description"));
}else{
showMessage(response.getString("status"));
}
} catch (Exception ex) {
showMessage("Server does not respond. Please try again later..");
System.out.println("Field Exception");
Logger.getLogger(MainPage.class.getName()).log(Level.SEVERE, null, ex);
}
}
}//GEN-LAST:event_fieldButtonActionPerformed
//Generate Map
private void generateMap() {
JSONObject response;
......
......@@ -322,7 +322,7 @@ public class TCPClient {
return responseJSON;
}
public JSONObject field(String token) throws Exception
public JSONObject field() throws Exception
{
System.out.println("Field");
String toSend = fieldJSON(token).toString();
......@@ -485,7 +485,7 @@ public class TCPClient {
response = client.map();
System.out.println(response.toString());
response = client.field(client.token);
response = client.field();
System.out.println(response.toString());
response = client.offer(client.token, 0, 1, 7, 3);
......
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