?? mainmenu.java
字號(hào):
//package bushfighting;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Canvas;
import com.nokia.mid.ui.FullCanvas;
public class MainMenu extends FullCanvas implements Runnable {
private int mCanvasWidth, mCanvasHeight;
private int mItemIndex = 0; //當(dāng)前的菜單索引
private int mItemWidth, mItemHeight;
private Image mBufferImage; //用作雙緩沖的圖片
private Graphics mBGraphics;
private Image mBGImage = null; //用作菜單背景
private BushFighting mMIDlet = null;
protected Display mDisplay = null;
public MainCanvas mGameCanvas = null; //游戲的主界面
private NetDataForm mDataForm = null; //用于進(jìn)行數(shù)據(jù)處理和信息顯示
private Score mScore = null;
private DisplayManager mDisplayManager = null;
private boolean mShowMenu = false; //菜單是否彈出的標(biāo)志
private MainMenu menu = this;
private boolean mLoadFinished = false;//是否加載完畢的標(biāo)志
protected Media title = new Media("/sound/title.mid","audio/midi",false);
/* private boolean stopSplash=false;
private int splashX=0;
private int splashY=0;
private int clipY=0;
private int splashStep=1;
private Image textImg=null;//文字介紹圖片
*/
private final int mProgressBar = 80; //進(jìn)度條的長度
private int mCurrentValue = 0; //當(dāng)前的進(jìn)度條位置
private int mState = 1; //用于表示當(dāng)前顯示的是啟動(dòng)畫面還是菜單畫面,0,表示啟動(dòng),1表示菜單
private static final String[] mMenuItems = {"開始游戲","游戲幫助","音樂 ","關(guān)于游戲","退出游戲"};
public final String STR_ABOUT = "開發(fā)商:& 廣州奧創(chuàng)信息技術(shù)有&限公司。&開發(fā)商:&北京颯美&網(wǎng)絡(luò)有限公司。&如果您有什么建議的話&請(qǐng)致電& 010-58695258&或Email:& service@sammy-net.com.cn& &非常感謝您的使用。";
public final String STR_PRODUCTINFO = "游戲名稱:&三國志-黃忠霸業(yè)&版本號(hào):1.0.0&程序大小:80K&占用內(nèi)存:160K&資費(fèi):7元/次下載&發(fā)行商:廣州奧創(chuàng)&信息技術(shù)有限&公司開發(fā)商:&北京颯美網(wǎng)絡(luò)有限公司&如果有什么建議&請(qǐng)致電:&010-58695258-322& 郵箱:&service@sammy-net.com.cn & 非常感謝您的使用";
private final String STR_HELPINFO = "在亂世的三國世界里&"+
"董卓挾天子以令諸侯&"+
"黃巾勢(shì)力獨(dú)霸一方&"+
"在這混沌的世界里&"+
"流傳著一本野史&"+
"記載著黃忠的英雄事跡&"+
"平亂黃巾賊&"+
"三英戰(zhàn)呂布&"+
"長板橋之役&"+
"火燒連環(huán)船&"+
"輔助劉備入駐西蜀&"+
"玩家需要操作黃忠&"+
"重新演繹這段野史&"+
"成就霸業(yè)!&"+
"導(dǎo)航鍵上/數(shù)字鍵2:&"+
" 操作角色向上移動(dòng) &"+
"導(dǎo)航鍵下/數(shù)字鍵8:&"+
" 操作角色向下移動(dòng) &"+
"導(dǎo)航鍵左/數(shù)字鍵4:&"+
" 操作角色向左移動(dòng) &"+
"導(dǎo)航鍵右/數(shù)字鍵6:&"+
" 操作角色向右移動(dòng) &"+
"導(dǎo)航鍵中/數(shù)字鍵5:&"+
" 發(fā)射弓箭";
public MainMenu(BushFighting midlet, Display display) {
mMIDlet = midlet;
mDisplay = display;
mCanvasWidth = getWidth();
mCanvasHeight = getHeight();
mBufferImage = Image.createImage(mCanvasWidth, mCanvasHeight);
mBGraphics = mBufferImage.getGraphics();
mDisplayManager = new DisplayManager(mDisplay, this);
try {
mBGImage = HF.loadImage("mlogo2.png");
mBGraphics.drawImage(mBGImage, 0, 0, Graphics.LEFT | Graphics.TOP); //先將
//mBGImage = HF.loadImage("mlogo2.png");
} catch (Exception e) {
System.out.println("error loading the logo");
}
}
//初始化數(shù)據(jù)數(shù)據(jù)
public void initGame() {
//使用一個(gè)內(nèi)嵌的線程去加載
//Thread thread = new Thread()
//{
//public void run()
//{
mScore = new Score();
mDataForm = new NetDataForm(mDisplayManager, mScore, mBufferImage);
mGameCanvas = new MainCanvas(menu, mDataForm, mScore, mBufferImage);
mGameCanvas.init();
mGameCanvas.setDisplayManager(mDisplayManager);
mLoadFinished = true;
//}
//};
//thread.start();
}
//顯示啟動(dòng)畫面
public void showSplashWindow() {
mState = 2; //顯示啟動(dòng)畫面
Thread thread = new Thread(this);
thread.start();
}
//繪制啟動(dòng)畫面
private void drawSplashWindow(Graphics g) {
clearScreen(mBGraphics,0);
/* mBGraphics.setClip(0,mCanvasHeight/2-clipY,mCanvasWidth,clipY<<1);
clipY+=splashStep;
mBGraphics.drawImage(mBGImage, splashY>=0?0:splashY,mCanvasHeight>>1, Graphics.VCENTER | Graphics.LEFT);
mBGraphics.setClip(0,mCanvasHeight+mBGImage.getHeight()>>1,mCanvasWidth,mCanvasHeight);
mBGraphics.drawImage(textImg,0,splashX,Graphics.LEFT|Graphics.TOP);
mBGraphics.setClip(0,0,mCanvasWidth,mCanvasHeight);
*/
mBGraphics.setColor(HF.COLOR_WHITE);
int x = (mCanvasWidth - mProgressBar) / 2;
int y = 150;
mBGraphics.fillRect(x, y, mProgressBar, 10);
mBGraphics.setColor(HF.COLOR_BLUE);
mBGraphics.fillRect(x, y, mCurrentValue, 10);
g.drawImage(mBufferImage, 0, 0, Graphics.LEFT | Graphics.TOP);
}
//用于處理顯示啟動(dòng)畫面
public void run() {
System.out.println("線程運(yùn)行");
int step = 8;
// try {
if (mState == 2) {
repaint(0, 0, mCanvasWidth, mCanvasHeight);
System.gc();
try{
Thread.sleep(1000);
}catch(Exception e){}
//轉(zhuǎn)去顯示公司的logo,并且加載游戲啟動(dòng)完畢后的logo
try{
mBGraphics.drawImage(mBGImage, 0, 0, Graphics.LEFT | Graphics.TOP); //先將
//mBGImage = HF.loadImage("logo.png");
mBGImage=HF.loadImage("splash.png");
//textImg=HF.loadImage("text.png");
} catch(Exception e){
}
//mState = 0;
}
if(mState == 2){
System.out.println("循環(huán)中前");
repaint(0,0,mCanvasWidth,mCanvasHeight);
System.gc();
try{
Thread.sleep(500);
}catch(Exception e){}
//stopSplash=false;
//splashX=mCanvasHeight+textImg.getHeight();
//splashY=10;
//clipY=0;
//HF.title.load();
mState = 0;
//mLoadFinished=false;
}
while (mLoadFinished== false/*||!stopSplash&&(splashX+textImg.getHeight())>(mCanvasHeight/2)*/ ||mCurrentValue < mProgressBar) {
//System.out.println("循環(huán)中"+(splashX+textImg.getHeight()));
/*splashX-=splashStep;
if(splashY+mBGImage.getWidth()>mCanvasWidth)
splashY--;
mCurrentValue += step;
*/
if (mCurrentValue >= mProgressBar)
mCurrentValue = mProgressBar - 2;
if (mLoadFinished == true)
mCurrentValue = mProgressBar;
repaint(0, 0, mCanvasWidth, mCanvasHeight);
try{
Thread.sleep(50);
}catch(Exception e){}
}
// }
// catch (Exception e) {
// }
try{
//textImg=null;
mBGImage=HF.loadImage("logo.png");
System.gc();
}catch(Exception e){}
mState = 1; //切換為顯示菜單畫面
//HF.title.play();
repaint(0, 0, mCanvasWidth, mCanvasHeight);
if(HF.sound)
title.play();
}
//執(zhí)行繪制菜單的工作
public void paint(Graphics g) {
if (mState == 2) {
g.drawImage(mBufferImage, 0, 0, Graphics.LEFT | Graphics.TOP);
} else if (mState == 0) {
drawSplashWindow(g);
} else {
clearScreen(mBGraphics, HF.COLOR_LIGHTBLUE);
mBGraphics.drawImage(mBGImage, 0, 0, Graphics.LEFT | Graphics.TOP);
mBGraphics.setFont(HF.SMALL_FONT);
drawMenu(mBGraphics);
g.drawImage(mBufferImage, 0, 0, Graphics.LEFT | Graphics.TOP);
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -