📄 carrace.java
字号:
/*
* @(#)CarRace.java 1.0 04/07/01 @(#)
*
* Copyright 2004 NTT DoCoMo, Inc. All rights reserved.
*/
import com.nttdocomo.ui.Dialog;
import com.nttdocomo.ui.Display;
import com.nttdocomo.ui.IApplication;
/**
* CarRace<BR>
* The main class of the application.
* <br>
* 2 scratchpads are used in this application.<br>
* <ol>
* <li>Score data<br>
* Manages the score shown in the score-rank as five 4-byte data.<br>
* <pre>
* | 00 00 3D EA | 00 00 1C 84 | 00 00 1B BC | 00 00 15 E0 | 00 00 10 9A |
* Rank-1 Rank-2 Rank-3 Rank-4 Rank-5
* </pre>
* <li>Image/Sound data<br>
* first 1-byte manages the download state of the media data,<br>
* and from the second byte combinations of data size and media data
* follows for the amount of the file numbers.
* <pre>
* | 01 | 06 48 | 47 49 46 38 ... 02 00 3B | 04 0E | 47 49 46 ... 80 00 3B | ...
* (a) (b) (c) (d) (e)
*
* (a) Download flag (1: Finish)
* (b) Media1 file size (2 byte fixed)
* (c) Media1 file date (length variable)
* (d) Media2 file size (2 byte fixed)
* (e) Media2 file data (length variable)
* :
* </pre>
* <p>
* @version 1.0
* </p>
*/
public class CarRace extends IApplication {
/** SCORE */
private Score score = new Score();
/** TITLE Panel */
private TitlePanel titlePanel = null;
/** RANKING Panel */
private RankPanel rankingPanel = null;
/** MAIN Canvas */
private GameCanvas gameCanvas = null;
/** RUN Thread */
private Thread thread = null;
/**
* The first method that runs in the beginning of the application.
*/
public void start() {
try {
/* Loading media file */
if (false == MediaCollection.load()) {
Dialog dialog = new Dialog(Dialog.DIALOG_INFO, "Error");
dialog.setText("It failed on loading of a media file.");
dialog.show();
terminate();
}
/* Creating title screen */
titlePanel = new TitlePanel(this, score);
/* Creating ranking screen */
rankingPanel = new RankPanel(this, score);
/* Creating game screen */
gameCanvas = new GameCanvas(this, score);
/* Displaying the title */
Display.setCurrent(titlePanel);
} catch (Exception e) {
StringBuffer msg = new StringBuffer();
msg.append(e.getClass().getName());
Dialog dialog = new Dialog(Dialog.DIALOG_INFO, "Error");
dialog.setText(msg.toString());
dialog.show();
MediaCollection.dispose();
terminate();
}
}
/**
* The method that runs first after comming back from suspend mode.
* <br>
* By using getSuspendInfo() method, you can acquire the reason of
* the suspend and the effects during the suspend mode.
*/
public void resume() {
}
/**
* Starts the race game.
*/
public void play() {
thread = new Thread(gameCanvas);
thread.start();
}
/**
* Ends the race game and shows the title screen.
*/
public void endGame() {
score.save();
showTitlePanel();
}
/**
* Displays the ranking.
*/
public void showRanking() {
rankingPanel.refresh();
Display.setCurrent(rankingPanel);
}
/**
* Displays the title screen.
*/
public void showTitlePanel() {
titlePanel.refresh();
Display.setCurrent(titlePanel);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -