📄 gameovermsg.java
字号:
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;
public class GameOverMsg implements Msg {
int msgType = Msg.GAME_OVER_MSG;
private TankClient tc;
public static int x=(int) (Math.random() * 800);
public GameOverMsg(TankClient tc) {
this.tc = tc;
}
public void send(DatagramSocket ds, String IP, int udpPort) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
try {
dos.writeInt(msgType);
dos.writeInt(tc.tank.getTankId());
dos.writeInt(tc.tank.x);
dos.writeInt(tc.tank.y);
dos.writeBoolean(tc.tank.isLive());
dos.writeInt(tc.tank.blood);
byte[] buf = baos.toByteArray();
DatagramPacket dp = new DatagramPacket(buf, buf.length,
new InetSocketAddress(IP, udpPort));
ds.send(dp);
} catch (Exception e) {
e.printStackTrace();
}
}
public void parse(DataInputStream dis) {
System.out.println("客户端接收一份服务端发来GrameOver的数据!");
try {
int tankId = dis.readInt();
int x = dis.readInt();
int y = dis.readInt();
for (int i = 0; i < tc.playerTanks.size(); i++) {
Tank pt = tc.playerTanks.get(i);
if (tankId == pt.getTankId()) {
pt.x = x;
pt.y = y;
}
pt.setReady(false);
pt.setLive(true);
pt.blood = 100;
pt.dir = Direction.STOP;
pt.bL=false;
pt.bU=false;
pt.bR=false;
pt.bD=false;
}
tc.tank.bL = false;
tc.tank.bU = false;
tc.tank.bR = false;
tc.tank.bD = false;
tc.setReadyer(0);
tc.tank.setReady(false);
tc.setWin(0);
tc.ms.removeAll(tc.ms);
tc.explodes.removeAll(tc.explodes);
tc.items.removeAll(tc.items);
tc.tank.dir = Direction.STOP;
tc.tank.setLive(true);
tc.tank.blood = 100;
tc.tank.setReady(false);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
tc.join.setVisible(true);
tc.setVisible(false);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -