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

📄 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.*;


// 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 LABEL_HISCORE = ix++;
    final static short LABEL_BACK = ix++;
    final static short LABEL_CONTINUE = ix++;
    final static short LABEL_EDIT = ix++;
    final static short LABEL_EXIT = ix++;
    final static short LABEL_INSTRUCTIONS = ix++;
    final static short LABEL_NEWGAME = ix++;
    final static short LABEL_MODIFY = ix++;
    final static short LABEL_OFF = ix++;
    final static short LABEL_ON = ix++;
    final static short LABEL_SETTINGS = ix++;
    final static short LABEL_SOUND = ix++;
    final static short LABEL_VERSION = ix++;
    final static short LABEL_VIBRATION = ix++;
    final static short TEXT_GAME_YOU_DESTROYED = ix++;
    final static short TEXT_GAME_BLOCKS = ix++;
    final static short TEXT_GAME_QUIT_PROMPT = ix++;
    final static short TEXT_GAME_RESUME_PROMPT = ix++;
    final static short TEXT_GAME_LEVEL_COMPLETE = ix++;
    final static short TEXT_GAME_LEVEL_BONUS = ix++;
    final static short TEXT_GAME_LEVEL = ix++;
    final static short TEXT_GAME_NEW_HISCORE = ix++;
    final static short TEXT_GAME_YOU = ix++;
    final static short TEXT_GAME_YOU_WON = ix++;
    final static short TEXT_GAME_YOU_LOST = ix++;
    final static short TEXT_INSTRUCTIONS = ix++;
    final static short TEXT_INSTRUCTIONS_GAUGE = ix++;
    final static short NUM_IDS = ix;

    private static Dictionary instance = null;

    private String[] strings;


    Dictionary(String locale, 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".
        strings = stringsEnUS();
    }


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

        String[] strArray = new String[NUM_IDS];

        // Labels
        strArray[LABEL_HISCORE] = "High Score";
        strArray[LABEL_BACK] = "Back";
        strArray[LABEL_CONTINUE] = "Continue";
        strArray[LABEL_EDIT] = "Edit";
        strArray[LABEL_EXIT] = "Exit";
        strArray[LABEL_INSTRUCTIONS] = "Instructions";
        strArray[LABEL_MODIFY] = "Modify";
        strArray[LABEL_NEWGAME] = "New game";
        strArray[LABEL_OFF] = "off";
        strArray[LABEL_ON] = "on";
        strArray[LABEL_SETTINGS] = "Settings";
        strArray[LABEL_SOUND] = "Sound";
        strArray[LABEL_VERSION] = "Version";
        strArray[LABEL_VIBRATION] = "Vibration";

        // Game screen text strings
        strArray[TEXT_GAME_YOU_DESTROYED] = "S-P-L-A-T-T!";
        strArray[TEXT_GAME_RESUME_PROMPT] = "Press a key to resume";
        strArray[TEXT_GAME_QUIT_PROMPT] = "Use softkey to quit";
        strArray[TEXT_GAME_LEVEL_COMPLETE] = "Level Complete!";
        strArray[TEXT_GAME_LEVEL_BONUS] = "Bonus  ";
        strArray[TEXT_GAME_LEVEL] = "Level ";
        strArray[TEXT_GAME_NEW_HISCORE] = "New Hi-Score ";
        strArray[TEXT_GAME_YOU_LOST] = "Game Over!";

        // Instructions screen text strings
        Canvas c = new CloseableCanvas("");
        String up = c.getKeyName(c.getKeyCode(Canvas.UP));
        String down = c.getKeyName(c.getKeyCode(Canvas.DOWN));
        String left = c.getKeyName(c.getKeyCode(Canvas.LEFT));
        String right = c.getKeyName(c.getKeyCode(Canvas.RIGHT));
        String fire = c.getKeyName(c.getKeyCode(Canvas.FIRE));
        strArray[TEXT_INSTRUCTIONS] =
            // Describe game's objective and how to play:
		"You are in command of a drop ship that must clear a path on " +
		"the planets surface which is covered in cystals.\n" +
		"To clear the planets surface you must drop bombs " +
		"on the crystals to destroy them.\n" +
            // Describe keypad usage:
		"Use " + fire + " to drop bombs.\n" +
		"Good Luck!";

        return strArray;
    }


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

⌨️ 快捷键说明

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