📄 gamemanager.java
字号:
import javax.microedition.lcdui.*;
import java.util.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
import java.io.*;
import javax.microedition.rms.RecordStore;
import java.util.Random;
//import com.nokia.mid.ui.DirectUtils;
public class gameManager extends Canvas implements Runnable{
private Thread t;
int introTimer = 0;
int introFps = 10;
private Graphics g2;
private Random r;
private Image ground;//currentWorld.
private Image man;
private Image cz7;
private Image cz6;
private Image cz5;
private Image cz4;
//private Image cz3;
//private Image cz2;
//private Image cz1;
public Image boss;
public Image oo;
public Image sp;
//public Image Mnet;
private Image magicMenu;
private Image magicEffect;
private Image cover;
private Image BufferImage;
private Image messageReady;
private Image magicMenuColorful;
private Image manState;
private Image menuPic;
private Image lu;
private Image ld;
private Image ru;
private Image rd;
private Image lineX;
private Image lineY;
private Image netPoint;
private Image magicHealth;
private Image gameOver;
private Image dg;
//public Image subMenuPic;
public Image eyes;
public Image star;
public Image long1;
public Image long2;
public Image long3;
private int tmpDirection;
private Player midiPlayer = null;
//private Player midiPlayer2 = null;
private int bossActive = 2;
boolean firstRun = true;
private byte stateLoading = -1;
private byte stateStart = 0;
private byte stateGameing = 1;
//private byte stateOver = 2;
private byte stateHelp = 3;
private byte stateAbout = 4;
private byte stateExit = 5;
private byte stateGroup = 6;
private byte gameState = stateStart;
public int threadSleepTime = 2;
private byte tmpMapPassable = 0;
private byte tmpMapPassable_man = 0;
private int W = 176;//螢幕寬
private int H = 208;//螢幕高
private int mapWidth = 0;//dis.readInt();
private int mapHeight = 0;//dis.readInt();
private int keyWait = -10;
//private int manPower = 100;
private int manPositionX;//人物相對於地圖的 x 座標,單位為地圖塊
private int manPositionY;//人物相對於地圖的 y 座標,單位為地圖塊
private int manX;//人物相對於螢幕的 x 座標,單位為象素
private int manY;//人物相對於螢幕的 y 座標,單位為象素
private int manSpeed ;//人物移動速度
//private int manLife = 50;
private int winX;
private int winY;
private int mapX =0;
private int mapY =0;
private int manHealth;
private int manMagic;
private int pAdd = 0;
private int direction;
private int foeAdd = 0;
public int splashAdd =0;
//private int alt =0;
private int foeSpeed = 2;
private int currentMagic;
private int magicStepX;
private int magicStepY; // 根據人物方向進行連鎖初始化!
private int magicX = 0;//螢幕座標x
private int magicY = 0;
private int magicAdd = 0;
private int magicPositionX = 0;//地圖座標x
private int magicPositionY = 0;
private int magicSpeed = 22;
public int subMenuSlt =0;
public int showHint = 0;
private int tAdd = 0;
//private int manGetThings = /////////////////////////////////////////////
private int bossMagicStepX = 0;
private int bossMagicStepY = 0;
private int bossMagicX = 0;
private int bossMagicY = 0;
private int bossMagicPositionX = 0;
private int bossMagicPositionY = 0;
public int manDart = 50;
private boolean useMagic = false;
private boolean magicStart = false;
private boolean magicHit = false;
private boolean manMove = false; //人物移動開關
private boolean mapMove = false; //地圖移動開關
private boolean gameRunning = true;//遊戲線程運行狀態
private boolean[] keyState = {false,false,false,false,false,false,false};
private boolean talking = false;
private boolean snow = false;
private boolean manRun = false;
private boolean keyWatch = false;
private boolean nearly = false;
private boolean canTalking = false;
boolean musicCtrl = false;
private boolean overDraw = false;
public boolean flag1 = false;
public boolean flag2 = false;
private byte[][] currentMap_Under = {};
private byte[][] currentMap_Over = {};
private byte[][] currentMap_channel ={};
private byte[][] map1_channel ={{16,28,5,1 ,5, 84, 2 ,89,9 }};
private byte[][] map2_channel ={{5,28,5,1 ,5, 0 , 1 , 5,7 }};
private byte[][] map3_channel ={{12,28,6,1 ,5, 88, 38 , 96,44 }};
private byte[][] map4_channel ={{19,28,4,1 ,5, 88, 47, 94,57 }};
private byte[][] map5_channel ={{15,59,6,2 ,6 , 33, 2, 38,8 },
{84,59,6,2 ,7 , 6, 3, 11,11 },
{89, 5,1,1 ,1 , 13, 16, 18,24},//16
{5 , 5,1,1 ,2 , 2, 16, 7,24},//17
{96,41,1,1 ,3 , 10, 16, 15,22},
{94,53,1,1 ,4 , 17, 16, 22,24}};
private byte[][] map6_channel ={{36,6,4,1 ,5, 13, 47 , 18,56}};
private byte[][] map7_channel ={{10,7,4,1 ,5, 81, 47 , 86,56 }};
/*
private byte[][] mapChange = {
// 當前所在座標的資料,需要替換成的資料,相關聯的頂層連鎖替換標號
{-24,-27,-34,-37,25,35,26,36}, // 地圖1_樹
{-24,-27,-34,-37,25,35,26,36}, // 地圖2_樹
{-8 ,-61 ,-42,-64,59, 62, 60,63}, // 地圖3_水
{-8 ,-61 ,-42,-64,59, 62, 60,63}, // 地圖4_水
{-27,-30 ,-65,-68,28, 66, 29,67}, // 地圖5_村
{-16,-16 ,-42,-42,14,40,15,41} // 地圖6_石
};*/
private int tmpManPositionX = 0;
private int tmpManPositionY = 0;
private int manWeapon = 1;
private int npcActive = 0;
public String hint = "*";
//得到物品 瓦爾基裏
private String[] getThing = { "", "得到青銅劍","得到瓦爾基裏劍","得到銳鐘斯劍","飛鏢 +20","生命 +20","體力 +50","","","","",""};
private String currentDialogue = "" ; //當前對白
//private int foeCount = 2;
//------------------------- 0 1 2 3 4 5 6 7 8 9 10 11
//------------------------- x , y , tmpX, tmpY , style , direction(-1,0-3) ,visiable/alive , moveAble , liftX , topY , width , height
private int[][] foePoint = {};
//------------------------- x0 , y1 , tmpX2, tmpY3 , style4 , direction(-1,0-3)5 ,visiable/alive6 , moveAble7 , liftX8 , topY9 , width10 , height11 身份(負數為敵人)12 ,攻擊狀態(負數為不攻擊13) 劇情判斷14 劇情增量15, 得到物品16
private final static int[][] map1_foe = { {12 , 18 , 0 , 0 , 4 , 4 , 5 , 1 , 4 , 17 , 22 , 16 , 1 , 0 , 1 , 1 , 0},
};
private final static int[][] map2_foe = { {24 , 12 , 0 , 0 , 8 , 4 , 5 , 1 , 4 , 10 , 22 , 16 , 1 , 0 , 4 , 1 , 3},
};
private final static int[][] map3_foe = { {17 , 15 , 0 , 0 , 4 , 4 , 5 , 1 , 4 , 13 , 21 , 16 , 1 , 0 , 2 , 1 , 0},
};
private final static int[][] map4_foe = { {10 , 9 , 0 , 0 , 4 , 4 , 5 , 1 , 2 , 8 , 24 , 20 , 1 , 0 , 3 , 1 , 4},
};
private final static int[][] map5_foe = { {26 , 8 , 0 , 0 , 6 , 4 , 5 , 1 , 21 , 6 , 10 , 5 , -1 , 0 , -2 , 1 , 0},
{52 , 8 , 0 , 0 , 6 , 5 , 5 , 1 , 47 , 6 , 10 , 5 , -1 , 0 , -3 , 1 , 0},
{14 , 19 , 0 , 0 , 7 , 4 , 5 , 1 , 2 , 6 , 22 , 17 , -1 , 0 , -4 , 1 , 0},
{64 , 20 , 0 , 0 , 7 , 5 , 5 , 1 , 47 , 7 , 44 , 25 , -1 , 0 , 5 , 1 , 0},//15
{17 , 44 , 0 , 0 , 6 , 5 , 5 , 1 , 2 , 36 , 45 , 23 , -1 , 0 , -3 , 1 , 0},
{77 , 45 , 0 , 0 , 7 , 4 , 5 , 1 , 55 , 30 , 44 , 20 , -1 , 0 , -4 , 1 , 0},
{44 , 57 , 0 , 0 , 7 , 5 , 5 , 1 , 23 , 42 , 35 , 16 , -1 , 0 , -5 , 1 , 0}
};
private final static int[][] map6_foe = { {16 , 17 , 0 , 0 , 6 , 4 , 5 , 1 , 11 , 9 , 17 , 25 , -1 , 0 , -2 , 1 , 0},
{24 , 25 , 0 , 0 , 6 , 5 , 5 , 1 , 11 , 9 , 17 , 25 , -1 , 0 , -3 , 1 , 0},
{17 , 34 , 0 , 0 , 6 , 4 , 5 , 1 , 11 , 9 , 17 , 25 , -1 , 0 , -4 , 1 , 0},
{33 , 35 , 0 , 0 , 6 , 5 , 5 , 1 , 11 , 9 , 17 , 25 , -1 , 0 , -5 , 1 , 0},//15
{25 , 24 , 0 , 0 , 9 , 6 , 45 , 1 , 11 , 9 , 17 , 25 , 1 , 0 , 5 , 1 , 0}//15
};
private final static int[][] map7_foe = { {16 , 22 , 0 , 0 , 4 , 4 , 5 , 1 , 15 , 21 , 12 , 11 , 1 , 0 , 0 , 1 , 0},
{13 , 11 , 0 , 0 , 6 , 4 , 5 , 1 , 10 , 9 , 3 , 2 , 1 , 0 , 0 , 1 , 0}
}; //身份
private int courseNum;//劇情事件編號
private int menuI =0;
//座標 當前劇情值 碰撞增量 得到物品
int[][] npcSome = {};
// 劇情事件驅動範圍編號, 相同值的對話為同一次對話 // 當某句對話為空時,用%%代替,程式將跳過此句
int[][] courseScope = {};
int[][] courseScope_map1 = {{ 1,0, 2,0, 3,0, }}; //
int[][] courseScope_map2 = {{ 1,0, 2,0, 3,0, 4,1 }}; //
int[][] courseScope_map3 = {{0,0, 1,0, 2,0, 3,0, 5,1 }}; //
int[][] courseScope_map4 = {{0,0, 1,0, 2,0, 3,0, 5,1, 6,1, 7,2, 8,2,9,2 }}; //
int[][] courseScope_map5 = {{0,0, 2,0, 2,3, 2,3, 2,3, 2,0, 3,0, }}; //
int[][] courseScope_map6 = {{5,0, 6,0, }}; //
int[][] courseScope_map7 = {{0,0, 1,0, 2,0, 3,0 },
{0,0, 1,0, 2,0, 3,0 }
}; //
String[][] Dialogue = {};///////////////////////////////////////
String gameShow = "中古時代,某種邪惡力量突然降臨,從此,平靜的生活變得危機重重,善良的靈魂被邪惡操縱,黑暗水晶被喚醒.....面對生死,面對邪惡,是堅持信仰,還是.....";
int currentMapID;
aRPG arpg ;
gameManager( aRPG arpg){
this.arpg = arpg;
///////////////////////////////////////////////
man = load("man");
oo = load("oo");
sp = load("sp");
//Mnet = load("Mnet");
// cz3 = load("cz3");
// cz2 = load("cz2");
//cz1 = load("cz1");
cover = load("cover");
boss = load("boss");
eyes = load("eyes");
star = load("star");
lu= load("lu");
ld= load("ld");
ru= load("ru");
rd= load("rd");
lineX= load("lineX");
lineY= load("lineY");
menuPic= load("menuPic");
netPoint = load("netPoint");
gameOver = load ("gameOver");
dg = load("dg");
BufferImage = Image.createImage(W,H);
g2 = BufferImage.getGraphics();
r = new Random();
gameRestart();
//saveAndRead(true);
saveAndRead(false);
setFullScreenMode(true);
// 不同機型要set字體
t = new Thread(this);
t.start();
}
public void run(){
while ( gameRunning ){
repaint();
serviceRepaints();
//System.gc();
try{
t.sleep(threadSleepTime);
}catch(Exception Ex){}
}
try{
arpg.notifyDestroyed();
}catch(Exception Ex){}
}
public void paint(Graphics g){
switch(gameState){
case -1:
//loadBar(g,22);
load(currentMapID);
break;
case 0:
if(introTimer >= introFps * 9){
introTimer = introFps * 9;
oo = null;
sp = null;
//Mnet = null;
//if (cover == null)cover = load("cover");
splash(g);
}
else{
intro(g);
}
introTimer++;
break;
case 1:
g.setColor(0,0,0);
g.fillRect(0,0,W,H);
gameScreen(g, keyState);
break;
case 2:
break;
case 3:
helpAndAbout(g ,2);
triangle(g,W-10,H-9);
break;
case 4:
helpAndAbout(g ,1);
triangle(g,W-10,H-9);
break;
case 5:
gameRunning = false;
break;
case 6:
helpAndAbout(g ,3);
triangle(g,W-10,H-6);
break;
}
}
public void hideNotify(){
showSubMenu = true;
//snow = true;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -