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

📄 mygame.java

📁 J2ME 3D 第一人称射击迷宫类手机游戏源码。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	public static void resumeSavedLocalGame() {
		// Player p1 = new LocalPlayer(1, "Whitey".toCharArray(), true,
		// BoardMediator.getCanvas());
		// Player p2 = new LocalPlayer(2, "Blackey".toCharArray(), false,
		// BoardMediator.getCanvas());
		// BoardMediator.init(p1, p2, true);
		//
		// setGameType(GAME_TYPE_LOCAL);
		// byte[] b = RmsFacade.get(SAVED_GAME_DATA);
		// ByteArrayInputStream bais = new ByteArrayInputStream(b);
		// try {
		// BoardMediator.loadGame(bais, false);
		// bais.close();
		// } catch (IOException e) {
		// e.printStackTrace();
		// }
		// b = null;
		// bais = null;
		// System.gc();
		//
		// Audio.stopSound(Audio.MUSIC);
		// setCanvas(BoardMediator.getCanvas());
		showMain();
		showRules();
	}

	/**
	 * Top view
	 */
	public static void topView() {
		if (gameStarted)
			switchView(); //
	}

	/**
	 * Exits a game. If the game is not finished it is stored, so it can be
	 * resumed later.
	 */
	public synchronized static void exitGame() {
		// Local game
		// if (getGameType() == GAME_TYPE_LOCAL) {
		// if (!BoardMediator.isGameFinished()) {
		// // Local game is not finished, save it
		// try {
		// if (BoardMediator.getCurrentPlayer() != null) {
		// ByteArrayOutputStream baos = new ByteArrayOutputStream();
		// BoardMediator.saveGame(baos);
		// baos.close();
		// RmsFacade.set(SAVED_GAME_DATA, baos.toByteArray());
		// RmsFacade.setBoolean(HAS_SAVED_LOCAL_GAME, true);
		// }
		// } catch (IOException e) {
		// e.printStackTrace();
		// }
		// } else {
		// // Local game is finished, remove any local saved game
		// RmsFacade.set(SAVED_GAME_DATA, null);
		// RmsFacade.setBoolean(HAS_SAVED_LOCAL_GAME, false);
		// }
		// }

		// Load preferred rules
		// Rules.setRuleFlags(RmsFacade.getInt(MyGame.RULES_PREFERRED));
		// Show menu
		MenuCanvas.getInstance().initShow();
		setCanvas(MenuCanvas.getInstance());
	}

	/**
	 * Shuts down the MIDlet.
	 */
	public synchronized static void shutdown() {
		RmsFacade.shutdown();
		Audio.shutdown();
		try {
			myMidlet.destroyApp(true);
		} catch (MIDletStateChangeException e) {
			e.printStackTrace();
		}

		if (m_popupCache != null) {
			m_popupCache.dispose();
			m_popupCache = null;
		}

		m_inst = null;
		System.gc();
		myMidlet.quitApp();

		// Device.getMidlet().notifyDestroyed();
	}

	/**
	 * Displays a popup with current rule settings.
	 */
	public static void showRules() {
		// String str = Resources.getString(Resources.TXT_T_RULES) + "\n\n";
		// if (Rules.isAnyRuleSet()) {
		// if (Rules.isSet(Rules.EVEN_OUT)) {
		// str += Resources.getString(Resources.TXT_I_R_EVENOUT) + "\n";
		// }
		// if (Rules.isSet(Rules.MAX_FIVE)) {
		// str += Resources.getString(Resources.TXT_I_R_MAXFIVE) + "\n";
		// }
		// } else {
		// str += Resources.getString(Resources.TXT_NO_RULES);
		// }
		// str += "\n";
		//
		// MyGame.showPopup(str.toCharArray(), null, 10, 0, 0, null);
	}

	/**
	 * Sets specified canvas as current
	 * 
	 * @param c
	 *            The canvas to set
	 */
	public synchronized static void setCanvas(PopupCanvas c) {
		m_currentCanvas = c;
		// Device.getDisplay().setCurrent(c);
		Display.getDisplay(myMidlet).setCurrent(c);
		c.repaint();
	}

	/**
	 * Returns current canvas
	 * 
	 * @return Current canvas
	 */
	public synchronized static PopupCanvas getCanvas() {
		return m_currentCanvas;
	}

	/**
	 * Returns true if a popup is currently displayed to the user
	 * 
	 * @return true if a popup is displayed
	 */
	public synchronized static boolean isShowingPopup() {
		if (getCanvas() != null && getCanvas().getPopup() != null
				&& getCanvas().getPopup().isActive()) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * Returns current displayed popup
	 * 
	 * @return Current popup or null if no popup is displayed
	 */
	public synchronized static Popup getCurrentPopup() {
		if (!isShowingPopup())
			return null;
		else
			return getCanvas().getPopup();
	}

	/**
	 * Shows a popup on the device display, enabling the user to make a choice
	 * amongst specified alternatives. Selected alternative is reported to
	 * specified listener. The popup has a timeout - if this timeout is reached
	 * the listener receives the specified timeout choice. If the user already
	 * has a popup open, a call to this method makes current popup go away and
	 * the listener to current popup is reported with the timeout choice. After
	 * this, specified popup is presented. Thus, it is the responsibility of the
	 * server or proxy layer to buffer multiple incoming popups. To check if a
	 * popup is currently displayed, use <code>MyGame.getCurrentPopup()</code>
	 * or <code>MyGame..isShowingPopup()</code>
	 * 
	 * @param text
	 *            Character array with text presented in popup.
	 * @param altTexts
	 *            Array of character arrays with alternatives presented in
	 *            popup. If this argument is null, no alternatives are
	 *            presented.
	 * @param timeOutInSeconds
	 *            The timeout in seconds. If this argument is set to zero, the
	 *            popup is displayed until the a user makes a choice. If no
	 *            choices are given and the timeout is zero, this popup will not
	 *            show.
	 * @param defaultChoice
	 *            The default selection when the popup appears.
	 * @param timeOutChoice
	 *            The choice reported if the popup times out or is overridden by
	 *            another popup.
	 * @param listener
	 *            The listener to this popup.
	 */
	public synchronized static Popup showPopup(char[] text, char[][] altTexts,
			int timeOutInSeconds, int defaultChoice, int timeOutChoice,
			PopupListener listener) {
		if (getCanvas() == null)
			return null;

		if (getCanvas().getPopup() != null && getCanvas().getPopup().isActive()) {
			Popup p = getCanvas().getPopup();
			getPopupListener().selectedChoice(p.getTimeOutChoice(), true);
			p.dispose();
			m_popupCache = p;
		}

		Popup p = getPopupInstance();
		p.init(text, altTexts, (byte) timeOutInSeconds, (byte) defaultChoice,
				(byte) timeOutChoice, getPopupListener(), getCanvas()
						.getWidth(), getCanvas().getHeight());
		m_popupListener = listener;
		getCanvas().setPopup(p);
		getCanvas().repaint();
		return p;
	}

	/**
	 * Returns a popup instance from cache.
	 * 
	 * @return A popup instance
	 */
	protected synchronized static Popup getPopupInstance() {
		if (m_popupCache == null) {
			m_popupCache = new Popup();
		}
		return m_popupCache;
	}

	/**
	 * Returns a popuplistener that can be used for dispatching popup events,
	 * used internally only.
	 * 
	 * @return A popuplistener dispatching events.
	 */
	protected synchronized static PopupListener getPopupListener() {
		return getInstance();
	}

	public static RecordStore rs = null;

	public static int addRecord(int value) {
		int re = -1;
		try {
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			DataOutputStream dos = new DataOutputStream(baos);
			dos.writeInt(value);
			dos.close();
			baos.close();
			re = rs.addRecord(baos.toByteArray(), 0, baos.toByteArray().length);
		} catch (RecordStoreException rse) {
			return -1;
		} catch (IOException e) {
			System.out.println(e.toString());
			return -1;
		}
		return re;
	}

	public static int getInt(int recordID) {
		int value = -1;
		try {
			byte[] temp = rs.getRecord(recordID);
			ByteArrayInputStream bais = new ByteArrayInputStream(temp);
			DataInputStream dis = new DataInputStream(bais);
			value = dis.readInt();
			bais.close();
			dis.close();
		} catch (RecordStoreException rse) {
			System.out.println("--------------------");
			return -1;
		} catch (IOException e) {
			System.out.println("+++++++++++++++++++");
			System.out.println(e.toString());
			return -1;
		}
		return value;
	}

	public static boolean setInt(int recordID, int value) {
		try {
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			DataOutputStream dos = new DataOutputStream(baos);
			dos.writeInt(value);
			dos.close();
			baos.close();
			rs.setRecord(recordID, baos.toByteArray(), 0,
					baos.toByteArray().length);
		} catch (RecordStoreException rse) {
			return false;
		} catch (IOException e) {
			System.out.println(e.toString());
			return false;
		}
		return true;
	}

	public static boolean deleteRecord(int recordID) {
		try {
			rs.deleteRecord(recordID);
			return true;
		} catch (RecordStoreException rse) {
			return false;
		}
	}

	public static int getRecordCounts() {
		try {
			return rs.getNumRecords();
		} catch (RecordStoreException rse) {
			return -1;
		}
	}

	public static int getNextID() {
		try {
			return rs.getNextRecordID();
		} catch (RecordStoreException rse) {
			return -1;
		}
	}

	public static void close() {
		try {
			rs.closeRecordStore();
		} catch (RecordStoreException rse) {
		}
	}
}

⌨️ 快捷键说明

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