⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hall.java

📁 游戏源码
💻 JAVA
字号:
package com.dfun.blackjack;

import javax.microedition.lcdui.*;

/**************************************************
 * @author Beetle
 * 类功能介绍:房屋管理
 **************************************************/
public class Hall
	implements CommandListener {
	/**************************************************
	 *定义公用变量
	 **************************************************/
	private Main main; //主控程序
	private String phoneNumber; //电话号码
	private Connection conn; //连接对象
	private Display display; //显示管理
	public String[][] houseList; //房间列表,值依次为:房间id,房间名称,庄家id,庄家名称,人数上限,现有人数
	private Image img[]; //图片数组
	/**************************************************
	 *定义主窗体变量
	 **************************************************/
	private Form mainForm; //大厅窗体
	public ChoiceGroup choHouseList; //房间列表
	private Command cmdNewHouse; //新建房间
	private Command cmdInto; //进入房间
	private Command cmdRefresh; //刷新按扭
	/**************************************************
	 *定义新建窗体变量
	 **************************************************/
	private Form newHouse; //新建房间
	private TextField maxClient; //人数上限
	private TextField houseName; //房间名称
	private Command cmdRequest; //提交
	private Command cmdCancel; //取消
	/*******************************************************
	 * 功能介绍:构造函数
	 * 输入参数:显示管理,连接对象,手机号码,主程序
	 *******************************************************/
	public Hall(Display display, Connection conn, String phoneNumber, Main main) {
		/**************************************************
		 *初始化公用变量
		 **************************************************/
		this.main = main;
		this.phoneNumber = phoneNumber;
		this.conn = conn;
		this.display = display;
		img = main.loadImg(3);
		/**************************************************
		 *初始化主窗体变量
		 **************************************************/
		choHouseList = new ChoiceGroup(null, List.EXCLUSIVE); //房间列表
		mainForm = new Form("游戏大厅");
		mainForm.append("请选择房间,如果人数上限或游戏已开始则不能进入!");
		mainForm.append(choHouseList);
		cmdRefresh = new Command("刷新", Command.OK, 1);
		cmdNewHouse = new Command("新建", Command.OK, 1);
		mainForm.addCommand(cmdRefresh);
		cmdInto = new Command("进入", Command.OK, 1);
		mainForm.addCommand(cmdNewHouse);
		mainForm.addCommand(cmdInto);
		mainForm.setCommandListener(this);
		/**************************************************
		 *初始化新建窗体变量
		 **************************************************/
		newHouse = new Form("新建房间");
		houseName = new TextField("房间名称", main.strUserName + "所建房间", 15, TextField.ANY);
		maxClient = new TextField("游戏人数,人数到达后游戏自动开始", "", 2, TextField.NUMERIC);
		cmdRequest = new Command("提交", Command.OK, 1);
		cmdCancel = new Command("取消", Command.BACK, 1);
		newHouse.append(houseName);
		newHouse.append(maxClient);
		newHouse.addCommand(cmdRequest);
		newHouse.addCommand(cmdCancel);
		newHouse.setCommandListener(this);
	}

	/*****************************************************
	 * 功能介绍:显示游戏大厅
	 * 输入参数:无
	 * 输出参数:无
	 *****************************************************/
	public void showHall() {
		houseName.setString(main.strUserName + "所建房间");
		while (choHouseList.size() != 0) {
			choHouseList.delete(0);
		}
		for (int j = 0; j < houseList.length; j++) {
			choHouseList.append(houseList[j][1], img[0]);
		}
		display.setCurrent(mainForm);
		main.refreshState = 0;
	}

	/*****************************************************
	 * 功能介绍:刷新游戏大厅
	 * 输入参数:无
	 * 输出参数:无
	 *****************************************************/
	public void refreshHall(String inputStr) {
		houseList=main.split(inputStr,",",6);
		ChoiceGroup choiceTmp = new ChoiceGroup(null, List.EXCLUSIVE); ;
		for (int j = 0; j < houseList.length; j++) {
			choiceTmp.append(houseList[j][1], null);
		}
		choHouseList = choiceTmp;
		mainForm.delete(1);
		mainForm.append(choHouseList);
		if(mainForm==display.getCurrent()){
			display.setCurrent(mainForm);
		}
	}

	public void commandAction(Command c, Displayable d) {
		if (c == cmdRefresh && d == mainForm) { //刷新游戏大厅
			if (!conn.getHouseList()) {
				display.setCurrent(new Alert("系统提示", "对不起网络信号不好取数据失败请稍候重试!", null, AlertType.ERROR));
			}

		}
		if (c == cmdInto && d == mainForm) { //进入房间
			if (choHouseList.getSelectedIndex() < 0) {
				display.setCurrent(new Alert("系统提示", "对不起您没有选定房间!", null, AlertType.ERROR));
				return;
			}
			int index = choHouseList.getSelectedIndex();
			main.house.intoHouse(index);
		}

		if (c == cmdNewHouse && d == mainForm) { //新建房间
			display.setCurrent(newHouse);
		}
		if (c == cmdCancel && d == newHouse) { //取消
			display.setCurrent(mainForm);
		}
		if (c == cmdRequest && d == newHouse) { //提交
			if (houseName.size() <= 0) {
				display.setCurrent(new Alert("系统提示", "您还未填写房间名称!", null, AlertType.ERROR));
				return;
			}
			if (maxClient.size() <= 0) {
				display.setCurrent(new Alert("系统提示", "您还未填写游戏人数!", null, AlertType.ERROR));
				return;
			}
			if (Integer.parseInt(maxClient.getString()) < 1 || Integer.parseInt(maxClient.getString()) > 4) {
				display.setCurrent(new Alert("系统提示", "您填写的人数必须是1至4!", null, AlertType.ERROR));
				return;
			}

			long houseId = conn.addHouse(houseName.getString(), main.userId, main.strUserName, Integer.parseInt(maxClient.getString()));
			main.house.intoHouse(houseId, houseName.getString(), main.userId, main.strUserName, Integer.parseInt(maxClient.getString()));
		}
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -