import java.io.*;
import java.util.*;
import com.nokia.mid.ui.*;
import javax.microedition.lcdui.*;
import javax.microedition.rms.*;
import com.nokia.mid.sound.Sound;
public class MScreen extends FullCanvas {
protected final int N3650 = 1;
protected final int N7650 = 0;
protected final int platform
= ("nokia3650".equals(System.getProperty("microedition.platform").toLowerCase()))?N3650:N7650;
//****************************************************************************
//角色左右方向
//****************************************************************************
private final int DIRECT_LEFT = -1;
private final int DIRECT_RIGH = 1;
private final int DIRECT_OVER = 2;
private final int DIRECT_DOWN = 3;
private final int DIRECT_LEFTOVER = 4;
private final int DIRECT_LEFTDOWN = 5;
private final int DIRECT_RIGHOVER = 6;
private final int DIRECT_RIGHDOWN = 7;
//****************************************************************************
//资源索引
//****************************************************************************
private final int FACE_MENUCOVER = 0;
private final int FACE_MENUTITLE = 1; //主菜单中央标题文字
private final int FACE_COPYRIGHT = 2; //主菜单底部版权信息
private final int FACE_MENUITEMS = 3; //菜单项的图形
private final int FACE_MENUPOINT = 4; //菜单页的菜单指针 弹头形状
private final int FACE_MISSION_OPT = 5;
private final int FACE_FONT_LITTLE = 6;//数字字体-最小
private final int FACE_FONT_MIDDLE = 7;//数字字体-中等大小
private final int FACE_FONT_GREATE = 8;//数字字体-最大
private final int FACE_GAME_OVER = 9; //游戏任务失败的画面
private final int FACE_GAMESTART = 10; //游戏开始和结束文字
private final int FACE_ANIMASLOT = 11; //主角的血槽图形
private final int FACE_HEROBEING = 12; //表示主角生命个数图形
private final int FACE_ARMS_BOMB = 13; //子弹数和炸弹数文字
private final int FACE_INFINITUD = 14; //子弹无限的符号
private final int FACE_PROP_ICON = 15; //道具图标图形
private final int FACE_BIGCANNON = 16; //飞机坦克用的炮管
private final int FACE_ZIZOU_GUN = 17; //自走炮的图形
//****************************************************************************
/** @todo:构造函数 */
//****************************************************************************
public MScreen() {
face_load();
sound_load();
screen_index = SCREEN_RESSLOAD;
}
//****************************************************************************
/** @todo: 框架代码 */
//****************************************************************************
private int screen_index = 0;
private boolean process_lock = false;
private final int SCREEN_MAINMENU = 0; //主菜单页面
private final int SCREEN_GAMEBODY = 1; //游戏页面
private final int SCREEN_HELPINFO = 2; //帮助页面
private final int SCREEN_COPYRIGH = 3; //版权信息
private final int SCREEN_GAMEOVER = 4; //游戏结束
private final int SCREEN_HIGHLIST = 5; //排行榜
private final int SCREEN_SELEGATE = 6; //选择关卡
private final int SCREEN_RESSLOAD = 7; //资源装载页面
/**********************************************
*
**********************************************/
protected final void process_set(int index){
process_lock = true;
switch(screen_index){
case SCREEN_GAMEBODY: gamebody_free(); break;
// case SCREEN_MAINMENU: mainmenu_free(); break;
// case SCREEN_HELPINFO: helpinfo_free(); break;
// case SCREEN_COPYRIGH: copyrigh_free(); break;
// case SCREEN_GAMEOVER: gameover_free(); break;
// case SCREEN_HIGHLIST: highlist_free(); break;
// case SCREEN_RESSLOAD: ressload_free(); break;
// case SCREEN_SELEGATE: selegate_free(); break;
}
screen_index = index;
switch(index){
case SCREEN_GAMEBODY: gamebody_init(); break;
case SCREEN_MAINMENU: mainmenu_init(); break;
case SCREEN_HELPINFO: helpinfo_init(); break;
case SCREEN_COPYRIGH: copyrigh_init(); break;
case SCREEN_HIGHLIST: highlist_init(); break;
case SCREEN_SELEGATE: selegate_init(); break;
// case SCREEN_GAMEOVER: gameover_init(); break;
// case SCREEN_RESSLOAD: ressload_init(); break;
}
process_lock = false;
}
/**********************************************
* 状态处理
**********************************************/
public final void process_tick() {
if(process_lock) return;
switch(screen_index){
case SCREEN_GAMEBODY: gamebody_run(); break;
case SCREEN_MAINMENU: mainmenu_run(); break;
case SCREEN_HELPINFO: helpinfo_run(); break;
case SCREEN_COPYRIGH: copyrigh_run(); break;
case SCREEN_GAMEOVER: gameover_run(); break;
case SCREEN_HIGHLIST: highlist_run(); break;
case SCREEN_RESSLOAD: ressload_exec(); break;
case SCREEN_SELEGATE: selegate_run(); break;
}
}
/**********************************************
* 按键处理
**********************************************/
protected final void process_key(int keycode){
if(process_lock) return;
switch(screen_index){
case SCREEN_GAMEBODY: gamebody_key(keycode); break;
case SCREEN_MAINMENU: mainmenu_key(keycode); break;
case SCREEN_HELPINFO: helpinfo_key(keycode); break;
case SCREEN_COPYRIGH: copyrigh_key(keycode); break;
case SCREEN_GAMEOVER: gameover_key(keycode); break;
case SCREEN_HIGHLIST: highlist_key(keycode); break;
case SCREEN_SELEGATE: selegate_key(keycode); break;
// case SCREEN_RESSLOAD: ressload_key(keycode); break;
}
}
/**********************************************
* 画
**********************************************/
protected void process_draw() {
if(process_lock) return;
switch(screen_index){
case SCREEN_MAINMENU: mainmenu_draw(); break;
case SCREEN_HELPINFO: helpinfo_draw(); break;
case SCREEN_COPYRIGH: copyrigh_draw(); break;
case SCREEN_GAMEBODY: gamebody_draw(); break;
case SCREEN_GAMEOVER: gameover_draw(); break;
case SCREEN_HIGHLIST: highlist_draw(); break;
case SCREEN_RESSLOAD: ressload_draw(); break;
case SCREEN_SELEGATE: selegate_draw(); break;
}
}
//****************************************************************************
/** @todo: 主要菜单 */
//****************************************************************************
private int mainmenu_index = 0; //菜单选择索引
private int mainmenu_total = 6;
private final int MAINMENU_STARGAME = 0; //开始新游戏
private final int MAINMENU_CONTINUE = 1; //继续游戏
private final int MAINMENU_HELPINFO = 2; //帮助信息
private final int MAINMENU_COPYRIGH = 3; //版权信息
private final int MAINMENU_HIGHLIST = 4; //高分榜
private final int MAINMENU_EXITGAME = 5; //退出游戏
private final void mainmenu_init(){
mainmenu_index = 0;
}
private final void mainmenu_execute(int index){
switch(index){
case MAINMENU_STARGAME: process_set(SCREEN_GAMEBODY); break;
case MAINMENU_CONTINUE: process_set(SCREEN_SELEGATE); break;
case MAINMENU_HELPINFO: process_set(SCREEN_HELPINFO); break;
case MAINMENU_COPYRIGH: process_set(SCREEN_COPYRIGH); break;
case MAINMENU_HIGHLIST: process_set(SCREEN_HIGHLIST); break;
case MAINMENU_EXITGAME: exitapp(); break;
}
}
private final void mainmenu_run(){
refresh();
}
private final void mainmenu_key(int keycode){
switch(keycode){
case KEY_DOWN:
if (mainmenu_index < mainmenu_total - 1) mainmenu_index++;
refresh();
break;
case KEY_OVER:
if (mainmenu_index > 0) mainmenu_index--;
refresh();
break;
case KEY_FIRE:
case KEY_SOFT1:
mainmenu_execute(mainmenu_index);
break;
}
}
评论0