📄 connectioncontroler.java
字号:
package unicoco;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.EOFException;
import java.io.IOException;
import java.io.InterruptedIOException;
import javax.microedition.io.StreamConnection;
public class ConnectionControler {
// 发送棋子的坐标
static DataInputStream dis;
static DataOutputStream dos;
static StreamConnection conn;
public final static void iniConnCtrl(DataInputStream dis,
DataOutputStream dos, StreamConnection conn) {
ConnectionControler.dis = dis;
ConnectionControler.dos = dos;
ConnectionControler.conn = conn;
}
public final static void sendChess(byte x, byte y) {
try {
dos.writeByte(99);
dos.writeByte(x);
dos.writeByte(y);
dos.flush();
} catch (Exception e) {
MIDGame.game.notifyDestroyed();
}
}
public final static void sendUserInfo(String userName, short[] wfs)
throws IOException {
dos.writeUTF(userName);
dos.writeShort(wfs[0]);
dos.writeShort(wfs[1]);
dos.flush();
}
public final static byte readMessageType() throws IOException, EOFException,
InterruptedIOException {
byte messageType = 0;
messageType = dis.readByte();
return messageType;
}
public final static byte[] readChess() {
byte[] chess = new byte[2];
try {
chess[0] = dis.readByte();
chess[1] = dis.readByte();
} catch (Exception e) {
MIDGame.game.notifyDestroyed();
}
return chess;
}
public final static String readMessage() {
String message = null;
try {
message = dis.readUTF();
} catch (Exception e) {
MIDGame.game.notifyDestroyed();
}
return message;
}
public final static void sendMessage(String ms) {
try {
dos.writeByte(98);
dos.writeUTF(ms);
dos.flush();
} catch (Exception e) {
MIDGame.game.notifyDestroyed();
}
}
public final static String readUserName() {
String name = null;
try {
name = dis.readUTF();
} catch (IOException e) {
// e.printStackTrace();
}
return name;
}
public final static short[] readUserWF() {
short[] test = new short[2];
try {
test[0] = dis.readShort();
test[1] = dis.readShort();
} catch (Exception e) {
MIDGame.game.notifyDestroyed();
}
return test;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -