?? 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 + -