📄 mainmenu.java
字号:
}
//g.setColor(0xff0000);
//g.setFont(HF.SMALL_FONT);
//g.drawString("试玩版",10,10,Graphics.LEFT|Graphics.TOP);
if(bExit) {
exitGame();
}
}
//绘制菜单
public void drawMenu(Graphics g) {
g.setFont(HF.MEDIUM_FONT);
g.setColor(0xff0000);
if(mItemIndex == 2)
g.drawString(mMenuItems[mItemIndex]+(HF.sound?" 开":" 关"),86,164,Graphics.HCENTER|Graphics.BOTTOM);
else
g.drawString(mMenuItems[mItemIndex],86,164,Graphics.HCENTER|Graphics.BOTTOM);
}
public static void drawMenuList(Graphics g, String menuList, int borderColor, int highLightColor,
int screenWidth, int screenHeight, int curIndex) {
if (menuList == null)
return;
int fontHeight = g.getFont().getHeight();
int itemCount = 0;
int pos1 = 0, pos2 = 0;
while ( (pos1 = menuList.indexOf("&", pos2)) != -1) { //计算要绘制的菜单项个数
itemCount++;
pos2 = pos1 + 1;
}
int itemWidth = 2 * screenWidth / 3 + 5; //每个菜单项的宽度
int itemHeight = fontHeight + 1; //高度
int listHeight = (itemCount) * itemHeight; //要绘制的菜单列表的高度
int x = 0;
int y = screenHeight - listHeight - fontHeight - 4;
drawFrame(g, borderColor, x, y, itemWidth, listHeight + 1); //绘制菜单的外框
drawFrame(g, HF.COLOR_BLACK, x + 2, y + 2, itemWidth, listHeight);
drawFrame(g, HF.COLOR_WHITE, x + 3, y + 3, itemWidth - 1, listHeight - 1);
x = x + 6;
y = y + 4;
pos1 = pos2 = 0;
int index = 0;
while ( (pos1 = menuList.indexOf("&", pos2)) != -1) {
if (index == curIndex) {
drawFrame(g, highLightColor, x - 3, y - 2, itemWidth, itemHeight);
g.setColor(HF.COLOR_RED);
g.fillRoundRect(x + 1, y - 1, itemHeight - 2, itemHeight - 2, 4, 4);
g.setColor(HF.COLOR_YELLOW);
} else
g.setColor(HF.COLOR_BLACK);
g.drawSubstring(menuList, pos2, pos1 - pos2, x + 25, y, Graphics.LEFT | Graphics.TOP);
index++;
y = y + itemHeight;
pos2 = pos1 + 1;
}
}
//处理按键事件
public void keyPressed(int keyCode) {
if(bExit)
return;
if (mState ==2) return; //屏蔽还没有进入游戏时的按键
if (keyCode == -6) { //左手边的选择键
System.out.println(""+mState);
if(mState==0) {
//stopSplash=true;
return;
}
/* if (mShowMenu == false) { //显示菜单
mShowMenu = true;
repaint(0, 0, mCanvasWidth, mCanvasHeight);
}
else*/
{
itemSelected(mItemIndex); //进入游戏
}
return;
} else if (keyCode == -7) { //右上角的选择键
return;
}
int action = getGameAction(keyCode);
switch (action) {
case DOWN:
mItemIndex = (mItemIndex + 1) % 5;
repaint(0, 0, mCanvasWidth, mCanvasHeight);
break;
case UP:
mItemIndex = (mItemIndex + 4) % 5;
repaint(0, 0, mCanvasWidth, mCanvasHeight);
break;
case FIRE:
itemSelected(mItemIndex); //处理相应的选项
break;
}
}
//绘制方框
public static void drawFrame(Graphics g, int bgColor, int x, int y, int width, int height) {
g.setColor(bgColor);
g.fillRect(x, y, width, height);
}
//使用指定的颜色清屏
public void clearScreen(Graphics g, int bgColor) {
g.setColor(bgColor);
g.fillRect(0, 0, mCanvasWidth, mCanvasHeight);
}
//处理菜单项的选择
public void itemSelected(int index) {
switch (index) {
case 0:
startGame();
break;
case 1:
showHelpInfo();
break;
case 2:
HF.sound = !HF.sound;
if(!HF.sound) {
title.stop();
} else {
title.play();
}
repaint(0, 0, mCanvasWidth, mCanvasHeight);
break;
case 3:
showAbout();
break;
case 4:
bExit = true;
repaint(0, 0, mCanvasWidth, mCanvasHeight);
//exitGame();
break;
}
}
boolean bIsGame = false;
boolean bExit = false;
//启动游戏
protected void startGame() {
bIsGame = true;
title.stop();
mGameCanvas.start();
mDisplay.setCurrent(mGameCanvas);
}
//显示排行榜
public void showRolls() {
mDataForm.showLocalRolls();
mDisplay.setCurrent(mDataForm);
}
//显示产品信息
protected void showProductInfo() {
mDataForm.setState(NetDataForm.STATE_MSGDISPLAY);
mDataForm.set("关于游戏", STR_PRODUCTINFO);
mDisplay.setCurrent(mDataForm);
}
//显示关于我们
protected void showAbout() {
mDataForm.setState(NetDataForm.STATE_MSGDISPLAY);
mDataForm.set("关于我们", STR_ABOUT);
mDisplay.setCurrent(mDataForm);
}
//显示游戏规则
protected void showHelpInfo() {
mDataForm.setState(NetDataForm.STATE_MSGDISPLAY);
mDataForm.set("游戏帮助", STR_HELPINFO); //"左键或者4键向左移动&右键或者6键向右移动&向上键或2键跳起");
mDisplay.setCurrent(mDataForm);
}
public void release() {
if (mGameCanvas != null)
mGameCanvas.release();
}
//退出游戏
protected void exitGame() {
mMIDlet.quitApp();
}
protected void resume() {
if(bIsGame) {
mGameCanvas.resume();
return;
}
if(bPause ) {
bPause = false;
}
}
boolean bPause = false;
protected void pause() {
if(bIsGame) {
mGameCanvas.pause();
return;
}
if(!bPause ) {
bPause = true;
if(HF.sound) {
title.stop();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -