?? mycanvas.java~104~
字號:
package Game;
/////////////////////////////
//屏幕寬180
//屏幕高196
/////////////////////////////
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import java.io.*;
import javax.microedition.lcdui.Font;
public class MyCanvas extends Canvas implements Runnable {
//////////////////////////////////////////////////////宏定義
public static final int GAME_LOGO = 0;
public static final int UP = -1;
public static final int DOWN = -2;
public static final int LEFT = -3;
public static final int RIGHT = -4;
public static final int FIRE = -5;
public static final int LEFT_KEY = -6;
public static final int RIGHT_KEY = -7;
//////////////////////////////////////////////////////mc變量
DataRMS dr;
int viewX; //屏幕左上角坐標
int viewY; //屏幕左上角坐標
int screenWidth; //屏幕寬
int screenHeight; //屏幕高
Image imgBuffer; //雙緩沖圖片
Thread thread; //線程
Graphics gg; //雙緩沖畫筆
Font font;
Mymidlet midlet; //移動信息驅動描述
Tools tools; //工具
///////////////////////////////////////////////////////狀態變量
int gameState; //游戲總狀態 0--菜單頁 1--游戲頁
int scene; //游戲進行中的場景號: 0--戰斗頁 其它代表各場景的序號
int sceneAfterFight; //記錄戰斗之后應該回到的場景
boolean keyState; //按鍵狀態!!!!!!!
int switchFightState; //場景畫面與戰斗畫面的切換狀態:
boolean running; //游戲開始
int toScene; //即將要切換去的場景號
int SlideState;
///////////////////////////////////////////////////////指針變量
int mainMenuPoint; //游戲主目錄指針
//////////////////////////////////////////////////////計時器變量
int logoCount; //LOGO計時器
///////////////////////////////////////////////////////坐標變量
///////////////////////////////////////////////////////游戲變量
MyImage image; //圖片類
Map map; //地圖
Hero hero;
Menu menu; //菜單
Text text; //顯示信息
boolean confirm = false; //是否按下確定
boolean dialogOn; //是否處于對話狀態
int dialogID; //對話ID號,隨著劇情增加
boolean firstBoot; //是否第一次游戲
int process = 0; //游戲進度,與同一個 NPC 說不同的話時用到
////////////////////////////////////////////////////////////////////////////////
public MyCanvas(Mymidlet midlet) { //構造!!!!!, 系統構造
this.setFullScreenMode(true); //設置全屏
this.dr = new DataRMS(this); //生成一個存儲對象
gameState = GAME_LOGO;
image = new MyImage(this);
tools = new Tools(this);
this.midlet = midlet;
this.screenHeight = this.getHeight();
this.screenWidth = this.getWidth();
thread = new Thread(this);
imgBuffer = Image.createImage(this.getWidth(), this.getHeight());
gg = imgBuffer.getGraphics();
font = Font.getFont(0, 0, 16);
menu = new Menu(this);
hero = new Hero(this);
text = new Text(this);
}
////////////////////////////////////////////////////////////////////////////
//自定義方法
public void gamestart() { //游戲開始
thread.start();
running = true;
}
public void ClearScreen(Graphics g) {
g.setColor(0);
g.fillRect(0, 0, this.screenWidth, this.screenHeight);
}
public void game_logic() { /////////////邏輯!!!!!邏輯!!!!!邏輯!!!!!
}
public void checkTalk() {
if (text.getTextState() == 0 && confirm) { //沒有對話時,并且按下確定時
switch (hero.getNextCollideNPC()) {
case 4: //與阿美對話時
dialogOn = true;
switch (process) {
case 1: //與阿美第一次對話完后
dialogID = 14;
break;
case 2: //與霍恩第一次對話完后
case 3: //與胡爾第一次對話完后
dialogID = 26;
break;
}
break;
case 2: //與霍恩對話
dialogOn = true;
switch (process) {
case 1: //與阿美第一次對話完后
dialogID = 15;
break;
case 2: //與霍恩第一次對話完后
case 3: //與胡爾第一次對話完后
dialogID = 25;
break;
}
break;
case 1: //與胡爾對話
dialogOn = true;
switch (process) {
case 1: //還沒到與此 NPC 對話的時候
dialogID = 44;
break;
case 2: //與霍恩第一次對話完后
dialogID = 27;
break;
case 3: //與胡爾第一次對話完后
dialogID = 37;
break;
}
break;
case 0: //與薩耶對話
dialogOn = true;
switch (process) {
case 1:
case 2: //還沒發展到此情節
dialogID = 44;
break;
case 3: //與胡爾第一次對話完后
dialogID = 38;
break;
}
break;
}
}
}
public void setDialog() {
if (dialogOn) {
text.emptyText();
switch (dialogID) {
case 1: //========= 與阿美第一次對話
// text.setText(0, "阿美:你終于醒了!");
text.setText(0, "辰:介不似蘋果李么!");
text.show();
break;
case 2:
// text.setText(0, "諾齊奧尼:這是什么地");
text.setText(0, "蘋果李:額。。你認識我?");
text.setText(1, "方?");
break;
case 3:
text.setText(0, "阿美:我的家啊!你已");
text.setText(1, "經昏睡了3天啦!");
break;
case 4:
text.setText(0, "諾齊奧尼:……");
break;
case 5:
text.setText(0, "阿美:你和你的朋友倒");
text.setText(1, "在海邊,是我爸爸把你");
text.setText(2, "們救回來的。");
break;
case 6:
text.setText(0, "諾齊奧尼:露娜,露娜");
text.setText(1, "……她在哪?");
break;
case 7:
text.setText(0, "阿美:哦。是那個女孩");
text.setText(1, "嗎?");
break;
case 8:
text.setText(0, "諾齊奧尼:嗯……");
break;
case 9:
text.setText(0, "阿美:她還在昏迷當中");
text.setText(1, "……");
break;
case 10:
text.setText(0, "諾奇奧尼:那我怎么才");
text.setText(1, "能救她啊……");
break;
case 11:
text.setText(0, "阿美:這個我也不知道");
text.setText(1, "……你去門口找我爸爸");
text.setText(2, "問問吧,他就在這附近");
break;
case 12:
text.setText(0, "賣裝備呢!");
break;
case 13:
text.setText(0, "諾奇奧尼:嗯,好的…");
text.setText(1, "…");
text.setCanEnd(true); //第一對話結束!
process = 1;
break;
case 14: //========= 與阿美第二次對話
text.setText(0, "阿美:快去問問我爸爸");
text.setText(1, "吧,他就在外邊附近。");
text.show();
text.setCanEnd(true); //此次對話結束
break;
case 15: //========= 與霍恩第一次對話
text.setText(0, "霍恩:小伙子你醒啦?");
text.show();
break;
case 16:
text.setText(0, "諾奇奧尼:謝謝您的救");
text.setText(1, "命之恩!我的朋友還沒");
text.setText(2, "醒,能幫我救救他嗎?");
break;
case 17:
text.setText(0, "霍恩:我已經盡力了,");
text.setText(1, "她中了一種很奇怪的毒");
text.setText(2, ",我從來沒有見過……");
break;
case 18:
text.setText(0, "諾奇奧尼:那……那怎");
text.setText(1, "么辦?");
break;
case 19:
text.setText(0, "霍恩:村子附近有個男");
text.setText(1, "孩叫胡爾,他性格很孤");
text.setText(2, "僻,但是精通醫術,你");
break;
case 20:
text.setText(0, "試著去找他問問吧。");
break;
case 21:
text.setText(0, "諾奇奧尼:嗯…好的。");
break;
case 22:
text.setText(0, "霍恩:等一下……自從");
text.setText(1, "你們的島被破壞后,村");
text.setText(2, "子附近有了許多奇怪的");
break;
case 23:
text.setText(0, "怪物,這是一把我精心");
text.setText(1, "打造的劍,你先拿去防");
text.setText(2, "身用。");
break;
case 24:
text.setText(0, "諾奇奧尼:嗯,謝謝,");
text.setText(1, "我會注意的。");
text.setCanEnd(true); //與霍恩第一次對話結束
process = 2;
break;
case 25: //========= 與霍恩第二次對話
text.setText(0, "霍恩:快去吧,救人要");
text.setText(1, "緊。");
text.show();
text.setCanEnd(true); //此次對話結束
break;
case 26: //========= 與阿美第三次對話
text.setText(0, "阿美:胡爾那人性格雖");
text.setText(1, "然孤僻,但是他內心里");
text.setText(2, "挺善良的。");
text.show();
text.setCanEnd(true); //此次對話結束
break;
case 27: //========= 與胡爾第一次對話
text.setText(0, "諾奇奧尼:請問你是胡");
text.setText(1, "爾嗎?");
text.show();
break;
case 28:
text.setText(0, "胡爾:小子,問這個干");
text.setText(1, "嘛?想打架嗎?");
break;
case 29:
text.setText(0, "諾奇奧尼:誤會誤會,");
text.setText(1, "我是請你幫我救人的…");
text.setText(2, "…");
break;
case 30:
text.setText(0, "胡爾:救人?天天都有");
text.setText(1, "人要我幫他們救人!我");
text.setText(2, "為什么要幫你?");
break;
case 31:
text.setText(0, "諾奇奧尼:求求你了,");
text.setText(1, "她對我非常重要!你想");
text.setText(2, "要什么我都能答應!");
break;
case 32:
text.setText(0, "胡爾:她?又是個癡情");
text.setText(1, "的人!好吧,看你那么");
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -