📄 dragonsoul.java
字号:
import com.nokia.mid.sound.Sound;
import com.nokia.mid.ui.DeviceControl;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import javax.microedition.rms.*;
import java.io.InputStream;
import java.io.ByteArrayOutputStream;
public class DragonSoul extends MIDlet
// implements CommandListener
{
public static DragonSoul inc;
//菜单设定
public byte setting[];
public GameCanvas GC;
//游戏战斗模式
private int j;
private Sound ota_sound;
//角色生命次数
private int n;
private MenuCanvas M;
private SelectPlayer S;
private HelpAboutCanvas o;
// public Image _fldif;
// public Image _fldchar;
//拳头
public Image fistImage;
//菜单背景图
public Image menuBk;
//无穷大标记
public Image m;
//游戏角色血量
public static final int eNum[] = {
100, 100, 85, 85, 80, 80, 125, 125
};
public static final String name[] = {
"陈龙", "权向珍", "冯", "迪奥", "简方", "克拉克", "山川", "巴多夫"
};
public boolean bGameHelp = false;
/*
* 游戏入口类构造函数
*/
public DragonSoul()
{
setting = new byte[6];
inc = this;
try {
//ota_sound = new Sound(saveIndex("024A3A55CDD185C9D00400691CCAEA2F02902F033036C36C36C3702F03302902F0497814817819817614614617817812428BC0A40BC0CC0DB0DB0DB0DC0BC0CB0A40BC125E05205E06605D85184604A0460460450000"), 1);
// _fldif = Image.createImage("/menu_button.png"); //right button
// _fldchar = Image.createImage("/menu_button_m.png"); //left button
fistImage = Image.createImage("/cursur.png"); //logo
menuBk = Image.createImage("/menu_bg.png"); //backgroud
m = Image.createImage("/infinity.png");
} catch(Exception exception) {
// exception.printStackTrace();
// System.out.println("Sound Error");
}
loadSetting();
// System.gc();
}
/**
* 将十六进制字符串转化为字节流
* @param s String,声音字符串
* @return abyte0 byte[],转化后的声音字节流
*/
public static final byte[] setStingToByte(String s)
{
byte abyte0[] = new byte[s.length() / 2];
for(int i1 = 0; i1 < abyte0.length; i1++) {
String s1 = s.substring(i1 * 2, i1 * 2 + 2);
int j1;
try {
j1 = Integer.parseInt(s1, 16);
} catch(Exception exception) {
j1 = 0;
}
abyte0[i1] = (byte)j1;
}
return abyte0;
}
/**
* 声音设定
* @param name String,声音文件名
* @param type int,声音播放类型
* @return tmpSnd Sound,设定后的声音
*/
public Sound setSound(String name, int type) {
Sound tmpSnd = null;
try {
InputStream is = getClass().getResourceAsStream(name);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte tmpbyte[] = new byte[1024];
for (int i = -1; (i = is.read(tmpbyte)) != -1; ) {
bos.write(tmpbyte, 0, i);
}
is.close();
tmpSnd = new Sound(bos.toByteArray(), type);
} catch (Exception ex) {
ex.printStackTrace();
}
return tmpSnd;
}
/*
* 控制标题声音的播放和停止
*/
public void titleSound() {
if(setting[0] == 1) {
if (ota_sound.getState() != Sound.SOUND_PLAYING) {
try {
ota_sound.play(1);
} catch(Exception exception) { }
}
} else {
if (ota_sound.getState() == Sound.SOUND_PLAYING) {
try {
ota_sound.stop();
} catch(Exception exception) {}
}
}
}
// public void stopSound() {
// if(setting[0] == 1) {
// if (ota_sound.getState() != Sound.SOUND_STOPPED) {
// try {
// ota_sound.stop();
// } catch(Exception exception) { }
// }
// }
// }
/*
* 开始运行应用程序
*/
public void startApp()
{
ota_sound = setSound("/title.ott", 1);
showLogoCanvas();
}
// public void commandAction(Command command, Displayable displayable)
// {
// if(command.getCommandType() == 7)
// exitApp();
// else
// if(command.getCommandType() == 2)
// backToMenu();
// }
/*
* 加载游戏设定
*/
public void loadSetting()
{
try
{
RecordStore recordstore = RecordStore.openRecordStore("ds_setup", false);
try
{
byte abyte0[] = recordstore.getRecord(1);
for(int i1 = 0; i1 < setting.length; i1++)
setting[i1] = abyte0[i1];
} catch(InvalidRecordIDException invalidrecordidexception) {
setting = (new byte[] {
1, 0, 1, 1, 1, 1
});
}
recordstore.closeRecordStore();
} catch(RecordStoreException recordstoreexception) {
// System.out.println("RS exception: ".concat(String.valueOf(String.valueOf(recordstoreexception))));
setting = (new byte[] {
1, 0, 1, 1, 1, 1
});
}
}
/*
* 保存游戏设定
*/
public void saveSetting()
{
try
{
RecordStore recordstore = RecordStore.openRecordStore("ds_setup", true);
byte abyte0[] = new byte[setting.length];
for(int i1 = 0; i1 < setting.length; i1++)
abyte0[i1] = setting[i1];
try
{
recordstore.setRecord(1, abyte0, 0, setting.length);
} catch(InvalidRecordIDException invalidrecordidexception) {
recordstore.addRecord(abyte0, 0, setting.length);
}
recordstore.closeRecordStore();
} catch(RecordStoreException recordstoreexception) {
// System.out.println("RS exception: ".concat(String.valueOf(String.valueOf(recordstoreexception))));
}
}
/*
* 获得角色生命次数
*/
public int getN()
{
return n;
}
/**
* 设定角色生命次数
* @param i1 int,角色生命次数
*/
public void setN(int i1)
{
n = i1;
}
/*
* 保存声音状态,"*"键控制声音开启和关闭
*/
public void setSoundState() {
setting[0] = (byte)(1 - setting[0]);
}
// public boolean eNum()
// {
// return setting[5] == 1;
// }
/**
* 获得游戏难易度
* @return 0:易 1:难
*/
public boolean getGameRank() {
return setting[1] == 0;
}
/**
* 设定背光灯亮度
* @return setting[4] byte,是否开启背光灯
*/
public byte loadLights()
{
if(setting[4] == 1)
DeviceControl.setLights(0, 100);
return setting[4];
}
/*
* 暂停应用程序
*/
public void pauseApp() {
}
/**
* 终止应用程序
* @param flag boolean
*/
public void destroyApp(boolean flag) {
}
/**
* 退出应用程序
*/
public static void exitApp()
{
try
{
inc.destroyApp(true);
}
catch(Exception exception) { }
inc.notifyDestroyed();
inc = null;
}
/*
* 返回到游戏主菜单
*/
public void backToMenu()
{
if(M == null)
M = new MenuCanvas(this);
M.initliza((byte)0);
// M.saveIndex(pauseGame);
titleSound();
Display.getDisplay(this).setCurrent(M);
M.repaint();
//System.gc();
}
/*
* 初始化游戏中帮助菜单
*/
public void initGameHelpMenu()
{
if(M == null)
M = new MenuCanvas(this);
M.initliza((byte)1);
Display.getDisplay(this).setCurrent(M);
M.repaint();
//System.gc();
}
/*
* 初始化游戏模式菜单
*/
public void initModeMenu()
{
if (GC != null) {
GC.endT();
GC.pauseGame();
}
if(M == null)
M = new MenuCanvas(this);
M.initliza((byte)2);
M.setSelectedIndex(backToGameMode());
Display.getDisplay(this).setCurrent(M);
M.repaint();
//System.gc();
}
/**
* 新建并显示LogoCanvas类界面
*/
public void showLogoCanvas()
{
LogoCanvas d1 = new LogoCanvas(this, -1);
d1.startThr();
Display.getDisplay(this).setCurrent(d1);
d1 = null;
//System.gc();
}
/*
* 初始化帮助菜单
*/
public void initHelp1Menu()
{
if(o == null)
o = new HelpAboutCanvas();
o.setMenuState(0);
Display.getDisplay(this).setCurrent(o);
//System.gc();
}
/*
* 初始化帮助菜单
*/
public void initHelp2Menu()
{
if(o == null)
o = new HelpAboutCanvas();
o.setMenuState(1);
Display.getDisplay(this).setCurrent(o);
//System.gc();
}
/*
* 初始化游戏设置菜单
*/
public void initSettingMenu()
{
Options a1 = new Options(this);
Display.getDisplay(this).setCurrent(a1);
a1 = null;
//System.gc();
}
/*
* 初始化选择的游戏角色
*/
public void initPlayer()
{
if(S == null)
S = new SelectPlayer(inc);
S.setPlayer(0, -1, false, false);
Display.getDisplay(this).setCurrent(S);
//System.gc();
}
/**
* 保存取得的菜单索引值
* @param i1 int,菜单索引值
*/
public void saveIndex(int i1)
{
j = i1;
}
/*
* 返回选择的游戏模式选项
*/
public int backToGameMode()
{
return j;
}
public void EnterGame(int i1, int j1)
{
if(GC == null)
GC = new GameCanvas(inc);
else
try
{
Thread.currentThread();
Thread.sleep(2000L);
}
catch(Exception exception) { }
GC.setGamePlayer(i1, j1);
Display.getDisplay(inc).setCurrent(GC);
}
public void atBack(){
if(!GC.jugdeGameNum()){
inc.backToMenu();
} else {
int i1 = GC.getPlayer1().getPlayer();
int j1 = GC.getPlayer2().getPlayer();
if(++j1 == i1)
j1++;
if(j1 >= 8)
{
inc.backToMenu();
} else
{
if(S == null)
S = new SelectPlayer(inc);
S.setPlayer(i1, j1, true, false);
Display.getDisplay(this).setCurrent(S);
EnterGame(i1, j1);
//System.gc();
}
}
}
public void back()
{
if(!GC.jugdeGameNum()){
inc.backToMenu();
} else {
int i1 = GC.getPlayer1().getPlayer();
int j1 = GC.getPlayer2().getPlayer();
int k1 = GC.getPlayer1().getE(); //playerAction()
if(++j1 == i1)
j1++;
if(j1 >= 8) {
inc.backToMenu();
} else {
if(S == null)
S = new SelectPlayer(inc);
S.setPlayer(i1, j1, true, false);
Display.getDisplay(this).setCurrent(S);
EnterGame(i1, j1);
GC.getPlayer1().setE(k1);
//System.gc();
}
}
}
/*
* 取消帮助菜单并显示游戏中画面
*/
public void backToGame()
{
if (bGameHelp) {
//GC.startT();
bGameHelp = false;
}
Display.getDisplay(inc).setCurrent(GC);
}
/*
* 显示游戏中帮助菜单并暂停游戏
*/
public void pauseGame(){
bGameHelp = true;
//GC.endT();
GC.pauseGame();
initHelp1Menu();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -