📄 house.java
字号:
package com.dfun.blackjack;
import javax.microedition.lcdui.*;
/**************************************************
* @author Beetle
* 类功能介绍:房间管理
**************************************************/
public class House
implements CommandListener {
/**************************************************
*定义公用变量
**************************************************/
private Main main; //主控程序
private String phoneNumber; //电话号码
private Connection conn; //连接对象
private Display display; //显示管理
public long creatorId; //当前房间的庄家id
public String creatorName; //当前房间的庄家名称
public String houseName; //房间名称
public long houseId; //房间id
public int maxClient; //最高上限
public String[][] houseUserList; //房间用户列表
private ChoiceGroup choHouseUserList;
private Hall hall; //游戏大厅
private Image img[]; //图片数组
/**************************************************
*定义房间变量
**************************************************/
public Form houseForm; //房间窗体
private Command cmdBack; //退出房间
private Command cmdSendMessage; //发言
/*******************************************************
* 功能介绍:构造函数
* 输入参数:无
*******************************************************/
public House(Display display, Connection conn, String phoneNumber, Main main, Hall hall) {
/**************************************************
*初始化公用变量
**************************************************/
this.main = main;
this.phoneNumber = phoneNumber;
this.conn = conn;
this.display = display;
this.hall = hall;
img = main.loadImg(4);
}
/*****************************************************
* 功能介绍:显示房间
* 输入参数:无
* 输出参数:无
****************************************************/
public void showHouse() {
houseForm = new Form("房间");
cmdBack = new Command("返回", Command.BACK, 1);
cmdSendMessage = new Command("聊天", Command.OK, 1);
houseForm.append("欢迎来到" + houseName + "当人数达到" + maxClient + "时游戏自动启动");
houseForm.addCommand(cmdBack);
houseForm.addCommand(cmdSendMessage);
choHouseUserList = new ChoiceGroup(null, ChoiceGroup.EXCLUSIVE);
for (int i = 0; i < houseUserList.length; i++) {
choHouseUserList.append(houseUserList[i][1], img[0]);
}
houseForm.append(choHouseUserList);
houseForm.setCommandListener(this);
display.setCurrent(houseForm);
}
/*****************************************************
* 功能介绍:用户退出房间
* 输入参数:用户唯一id
* 输出参数:是否成功
*****************************************************/
public void outHouse(long houseId) {
try {
conn.sendOneData("06" + houseId);
String strTmp = conn.getOneData();
if (!strTmp.equals("ok")) {
return;
}
hall.showHall();
main.refreshState = 0;
}
catch (Exception e) {
}
}
/*****************************************************
* 功能介绍:取得指定房间的用户列表
* 输入参数:房间id
* 输出参数:无
****************************************************/
public void refreshUserList(String strUser) {
String strTmp = strUser;
houseUserList = main.split(strTmp, ",", 3);
switch (main.refreshState) {
case 0:
showHouse();
break;
case 1:
while (choHouseUserList.size() != 0) {
choHouseUserList.delete(0);
}
for (int i = 0; i < houseUserList.length; i++) {
choHouseUserList.append(houseUserList[i][1], null);
}
display.setCurrent(houseForm);
break;
case 2:
while (choHouseUserList.size() != 0) {
choHouseUserList.delete(0);
}
for (int i = 0; i < houseUserList.length; i++) {
choHouseUserList.append(houseUserList[i][1], null);
}
break;
}
}
/*****************************************************
* 功能介绍:进入房间
* 输入参数:房间id,房间名称,创建者id,创建者名称,游戏人数
* 输出参数:无
****************************************************/
public void intoHouse(int i) {
houseId = Long.parseLong(hall.houseList[i][0]);
houseName = hall.houseList[i][1];
creatorId = Long.parseLong(hall.houseList[i][2]);
creatorName = hall.houseList[i][3];
maxClient = Integer.parseInt(hall.houseList[i][4]);
conn.sendOneData("05" + houseId);
}
/*****************************************************
* 功能介绍:进入自建的房间
* 输入参数:房间id,房间名称,创建者id,创建者名称,游戏人数
* 输出参数:无
****************************************************/
public void intoHouse(long houseId, String houseName, long creatorId, String creatorName, int maxClient) {
this.houseId = houseId;
this.houseName = houseName;
this.creatorId = creatorId;
this.creatorName = creatorName;
this.maxClient = maxClient;
conn.sendOneData("05" + houseId);
}
public void commandAction(Command c, Displayable d) {
if (d == houseForm && c == cmdBack) { //返回
outHouse(this.houseId);
}
if (d == houseForm && c == cmdSendMessage) { //发送消息
main.msg.showForm();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -