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

📄 dictionary.java

📁 --- --- --- -基于蓝牙的J2ME游戏框架---------------很有用的
💻 JAVA
字号:
//
// Copyright 2002 Nokia Corporation
//
// THIS SOURCE CODE IS PROVIDED 'AS IS', WITH NO WARRANTIES WHATSOEVER,
// EXPRESS OR IMPLIED, INCLUDING ANY WARRANTY OF MERCHANTABILITY, FITNESS
// FOR ANY PARTICULAR PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE
// OR TRADE PRACTICE, RELATING TO THE SOURCE CODE OR ANY WARRANTY OTHERWISE
// ARISING OUT OF ANY PROPOSAL, SPECIFICATION, OR SAMPLE AND WITH NO
// OBLIGATION OF NOKIA TO PROVIDE THE LICENSEE WITH ANY MAINTENANCE OR
// SUPPORT. FURTHERMORE, NOKIA MAKES NO WARRANTY THAT EXERCISE OF THE
// RIGHTS GRANTED HEREUNDER DOES NOT INFRINGE OR MAY NOT CAUSE INFRINGEMENT
// OF ANY PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OWNED OR CONTROLLED
// BY THIRD PARTIES
//
// Furthermore, information provided in this source code is preliminary,
// and may be changed substantially prior to final release. Nokia Mobile
// Phones Ltd. retains the right to make changes to this source code at
// any time, without notice. This source code is provided for informational
// purposes only.
//
// Third-party brands and names are the property of their respective
// owners. Java(TM) and J2ME(TM) are registered trademarks of
// Sun Microsystems Inc.
//
// A non-exclusive, non-transferable, worldwide, limited license is hereby
// granted to the Licensee to download, print, reproduce and modify the
// source code. The licensee has the right to market, sell, distribute and
// make available the source code in original or modified form only when
// incorporated into the programs developed by the Licensee. No other
// license, express or implied, by estoppel or otherwise, to any other
// intellectual property rights is granted herein.
//


import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;

import java.io.*; //IOException;


// This class maps integer id's to Strings used in the user interface
// screens of the MIDlet. It is meant as a simple placeholder for
// internationalization support.
//
// Currently, the default (and only) language supported is "en-US".
// The class could be extended to support other mappings in the future,
// although it currently supports just one.
//
// (Note: A few simple strings used in CloseableCanvas like ":", "(", ")",
// numeric strings, and white space like " " or "\n" are not translated
// by the Dictionary. If those would need internationalization support,
// then appropriate support would need to be added.)

class Dictionary
{
    // The types of strings used in the MIDlet user interface are:
    //   LABEL : short text labels used in simple UI elements like
    //           Commands, List StringItems, etc.
    //    TEXT : text strings that are 'contents' of some screen, i.e. drawn
    //           in the game screen or used in the instructions screen

    private static short ix = 0;
    final static short TEXT_ZERO = ix++;
    final static short MENU_0  = ix++;
    final static short MENU_1  = ix++;
    final static short MENU_2  = ix++;
    final static short MENU_3  = ix++;
    final static short MENU_4  = ix++;
    final static short MENU_5  = ix++;
    final static short MENU_6  = ix++;
    final static short MENU_7  = ix++;
    final static short MENU_8  = ix++;
    final static short MENU_9  = ix++;
    final static short MENU_A  = ix++;
    final static short MENU_B  = ix++;
    final static short MENU_C  = ix++;
    final static short MENU_D  = ix++;
    final static short MENU_E  = ix++;
    final static short MENU_F  = ix++;
    final static short MENU_G  = ix++;
    final static short QUIT    = ix++;
    final static short BT_WAIT_JOIN = ix++;
    final static short BT_SEARCH_HOST = ix++;
    final static short TUT_1  = ix++;
    final static short TUT_2  = ix++;
    final static short TUT_3  = ix++;
    final static short TUT_4  = ix++;
    final static short TUT_5  = ix++;
    final static short CONT_1  = ix++;
    final static short CONT_2  = ix++;
    final static short CONT_3  = ix++;
    final static short CONT_4  = ix++;
    final static short CONT_5  = ix++;
    final static short CONT_6  = ix++;
    final static short CONT  = ix++;
    final static short CONT2  = ix++;
    final static short LEVEL_COMPLETE = ix++;
    final static short GAME_OVER = ix++;
    final static short OOT = ix++;
    final static short GET_READY = ix++;
    final static short ABSORB_GREEN = ix++;
    final static short ABSORB_PURP = ix++;
    final static short PRESS_FIRE = ix++;
    final static short CRED_1  = ix++;
    final static short CRED_2  = ix++;
    final static short CRED_3  = ix++;
    final static short CRED_4  = ix++;
    final static short CRED_5  = ix++;
    final static short CRED_6  = ix++;
    final static short CRED_7  = ix++;
    final static short CRED_8  = ix++;
    final static short CRED_9  = ix++;
    final static short INT_CONN = ix++;
    final static short SUB_SUC = ix++;
    final static short SUB_FAIL = ix++;
    final static short TIME = ix++;
    final static short LIVES = ix++;
    final static short SCORE = ix++;
    final static short BT_LOST = ix++;
    final static short COMP1 = ix++;
    final static short COMP2 = ix++;
    final static short COMP3 = ix++;
    final static short COMP4 = ix++;
    final static short COMP5 = ix++;
    final static short NUM_IDS = ix;

    private static Dictionary instance = null;
    static String locale;

	GameCanvas c;
    private String[] strings;


    Dictionary(GameCanvas can, String loc, String encoding)
    {

        // If you decide to add additional internationalization support,
        // you would need to modify this method, something like this:
        //    if (locale.equals("xx-YY"))
        //    {
        //        strings = stringsXxYY();
        //    }
        //    else if (locale.startsWith("zz"))
        //    {
        //        // e.g. might keep the strings a in .dat resource file
        //        strings = stringsZz();
        //    }
        //    else
        //    {
        //        strings = stringsEnUS(); // use default language
        //    }
        //
        // The strings returned by the 'stringsXxYy()' internationalization
        // methods could be defined at compile-time, as in the default
        // method stringsEnUs(), or at run-time.
        //
        // Run-time support would involve reading the strings
        // from appropriate resource files added to the MIDlet's .jar file.
        // (e.g. "en-UK.dat", "en.dat", "fi-FI.dat", "fi-SE.dat", etc.)
        // Such an approach would allow one to separate the process
        // of internationalizing strings from the process of compiling the
        // MIDlet. (Determining which .dat files are part of a particular
        // version of a MIDlet's .jar file, would be part of the
        // MIDlet jarring and deployment process.) You may also need
        // to used fixed dictionary entry ID's above.

        // The only language currently supported is the default one: "us-EN".
        c = can;
        locale = loc;
        strings = stringsEnUS();
    }


    private String[] stringsEnUS()
    {
        // USA English strings

        String[] strArray = new String[NUM_IDS];
		String	 sText = null;
		byte[] bText = new byte[1600];

		DataInputStream datainputstream = null;
		try
		{
			if (locale.startsWith("de"))
				datainputstream = new DataInputStream(getClass().getResourceAsStream("/de.txt"));
			else if (locale.startsWith("fr"))
				datainputstream = new DataInputStream(getClass().getResourceAsStream("/fr.txt"));
			else if (locale.startsWith("it"))
				datainputstream = new DataInputStream(getClass().getResourceAsStream("/it.txt"));
			else if (locale.startsWith("es"))
				datainputstream = new DataInputStream(getClass().getResourceAsStream("/sp.txt"));
			else
				datainputstream = new DataInputStream(getClass().getResourceAsStream("/en.txt"));

			datainputstream.readFully(bText);
		}
		catch (EOFException e)
		{
			// should be ok
			System.out.println ("EOFException");
		}
		catch (Exception e)
		{
			System.out.println ("Exception");
			return strArray;
		}
		finally
		{
			try
			{
				if (datainputstream != null)
					datainputstream.close();
				System.out.println ("Dict Closed ok");
			}
			catch (Exception ex)
			{
				// Who cares?
				System.out.println ("Dict Exception2 "+ex.getMessage());
			}

		}

		sText = fromUTF8(bText);
		if (sText != null)
		{
			strArray[TEXT_ZERO] 	= "";
			int i = 0,
				j = 1;
			StringBuffer buf = null;
//System.out.println (sText.length());
			while (i < sText.length())
			{
				if (buf == null) buf = new StringBuffer("");
				if (sText.charAt(i) == '\n' )
				{
					switch (j)
					{
						case 27:
							strArray[j++] = "|"+c.getKeyName(c.getKeyCode(GameCanvas.LEFT)) + " " + buf.toString();
							break;
						case 28:
							strArray[j++] = "|"+c.getKeyName(c.getKeyCode(GameCanvas.RIGHT)) + " " + buf.toString();
							break;
						case 29:
							strArray[j++] = "|"+c.getKeyName(c.getKeyCode(GameCanvas.UP)) + " " + buf.toString();
							break;
						case 30:
							strArray[j++] = "|"+c.getKeyName(c.getKeyCode(GameCanvas.DOWN)) + " " + buf.toString();
							break;
						case 31:
							strArray[j++] = "|"+c.getKeyName(c.getKeyCode(GameCanvas.FIRE)) + " " + buf.toString();
							break;
						case 32:
							strArray[j++] = strArray[26]+strArray[27]+strArray[28]+strArray[29]+strArray[30]+strArray[31];
						default:
							strArray[j++] = buf.toString();
							break;
					}
					buf = null;
					if (j >= NUM_IDS)
					{
//						System.out.println ("NUM_IDS too small");
						break;
					}
				}
				else
				{
					if ((int)sText.charAt(i) != 13) buf.append(sText.charAt(i));
				}
				i++;
			}
		}
		else
		{
System.out.println ("Dict Exception3 Shoite ");
		}

        return strArray;
    }


    String getString(int id)
    {
        if ((id >= 0) && (id < strings.length))
        {
            return strings[id];
        }
        else
        {
            throw new IllegalArgumentException("Errore" + id +
                " " + strings.length);
        }
    }

	static String fromUTF8 (byte [] ao)
	{
		int nCharCode, i;
		int nLength = ao.length;
		char [] ach = new char [nLength];

		int nCount = 0;

		loop: for (i = 0; i < nLength; i ++)
		{
			nCharCode = ((int) ao [i]) & 0x00ff;

			if (nCharCode >= 0x80)
			{
				if (nCharCode < 0xe0)
				{
					// need 2 bytes
					nCharCode = (nCharCode & 0x1f) << 6;
					nCharCode |= (((int) ao [++ i]) & 0x3f);
				}
				else
				{
					// need 3 bytes
					nCharCode = (nCharCode & 0x0f) << 12;
					nCharCode |= (((int) ao [++ i]) & 0x3f) << 6;
					nCharCode |= (((int) ao [++ i]) & 0x3f);

					// ignore character added by Notepad
					if (nCharCode == 0xfeff)
					{
						continue loop;
					}
				}
			}

			ach [nCount ++] = (char) nCharCode;
		}

		return new String (ach, 0, nCount);
	}

}

⌨️ 快捷键说明

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