📄 xgame.java
字号:
if(menu.selectedItem<menu.itemsNum-1){
//drawObject(g,OBJECT_MENU_IMG,3,1,width/2,menu.yPos+menu.SHOW_ITEMS*(fontHeight+1));//down arrow
}
if(bSavedSuccessful){
g.setClip(0,0,width,height);
rectWidth=width/2;
rectX=width/2-rectWidth/2;
rectHeight=height/2;
rectY=height/2-rectHeight/2;
drawMenuBackGround(g);
g.setColor(0,102,157);
String strTmp="@TXT_GAME_SAVED@";
g.drawString(strTmp,width/2-font.stringWidth(strTmp)/2,height/2-fontHeight/2,Graphics.TOP|Graphics.LEFT);
}
}
// protected void drawMenuBackground(Graphics g) {
// g.drawImage(imgTitleBg,0,0,Graphics.TOP|Graphics.LEFT);//Graphics.VCENTER|Graphics.HCENTER);
//
// //g.setColor(0x000000);
// //g.fillRect(0, 0, width, height);
// }
protected void inputMenu() {
if(!bSavedSuccessful){
switch (inputPressed) {
case INPUT_UP:
menuUp();
break;
case INPUT_DOWN:
menuDown();
break;
case INPUT_OK:
case INPUT_FIRE:
actionMenu();
break;
case INPUT_CANCEL:
if (state == STATE_MENU_HELP) {
setState(STATE_MENU_MAIN);
}
break;
}
}
else if(counter>3){
bSavedSuccessful=false;
setState(STATE_MENU_MAIN);
}
repaint = true;
}
private void menuUp() {
menu.moveUp();
}
private void menuDown() {
menu.moveDown();
}
private final static int MENU_ITEM_NEW_GAME=0;
// #if(${ant.handset_sound}=="none")
// @private final static int MENU_ITEM_HELP=1;
// @private final static int MENU_ITEM_SCORE=2;
// @private final static int MENU_ITEM_EXIT=3;
// #else
private final static int MENU_ITEM_OPTION=1;
private final static int MENU_ITEM_HELP=2;
private final static int MENU_ITEM_SCORE=3;
private final static int MENU_ITEM_EXIT=4;
// #end
private static boolean bSavedSuccessful;
protected void actionMenu() {
if(menuType==0){//main menu
switch (menu.selectedItem) {
case MENU_ITEM_NEW_GAME://start:
//setState(STATE_GAME_SELECT_MERMAID);
bCanContinueGame=false;
return;
// #if(${ant.handset_sound}!="none")
case MENU_ITEM_OPTION:
setState(STATE_MENU_OPTION);
break;
// #end
case MENU_ITEM_HELP:
setState(STATE_MENU_HELP);
return;
case MENU_ITEM_SCORE:
scoreType=-1;
setState(STATE_MENU_SCORE);
return;
case MENU_ITEM_EXIT:
bCanContinueGame=false;
saveRecord();
setState(STATE_LOGO_GAME_EXIT);
return;
}
}
else if(menuType==1){// pause menu
switch (menu.selectedItem) {
case 0://resume game
resumeGame();
setState(STATE_GAME_START);
return;
case 1://save game
bCanContinueGame=true;
saveRecord();
bSavedSuccessful=true;
bLoaded=true;
counter=0;
return;
case MENU_ITEM_NEW_GAME+2://start:
bCanContinueGame=false;
return;
// #if(${ant.handset_sound}!="none")
case MENU_ITEM_OPTION+2:
setState(STATE_MENU_OPTION);
return;
// #end
case MENU_ITEM_HELP+2:
setState(STATE_MENU_HELP);
return;
case MENU_ITEM_SCORE+2:
scoreType=-1;
setState(STATE_MENU_SCORE);
return;
case MENU_ITEM_EXIT+2:
bCanContinueGame=false;
saveRecord();
setState(STATE_LOGO_GAME_EXIT);
return;
}
}
else if(menuType==2){// can continue menu
switch (menu.selectedItem) {
case 0://continue game
//if(!bCanContinueGame){
loadRecord();
//}
startLevel();
setState(STATE_GAME_START);
return;
case MENU_ITEM_NEW_GAME+1://start:
//setState(STATE_MENU_START);
bCanContinueGame=false;
return;
// #if(${ant.handset_sound}!="none")
case MENU_ITEM_OPTION+1:
setState(STATE_MENU_OPTION);
return;
// #end
case MENU_ITEM_HELP+1:
setState(STATE_MENU_HELP);
return;
case MENU_ITEM_SCORE+1:
scoreType=-1;
setState(STATE_MENU_SCORE);
return;
case MENU_ITEM_EXIT+1:
bCanContinueGame=false;
saveRecord();
setState(STATE_LOGO_GAME_EXIT);
return;
}
}
}
/*
* game :
*/
private static boolean bSoundOn=true;
private static boolean gamePause;
public static int gameLevel;
private static int gameScore;
private static int levelScore;
private static int levelsPassed;//how many level has completed. get from RMS
private boolean bCanContinueGame;
protected void enterGame(){
setSoftkey(SOFTKEY_MENU,SOFTKEY_PAUSE);
gamePause=false;
// #if(${ant.handset_sound}!="none")
if(bSoundOn&&!gamePause){
playLoop(musicPlayer);
}
else{
stopLoop();
}
// #end
}
protected void nextLevel(){
//if(gameLevel<7){
gameLevel++;
//}
levelScore=0;
initGame();
}
protected void startLevel(){
if(!bCanContinueGame){
gameScore=0;
levelScore=0;
}
initGame();
}
protected void resumeGame(){
}
protected void initGame() {
unloadImage();
}
protected void leaveGame() {
// #if(${ant.handset_sound}!="none")
showInfo("leaveGame:");
stopLoop();
// #end
}
protected void gamePause(){
gamePause=true;
}
protected void gameResume(){
gamePause=false;
}
protected void logicGame() {
repaint=true;
if(gamePause){
return;
}
}
protected void paintGame(Graphics g){
//drawMenuBackground(g);
g.setColor(0,0,0);
g.fillRect(0,0,width,height);
//g.drawString("game start:",10,10,Graphics.TOP|Graphics.LEFT);
//drawObject(g, OBJECT_GAME_BG, 0, 0, 0, 0);
}
protected void inputGame(){
if ((inputHolding == INPUT_LEFT)
|| (inputHolding == INPUT_RIGHT)
|| (inputHolding == INPUT_DOWN)
|| (inputHolding == INPUT_UP)) {
inputPressed = inputHolding;
}
//showInfo("inputPressed:"+inputKeyCode);
//just for test
// if(inputKeyCode==KEY_NUM1){
// setState(STATE_GAME_LEVEL_SUCCESS);
// }
switch (inputPressed) {
case INPUT_FIRE:
break;
case INPUT_RIGHT:
if(gamePause){
return;
}
break;
case INPUT_LEFT:
if(gamePause){
return;
}
break;
case INPUT_DOWN:
if(gamePause){
return;
}
break;
case INPUT_UP:
if(gamePause){
return;
}
break;
case INPUT_OK://go to main menu
menuType=1;//pause menu;
gamePause=true;
setState(STATE_MENU_MAIN);
// #if(${ant.handset_sound}!="none")
stopLoop();
// #end
break;
case INPUT_CANCEL:
gamePause=!gamePause;
// #if(${ant.handset_sound}!="none")
if(bSoundOn&&!gamePause){
playLoop(musicPlayer);
}
else{
stopLoop();
}
// #end
break;
}
}
//***********************
//help
//************************
//private static int X_BEGIN_HELP=
private static int curLine=0;
private String strHelp[];
private static int maxLine;//=10;
private static int ONE_LINE_MAX_WIDTH;//=width-2*(beginPosX+6);
private final static int ARROW_HEIGHT=8;
private void enterMenuHelp(){
rectWidth=width-20;
rectX=width/2-rectWidth/2;
rectHeight=height-25;
rectY=height/2-rectHeight/2;
ONE_LINE_MAX_WIDTH=rectWidth-12;
if(strHelp==null){
// #if(${ant.handset_is_pda})
// @String tmp=new String("@TEXT_HELP_FOR_PDA@");
// #else
String tmp=new String("@TEXT_HELP@");
// #end
maxLine=(rectHeight-2*ARROW_HEIGHT)/fontHeight;
strHelp=gtkBreakString(tmp,ONE_LINE_MAX_WIDTH);
tmp=null;
}
setSoftkey(SOFTKEY_NONE,SOFTKEY_BACK);
}
private void inputMenuHelp(){
//showInfo("inputPressed:"+inputPressed+" curLine;" +curLine);
switch (inputPressed) {
case INPUT_UP:
if(curLine>0){
curLine--;
}
break;
case INPUT_DOWN:
if(curLine<strHelp.length-maxLine){
curLine++;
}
break;
case INPUT_OK:
case INPUT_FIRE:
break;
case INPUT_CANCEL:
if (state == STATE_MENU_HELP) {
setState(STATE_MENU_MAIN);
}
break;
}
repaint=true;
}
// private void logicMenuHelp(){
//
// }
private void paintMenuHelp(Graphics g){
drawMenuBackGround(g);
g.setColor(0,102,157);
int beginPosY=rectY+fontHeight;
for( int i=0;i<maxLine;i++){
if(curLine+i>=strHelp.length){
break;
}
g.drawString(strHelp[curLine+i],rectX+3,beginPosY+i*fontHeight,Graphics.TOP|Graphics.LEFT);
}
//draw arrow
if(curLine>0){
//drawObject(g,OBJECT_MENU_IMG,3,0,width/2,rectY+rectHeight-ARROW_HEIGHT);//up arrow
}
if(curLine<strHelp.length-maxLine){
//drawObject(g,OBJECT_MENU_IMG,3,1,width/2,rectY+rectHeight-ARROW_HEIGHT);//down arrow
}
}
//************************
//score
//***********************
private static int scoreType=-1;
public static int highScore[]= {
1000,
920,
830,
500,
10,
};
private static int isHighScore(int score){
int pos=-1;
int len=highScore.length;
//GMain.pInfo("score:"+score);
if(score>highScore[len-1]){
highScore[len-1]=score;
//pop sort
pos=len-1;
for(int i=len-1;i>0;i--){
//GMain.pInfo("score:"+score+" highScore[i-1]:"+highScore[i-1]);
if(score>highScore[i-1]){
highScore[i]=highScore[i-1];
highScore[i-1]=score;
pos=i-1;
}
else{
break;
}
}
}
//GMain.pInfo("pos:"+pos);
return pos;
}
private void enterMenuScore(){
unloadImage();
//loadObject(OBJECT_MENU_IMG);
loadImage();
setSoftkey(SOFTKEY_NONE,SOFTKEY_BACK);
rectWidth=width-20;
rectX=width/2-rectWidth/2;
rectHeight=height-25;
rectY=height/2-rectHeight/2;
ONE_LINE_MAX_WIDTH=rectWidth-12;
// if(strHelp==null){
//
// String tmp=new String("@TEXT_HELP@");
// maxLine=(rectHeight-2*ARROW_HEIGHT)/fontHeight;
// strHelp=gtkBreakString(tmp,ONE_LINE_MAX_WIDTH);
// tmp=null;
//
// }
}
private void inputMenmuScore(){
switch (inputPressed) {
case INPUT_UP:
break;
case INPUT_DOWN:
break;
case INPUT_OK:
case INPUT_FIRE:
break;
case INPUT_CANCEL:
setState(STATE_MENU_MAIN);
break;
}
repaint=true;
}
// private void logicMenmuScore(){
//
// }
private void paintMenmuScore(Graphics g){
drawMenuBackGround(g);
String strTmp2="12:";
int len=highScore.length;
int posX2=width/4;//-GMain.font.stringWidth(strTmp2);
int posX3;//=GMain.SCR_WIDTH/2+2;
int beginPosY=height/2-len*fontHeight/2;
for(int i=0;i<len;i++){
g.setColor(0,0,0);
if(scoreType>=0){
if(i==scoreType){
g.setColor(255,255,0);
// //g.setClip(posX2,beginPosY+i*GMain.fontHeight,GMain.SCR_WIDTH*3/4-posX2,GMain.fontHeight);
// g.fillRect(posX2,beginPosY+i*fontHeight,width*3/4-posX2+font.stringWidth(strTmp2),fontHeight);
}
}
int seq=i+1;
strTmp2=""+seq+":";
g.drawString(strTmp2,posX2,beginPosY+i*fontHeight,Graphics.TOP|Graphics.LEFT);
strTmp2=""+highScore[i];
//showInfo(strTmp2);
posX3=width*3/4-font.stringWidth(strTmp2)/2;
g.drawString(strTmp2,posX3,beginPosY+i*fontHeight,Graphics.TOP|Graphics.LEFT);
//showInfo("i:"+i+" strTmp2:"+strTmp2+" beginPosY: "+ beginPosY);
}
}
private void exit(){
destroy();
}
//*********************
//Option
//*********************
private void enterMenuOption(){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -