diff --git a/src/com/annimon/turrets/NetworkListener.java b/src/com/annimon/turrets/NetworkListener.java index a460b35..32ee87a 100644 --- a/src/com/annimon/turrets/NetworkListener.java +++ b/src/com/annimon/turrets/NetworkListener.java @@ -8,7 +8,8 @@ public interface NetworkListener { public static final int ON_CONNECT = 1, - ON_SEED_RECEIVED = 2; + ON_SEED_RECEIVED = 2, + ON_MOVE_RECEIVED = 3; public void onStatusChanged(int status, Object data); } diff --git a/src/com/annimon/turrets/SocketHelper.java b/src/com/annimon/turrets/SocketHelper.java index 8eccf6a..883e015 100644 --- a/src/com/annimon/turrets/SocketHelper.java +++ b/src/com/annimon/turrets/SocketHelper.java @@ -34,6 +34,9 @@ public class SocketHelper extends Thread { case NetworkListener.ON_SEED_RECEIVED: listener.onStatusChanged(status, receiveSeed()); break; + case NetworkListener.ON_MOVE_RECEIVED: + listener.onStatusChanged(status, receiveMove()); + break; } } catch (IOException ex) { } @@ -54,6 +57,25 @@ public class SocketHelper extends Thread { return dis.readLong(); } + public void sendMove(TurretInfo info) { + try { + dos.writeInt(NetworkListener.ON_MOVE_RECEIVED); + dos.writeDouble(info.barrelAngle); + dos.writeDouble(info.shotPower); + dos.writeInt(info.barrelX); + dos.writeInt(info.barrelY); + } catch (IOException ex) { } + } + + private TurretInfo receiveMove() throws IOException { + TurretInfo t = new TurretInfo(); + t.barrelAngle = dis.readDouble(); + t.shotPower = dis.readDouble(); + t.barrelX = dis.readInt(); + t.barrelY = dis.readInt(); + return t; + } + public void close() throws IOException { if (dis != null) dis.close(); if (dos != null) dos.close();