📄 gamemidlet.java
字号:
m_pDisplay.setCurrent(m_pGameScreen);
/* Start Addition 21-03-2003 for external events */
activeDisplay = m_pGameScreen;
//System.out.println("activeDisplay_playS"+activeDisplay);
/* End Addition 21-03-2003 */
m_pGameScreen.g_bdrawLoading = true;
m_pGameScreen.repaint();
m_pGameScreen.serviceRepaints();
readGameData();
m_pGameScreen.g_bdrawLoading = false;
m_pGameModel.playSavedGame();
m_pGameScreen.startGame(false, false);
resumeGame();
}
private void resumeGame() {
removeCommands(m_pGameScreen);
m_pGameScreen.addCommand(m_cmdPause);
m_pGameScreen.startGame(true, false);
m_pDisplay.setCurrent(m_pGameScreen);
/* Start Addition 21-03-2003 for external events */
activeDisplay = m_pGameScreen;
//System.out.println("activeDisplay_resumeS"+activeDisplay);
/* End Addition 21-03-2003 */
}
private void newGame() {
if (m_pGameScreen == null) { // SD
m_pGameScreen = new GameScreen(this);
m_pGameModel = new GameModel(this, m_pGameScreen);
m_pGameScreen.setModel(m_pGameModel);
}
m_bSavedGame = false;
m_bHasBeenSaved = false;
m_pMenuScreen.level1Index = 1;
removeCommands(m_pGameScreen);
m_pGameScreen.addCommand(m_cmdPause);
m_pDisplay.setCurrent(m_pGameScreen);
/* Start Addition 21-03-2003 for external events */
activeDisplay = m_pGameScreen;
//System.out.println("activeDisplay_newG"+activeDisplay);
/* End Addition 21-03-2003 */
if (m_pGameModel.g_bPaused) {
m_pGameScreen.startGame(true, false);
}
m_pGameScreen.startGame(false, true);
}
private void saveAndQuit() {
m_pGameScreen.g_bdrawSaving = true;
m_pGameScreen.repaint();
m_pGameScreen.serviceRepaints();
m_bSavedGame = true;
saveGameData();
m_bHasBeenSaved = true;
saveOptions();
m_pMenuScreen.level1Index = 0;
}
void pauseGame() {
/* Start Addition 21-03-2003 for external events */
if(activeDisplay != null && activeDisplay == m_pGameScreen){
/* End Addition 21-03-2003 */
m_pGameScreen.m_selectedIndex = 0;
removeCommands(m_pGameScreen);
m_pGameScreen.addCommand(m_cmdSelect);
m_pGameScreen.pauseGame();
m_pDisplay.setCurrent(m_pGameScreen);
/* Start Addition 21-03-2003 for external events */
activeDisplay = m_pGameScreen;
//System.out.println("activeDisplay_pause"+activeDisplay);
/* End Addition 21-03-2003 */
}
}
private void showText(int messageId) {
m_pTextScreen.init(messageId);
m_pDisplay.setCurrent(m_pTextScreen);
/* Start Addition 21-03-2003 for external events */
activeDisplay = m_pTextScreen;
//System.out.println("activeDisplay_text"+activeDisplay);
/* End Addition 21-03-2003 */
}
private void showHighScores() {
m_pHiScoreScreen.setCommandListener(this);
m_pDisplay.setCurrent(m_pHiScoreScreen);
/* Start Addition 21-03-2003 for external events */
activeDisplay = m_pHiScoreScreen;
//System.out.println("activeDisplay_high"+activeDisplay);
/* End Addition 21-03-2003 */
m_pHiScoreScreen.showHighScores();
}
private void removeCommands(Displayable pDisplayable) {
pDisplayable.removeCommand(m_cmdPause);
pDisplayable.removeCommand(m_cmdSelect);
}
private void showMenuScreen() {
m_pDisplay.setCurrent(m_pMenuScreen);
/* Start Addition 21-03-2003 for external events */
activeDisplay = m_pMenuScreen;
//System.out.println("activeDisplay_menu"+activeDisplay);
/* End Addition 21-03-2003 */
m_pMenuScreen.repaint();
}
void showHiScores(int score) {
m_pHiScoreScreen.setPeakScore(score);
m_pHiScoreScreen.enterHighScore();
}
private void exitApp() {
try {
saveOptions();
if (!m_bHasBeenSaved) {
saveGameData();
}
destroyApp(true);
notifyDestroyed();
} catch (MIDletStateChangeException e) {}
}
private void saveOptions() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream pDos = new DataOutputStream(baos);
try {
pDos.writeBoolean(m_bSoundOn);
pDos.writeBoolean(m_bSavedGame);
} catch (Exception ex) {
return;
}
RecordStore rs = null;
byte[] buf = baos.toByteArray();
try {
rs = RecordStore.openRecordStore("qbertopt", true);
rs.setRecord(1, buf, 0, buf.length);
} catch (InvalidRecordIDException ire) {
// add record if it doesn't exist
try {
rs.addRecord(buf, 0, buf.length);
} catch (Exception e) {
}
} catch (Exception e) {
// nothing.. maybe full
} finally {
try {
if (rs != null)
rs.closeRecordStore();
} catch (Exception e) {}
}
}
private void readOptions() {
RecordStore rs = null;
try {
rs = RecordStore.openRecordStore("qbertopt", true);
DataInputStream pDis = new DataInputStream(new ByteArrayInputStream(rs.getRecord(1)));
// read the options
m_bSoundOn = pDis.readBoolean();
m_bSavedGame = pDis.readBoolean();
} catch (Exception e) {
m_bSoundOn = false; // this should already be false; if sound should be enabled by default, change to true here
} finally {
if (rs != null) {
try {
rs.closeRecordStore();
} catch (Exception e) {}
}
}
}
private void saveGameData() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream pDos = new DataOutputStream(baos);
try {
m_pGameModel.saveAll(pDos);
m_pGameScreen.g_bdrawSaving = false;
showMenuScreen(); // SD ?
} catch (Exception e) {
return;
}
RecordStore rs = null;
byte[] buf = baos.toByteArray();
try {
rs = RecordStore.openRecordStore("qbertdata", true);
rs.setRecord(1, buf, 0, buf.length);
} catch (InvalidRecordIDException ire) {
// add record if it doesn't exist
try {
rs.addRecord(buf, 0, buf.length);
} catch (Exception ex) {
}
} catch (Exception e) {
// nothing.. maybe full
} finally {
try {
if (rs != null)
rs.closeRecordStore();
} catch (Exception ex) {
}
}
}
private void readGameData() {
RecordStore rs = null;
try {
rs = RecordStore.openRecordStore("qbertdata", true);
DataInputStream pDis = new DataInputStream(new ByteArrayInputStream(rs.getRecord(1)));
m_pGameScreen.startGame(false, false);
m_pGameModel.loadSavedGame(pDis);
m_pGameScreen.pauseGame();
} catch (Exception ex) {
m_bSavedGame = false;
} finally {
if (rs != null) {
try {
rs.closeRecordStore();
} catch (Exception ex) {
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -