📄 connectioncontroler.java
字号:
/*
*通信
*作者:肖昶
*
*/
package fivegame;
import java.io.*;
public class ConnectionControler {
static DataInputStream dis;
static DataOutputStream dos;
public static final void initConnCtrl(DataInputStream dis,
DataOutputStream dos) {
ConnectionControler.dis = dis;
ConnectionControler.dos = dos;
}
public static final void sendChess(byte x, byte y) {
try {
dos.writeByte(1);
dos.writeByte(x);
dos.writeByte(y);
dos.flush();
} catch (Exception e) {
e.printStackTrace();
}
}
public static final void sendUserInfo(String userName, short wfs[])
throws IOException {
dos.writeUTF(userName);
dos.writeShort(wfs[0]);
dos.writeShort(wfs[1]);
dos.flush();
}
public static final byte readMessageType() throws IOException,
EOFException, InterruptedIOException {
return dis.readByte();
}
public static final byte[] readChess() {
byte chess[] = new byte[2];
try {
chess[0] = dis.readByte();
chess[1] = dis.readByte();
} catch (Exception e) {
e.printStackTrace();
}
return chess;
}
public static final String readUserName() {
String name = null;
try {
name = dis.readUTF();
} catch (IOException e) {
e.printStackTrace();
}
return name;
}
public static final short[] readUserWL() {
short data[] = new short[2];
try {
data[0] = dis.readShort();
data[1] = dis.readShort();
} catch (Exception e) {
e.printStackTrace();
}
return data;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -