📄 resources.java
字号:
package myGame.main;
import java.io.InputStream;
import java.util.Hashtable;
import javax.microedition.lcdui.Image;
/**
* Primitive resource mapper.
*
* @author YuBingxing
*/
public class Resources {
// Text keys
private static int TXTID = 0;
// text / page titles / 7
public static final int TXT_T_MYMAZE3DGAME = TXTID++;
public static final int TXT_T_GARPHICS3DPROPERTIES = TXTID++;
public static final int TXT_T_SETTINGS = TXTID++;
public static final int TXT_T_SCORES = TXTID++;
public static final int TXT_T_DIFFICULTY = TXTID++;
public static final int TXT_T_TIMELIMIT = TXTID++;
public static final int TXT_T_BGMUSIC = TXTID++;
// text / item labels / 20
public static final int TXT_I_NEWGAME = TXTID++;
public static final int TXT_I_CONTINUE = TXTID++;
public static final int TXT_I_GARPHICS3DPROPERTIES = TXTID++;
public static final int TXT_I_TOPVIEW = TXTID++;
public static final int TXT_I_SETTINGS = TXTID++;
public static final int TXT_I_ABOUT = TXTID++;
public static final int TXT_I_EXIT = TXTID++;
public static final int TXT_I_BT_SCORES = TXTID++;
public static final int TXT_I_S_AUDIO = TXTID++;
public static final int TXT_I_S_DIFFICULTY = TXTID++;
public static final int TXT_I_S_TIMELIMIT = TXTID++;
public static final int TXT_I_S_BGMUSICSELECT = TXTID++;
public static final int TXT_I_S_D_EASY = TXTID++;
public static final int TXT_I_S_D_NORMAL = TXTID++;
public static final int TXT_I_S_D_HARD = TXTID++;
public static final int TXT_I_S_D_VERYHARD = TXTID++;
public static final int TXT_I_S_T_60 = TXTID++;
public static final int TXT_I_S_T_120 = TXTID++;
public static final int TXT_I_S_T_300 = TXTID++;
public static final int TXT_I_S_T_600 = TXTID++;
public static final int TXT_I_S_T_NOLIMIT = TXTID++;
public static final int TXT_I_S_BGMUSIC1 = TXTID++;
public static final int TXT_I_S_BGMUSIC2 = TXTID++;
public static final int TXT_I_S_BGMUSIC3 = TXTID++;
// text / commands / 7
public static final int TXT_C_OK = TXTID++;
public static final int TXT_C_CANCEL = TXTID++;
public static final int TXT_C_BACK = TXTID++;
public static final int TXT_C_HELP = TXTID++;
public static final int TXT_C_UNDO = TXTID++;
public static final int TXT_C_QUIT = TXTID++;
public static final int TXT_C_REFRESH = TXTID++;
// text / popup related / 6
public static final int TXT_YES = TXTID++;
public static final int TXT_NO = TXTID++;
public static final int TXT_CANCEL = TXTID++;
public static final int TXT_OK = TXTID++;
public static final int TXT_GIVE_UP = TXTID++;
public static final int TXT_SAVE_GAME = TXTID++;
// text / helptexts / 10
public static final int TXT_H_NEWGAME = TXTID++;
public static final int TXT_H_CONTINUE = TXTID++;
public static final int TXT_H_GRAPHICS3DPROPERTIES = TXTID++;
public static final int TXT_H_TOPVIEW = TXTID++;
public static final int TXT_H_SCORES = TXTID++;
public static final int TXT_H_SETTINGS = TXTID++;
public static final int TXT_H_ABOUT = TXTID++;
public static final int TXT_H_S_AUDIO = TXTID++;
public static final int TXT_H_S_DIFFICULTY = TXTID++;
public static final int TXT_H_S_TIMELIMIT = TXTID++;
public static final int TXT_H_S_BGMUSIC = TXTID++;
// text / other stuff / 4
public static final int TXT_STARTING_GAME = TXTID++;
public static final int TXT_MESSAGE = TXTID++;
public static final int TXT_SCORE_GAMES = TXTID++;
public static final int TXT_ABOUT = TXTID++;
// Image keys
private static final int OFFSET_IMG = 100;
public static final int IMG_BACKGROUND = 100;
public static final int IMG_AUDIO_ON = 101;
public static final int IMG_AUDIO_OFF = 102;
public static final int IMG_ENABLED = 103;
public static final int IMG_DISABLED = 104;
// Resource (sound) keys
private static final int OFFSET_SND = 200;
public static final int SND_BACKGOUND = 200;
public static final int SND_CONNFAIL = 201;
public static final int SND_WINNER = 202;
public static final int SND_BGMUSIC1 = 203;
public static final int SND_BGMUSIC2 = 204;
public static final int SND_BGMUSIC3 = 205;
// Text data
protected static final char[][] TEXTBUF = {
// Text / page titles /7
"My Maze3D Game".toCharArray(),
"Graphics 3D Properties".toCharArray(),
"SETTINGS".toCharArray(),
"SCORES".toCharArray(),
"DIFFICULTY".toCharArray(),
"TIMELIMIT".toCharArray(),
"BACKGROUND MUSIC SELECT".toCharArray(),
// Text / item labels / 20
"New game".toCharArray(),
"Continue".toCharArray(),
"Graphics 3D Properties".toCharArray(),
"Top view".toCharArray(),
"Settings".toCharArray(),
"About".toCharArray(),
"Quit".toCharArray(),
"Scores".toCharArray(),
"音乐开关".toCharArray(),
"游戏难度".toCharArray(),
"时间限制".toCharArray(),
"背景音乐".toCharArray(),
"简单".toCharArray(),
"一般".toCharArray(),
"困难".toCharArray(),
"疯狂".toCharArray(),
"60秒".toCharArray(),
"120秒".toCharArray(),
"300秒".toCharArray(),
"600秒".toCharArray(),
"不限时".toCharArray(),
"背景音乐1——爵士乐".toCharArray(),
"背景音乐2——一生所爱".toCharArray(),
"背景音乐3——故乡的原风景".toCharArray(),
// Text / commands / 7
"确定".toCharArray(),
"取消".toCharArray(),
"返回".toCharArray(),
"帮助".toCharArray(),
"上一页".toCharArray(),
"退出".toCharArray(),
"刷新".toCharArray(),
// Text / popup related / 6
"YES".toCharArray(),
"NO".toCharArray(),
"CANCEL".toCharArray(),
"OK".toCharArray(),
"GIVE UP".toCharArray(),
"SAVE".toCharArray(),
// Text / helptexts / 10
("重新开始一个新游戏. 这将把上次游戏存档清除掉。").toCharArray(),
("继续上次自动存档游戏。").toCharArray(),
("Show the Graphics 3D properties of the phone").toCharArray(),
("显示迷宫游戏俯视地图,你能在地图中看到自己的位置和迷宫出口位置.").toCharArray(),
("显示游戏分数。您将看到自己的游戏分数排名!").toCharArray(),
("设置你的迷宫游戏难度和时间等级,还有游戏的音乐开关。").toCharArray(),
("<***说*****明***>").toCharArray(),
("Enable or disable audio.").toCharArray(),
("自定义3D迷宫游戏的难度。").toCharArray(),
("自定义3D迷宫的游戏限制时间。").toCharArray(),
("选择游戏背景音乐。").toCharArray(),
// Text / other stuff / 4
"Starting the game...".toCharArray(),
"Message".toCharArray(),
"Games".toCharArray(),
("这是一个简单的3D迷宫手机游戏。它是为支持J2ME3D手机设计的.\n"
+ "需要支持JSR-184(Mobile 3D Graphics API)规范。\n\n"
+ "在游戏中, 您可以按下(开火键)5键,使你前面的墙壁变成半透明;您也可以按下*键打开地图俯瞰模式"
+ "观察你的位置,按任意键将返回游戏中。\n\n" + "作者:余冰星\n\n"
+ "感谢公司指导老师和学校指导老师对我的指导。\n\n" + "June, 2007\n")
.toCharArray() };
protected static final String[] PROPERTIESID = {// 12
"supportAntialiasing", "supportDithering", "supportTrueColor",
"supportMipmapping", "supportPerspectiveCorrection",
"supportLocalCameraLighting", "maxLights", "maxViewportDimension",
"maxTextureDimension", "maxSpriteCropDimension",
"maxTransformsPerVertex", "numTextureUnits" };
protected static final char[][] PROPERTIESBUF = {// 12
("反走样支持(supportAntialiasing)\n\n"
+ "Specifies that antialiasing should be used to increase"
+ " the perceived resolution of the screen. No particular method of "
+ "antialiasing is mandated. However, it is strongly recommended that"
+ " the method be independent of drawing order, and fast enough to operate"
+ " at interactive frame rates. If the chosen method requires post-processing "
+ "per frame, that can be done in releaseTarget.")
.toCharArray(),
("反抖动支持(supportDithering)\n\n"
+ "Specifies that dithering should be used to increase the perceived "
+ "color depth of the screen. No particular method of dithering is mandated."
+ " However, the method should be optimized for animated content "
+ "(as opposed to still images) and be able to operate at interactive frame rates. "
+ "For example, ordered dithering is recommended over error diffusion."
+ " Implementations may choose to do the dithering at rendering time "
+ "(per pixel) or as a post-process (upon releaseTarget).")
.toCharArray(),
("纹理单元真彩支持(supportTrueColor)\n\n"
+ "Specifies that rendering should be done with an internal "
+ "color depth higher than what is supported by the device. For example, on a device "
+ "with an RGB565 display, rendering could be done into an RGBA8 back buffer, "
+ "truncating the pixels to 16 bits only upon releaseTarget. "
+ "True color rendering is especially useful when combined with dithering.")
.toCharArray(),
("管理图像映射支持(supportMipmapping)\n\n"
+ "Mipmap level images are generated automatically by repeated "
+ "filtering of the base level image. No particular method of filtering is mandated, "
+ "but a 2x2 box filter is recommended. It is not possible for the application to "
+ "supply the mipmap level images explicitly.")
.toCharArray(),
("透视图修正支持(supportPerspectiveCorrection)\n\n"
+ "Lighting may operate in either one-sided or two-sided mode. "
+ "In one-sided mode, a single color is computed for each vertex, based on the vertex normal,"
+ " light source parameters, and material parameters. The same color is used in shading "
+ "both the front face and the back face of the polygon."
+ " In two-sided mode, the colors for the back face of a polygon "
+ "are computed separately and with reversed normals (n' = -n)."
+ " Regardless of the lighting mode, the same set of Material "
+ "parameters is used for both sides of the polygon. ")
.toCharArray(),
("本地摄像机灯光支持(supportLocalCameraLighting)\n\n"
+ "There are two choices for polygon shading, smooth and flat. "
+ "Smooth shading means that a color is computed separately for each pixel. This may be done by linear "
+ "interpolation between vertex colors (also known as Gouraud shading), but implementations are also allowed"
+ " to substitute a more accurate model. Flat shading means that the color computed for the third"
+ " vertex of a triangle is used across the whole triangle.")
.toCharArray(),
("最大亮度(maxLights)\n\n" + "The maximum number of concurrent lights.")
.toCharArray(),
("最大视角尺寸(maxViewportDimension)\n\n"
+ "The viewport is the area where the view of the current camera will appear. "
+ "Any parts of the viewport that lie outside the boundaries of the target clipping rectangle are silently clipped off; "
+ "however, this must simply discard the pixels without affecting projection. ")
.toCharArray(),
("最大纹理尺寸(maxTextureDimension)\n\n"
+ "The texture image is stored as a reference to an Image2D. "
+ "The image may be in any of the formats defined in Image2D. The width and height of the image must "
+ "be non-negative powers of two, but they need not be equal. The maximum allowed size for a texture "
+ "image is specific to each implementation, and it can be queried with Graphics3D.getProperties().")
.toCharArray(),
("最大精灵尺寸(maxSpriteCropDimension)\n\n"
+ "Sprite3D is a fast, but functionally restricted alternative to textured geometry."
+ " A Sprite3D is rendered as a screen-aligned rectangular array of pixels with a constant depth. "
+ "The apparent size of a sprite may be specified directly in pixels (an unscaled sprite) or indirectly "
+ "using the transformation from the Sprite3D node to the camera space (a scaled sprite).")
.toCharArray(),
("最大转变顶点(maxTransformsPerVertex)\n\n"
+ "The number of bones that can be associated with a single vertex is unlimited, "
+ "except for the amount of available memory. However, there is an implementation defined limit (N) to the number of bones "
+ "that can actually have an effect on any single vertex. If more than N bones are active on a vertex, the implementation "
+ "is required to select the N bones with highest weights. In case of a tie (multiple bones with equal weights competing for the last slot),"
+ " the selection method is undefined but must be deterministic. The limit N can be queried from getProperties.")
.toCharArray(),
("纹理单位数量\n(numTextureUnits)\n\n" + "").toCharArray() };
public static Hashtable graphics3Dproperties = new Hashtable();
public static void initGraphics3Dproperties() {
System.out.println(PROPERTIESID.length + "," + PROPERTIESBUF.length);
for (int i = 0; i < PROPERTIESID.length; i++)
graphics3Dproperties.put(PROPERTIESID[i], PROPERTIESBUF[i]);
}
/** Image cache */
protected static Hashtable m_images = new Hashtable();
// Image resource names
protected static final String[] IMGNAME_MAP = { "background.png",
"audio_on.png", "audio_off.png", "enabled.png", "blank.png" };
// Resource (audio) names
protected static final String[] RESOURCE_MAP = { "bgmusic1.mid",
"connfail.mid", "winner.mid", "bgmusic1.mid", "bgmusic2.amr",
"bgmusic3.amr" };
/**
* Returns specified resource as stream
*
* @param resourceId
* The id of the resource.
* @return An inputstream to the resource.
*/
public static InputStream getResource(int resourceId) {
resourceId -= OFFSET_SND;
return Resources.class.getResourceAsStream("/"
+ RESOURCE_MAP[resourceId]);
}
/**
* Returns specified text as character array.
*
* @param id
* The id of the text.
* @return A text as char array.
*/
public static char[] getChars(int id) {
return TEXTBUF[id];
}
/**
* Returns specified text as string.
*
* @param id
* The id of the text.
* @return A text as String.
*/
public static String getString(int id) {
return new String(getChars(id));
}
/**
* Returns specified image.
*
* @param id
* The id of the image.
* @return An image.
*/
public static synchronized Image getImage(int id) {
id -= OFFSET_IMG;
Image img = (Image) m_images.get(new Integer(id));
if (img == null) {
try {
img = Image.createImage("/" + IMGNAME_MAP[id]);
m_images.put(new Integer(id), img);
} catch (Exception e) {
System.out.println("Error getting resource img "
+ IMGNAME_MAP[id]);
e.printStackTrace();
}
}
return img;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -