?? gamelogic.java~1~
字號:
//===============================================//
// BB Factory version 1.00 //
// Platform : Nokia K-Java handsets //
// Handset : Nokia 7650 //
// Author : Pacess HO //
// Date : 30-June-2003 //
// Copyright (C) 2003, Pacess HO. //
// Copyright (C) 2003, iNFOiSLiVE Corporation. //
//===============================================//
package city_hunter;
import java.io.*;
import java.util.*;
import java.io.InputStream;
import java.io.IOException;
import java.io.EOFException;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.Random;
import javax.microedition.rms.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import javax.microedition.rms.RecordStore;
/*final class Sprite {
int iType;
int iMiss;
int iX;
int iDX;
int iImageID;
int iCounter;
} */
//==============================//
// Logic part of "BB Factory" //
//==============================//
public class GameLogic
extends Canvas
implements Runnable, CommandListener {
// Motorola V303: 176x182 //
// Motorola C650: 128x96 //
// private static final int SCREEN_WIDTH = 176;
// private static final int SCREEN_HEIGHT = 182;
private static final String AUTHOR = "[ Produced by Pacess ]";
private static final String RMS_NAME = "Commander";
private static final String VERSION = "v1.00";
private static final int HELP_LINEEND = (20*9);
private static final int CREDIT_LINEEND = (30*9);
private static final int OPTION_H[] = {0, 13, 27, 42, 56, 71, 85, 97, 109};
private static final int GRADE_RANGE = 500;
private static final int PLAYER_SPEED = (4<<16);
private static final int PLAYER_HP = 100;
private static final byte MAX_LEVEL = 25;
private static final byte MAX_RECORD = 10;
private static final String RANK_NAME[] = {
"Florence", "Pacess", "Angela", "Sharon", "Kay",
"Daphne", "Angus", "Mandy", "Emma", "Idy"};
// Screen stage ID //
private String StrErr = "OK";
private static final byte STAGE_NONE = -1;
private static final byte STAGE_INIT = 10;
private static final byte STAGE_MENU = 20;
private static final byte STAGE_LEVEL = 30;
private static final byte STAGE_GAME = 40;
private static final byte STAGE_CLEAR = 50;
private static final byte STAGE_GAMEOVER = 55;
private static final byte STAGE_SETTING = 60;
private static final byte STAGE_HELP = 70;
private static final byte STAGE_RANK = 80;
private static final byte STAGE_RANKL = 85;
private static final byte STAGE_RANKW= 86;
private static final byte STAGE_UPLOAD = 90;
private static final byte STAGE_CREDIT = 100;
private static final byte STAGE_QUIT = 110;
private static int m_iStage = STAGE_NONE;
// private Sprite aa;
int wwwwww = 0;
private Command exit2 = new Command("退出", Command.BACK, 1);
private static final int MAX_FRAME_WAIT = 55;
private static final byte MAX_SAVELENGTH = 32;
private static final byte MAX_SAVEDATA = 8;
// private static final byte MAX_SPRITE = 8;
private static final int OPTION_Y = 79;
// Screen information //
private int SCREEN_WIDTH = getWidth();
private int SCREEN_HEIGHT = getHeight(); // isdesign for moto 176*182
//SCREEN_WIDTH = 176;
//SCREEN_HEIGHT = 182;
private int itimeNo;
//private int iImageno[];
//////////////////////////////////////////////////////////////////////////////////////////
private byte M_Bomb[][];
private static final byte m_bombtotal = 4;
private byte M_detonation_spot[][]; ////////暴炸點(diǎn)
private static final int m_detonation_spottotal = 9 * m_bombtotal;
private static final byte m_detonationtime = 7; ///暴炸顯示時間
private static final byte bombset = 60;
private static final int bombstrat = 0; ///開炸
private static final int bombtime = 1;
private static final int bombover = 1;
private int m_inocpu; //用來統(tǒng)計當(dāng)前關(guān)卡的怪物個數(shù)
private byte M_imapno[][];
/* { //////////////////////測試用的數(shù)量.
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
,
{
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}
,
{
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0}
,
// {0,1,1, 1,1,1, 1,1,1, 1,1,1, 1,1,0},
{
0, 1, 1, 1, 2, 2, 1, 1, 1, 2, 1, 1, 1, 1, 0}
,
{
0, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 0}
,
// {0,1,0, 1,0,1, 0,1,0, 1,0,1, 0,1,0},
{
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}
,
{
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0}
,
{
0, 1, 1, 1, 4, 5, 6, 7, 8, 1, 1, 1, 1, 1, 0}
,
{
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0}
,
{
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}
,
{
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0}
,
{
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}
,
{
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0}
,
{
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}
,
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
}; */
private int m_imapnoW; //////大地圖中用小塊地圖的寬的個數(shù).
private int m_imapnoH; //////大地圖中用小塊地圖的高的個數(shù).
private int m_movex = 0; /////偏移X
private int m_movey = 0; /////偏移Y
//////////用來算m_movex,m_movey的值
private int m_moveminx = 0; /////偏移X
private int m_movemaxx = 0; /////偏移X
private int m_moveminy = 0; /////偏移X
private int m_movemaxy = 0; /////偏移X
private int m_drawx = 0; /////手機(jī)上要畫的X方向的塊數(shù)
private int m_drawy = 0; /////手機(jī)上要畫的Y方向的塊數(shù)
private static final int m_mapTYPE_W = 16; ////////小地圖的寬
private static final int m_mapTYPE_H = 16; /////小地圖的高
private int m_pathW = 0; ////////沒多太用,等于一個
private byte M_medal[][]; ////////////////獎品數(shù)組正想用來設(shè)獎品信息量的還沒有用上
private static final byte m_medaltotal = 6; //////獎品最大個數(shù)
private Image M_imgmap[]; /////地圖
private Image M_imgbomb; /////炸彈
private Image M_imgbombing; //炸彈爆炸效果大
private Image M_imgplay[]; /////人物
private Image M_imgmedal[]; /////獎品
private Image M_title; // 顯示游戲信息
private Image M_imgnumber; // 顯示游戲分?jǐn)?shù) 大圖
private Image M_imgnum[]; // 小圖
//////////////////////////////////人物是16*20.在畫人時我y減了4.這樣當(dāng)成16*16的.
private static Image[][] m_imgman; // 主角動畫圖片
private static Image m_Bombing[]; // 爆炸動畫圖片
private Image m_imgenemy[][]; //怪物動畫圖片
private static Image m_Bombwall[];
private static Image m_diecpu[];
byte oldmandirect; //判斷方向的標(biāo)志
int imgpoint; // 用來 指示當(dāng)前畫那一幀
private int M_iHPlay[]; ////人的性質(zhì)
private int M_iCPlay[][]; /////電腦的性質(zhì)
private Image PlayImage[]; ////人物圖
private byte m_iCPUPlayNo = 0; /////電腦數(shù)量
private byte Toll_Gate = 0; /////當(dāng)前關(guān)數(shù)
Random rand = new Random(); ///////用來產(chǎn)生CPU玩家的方向中的.
private static final byte Bombing_c = 1; ///暴炸顯示畫面
private static final byte Bombing_ud = 5; ///暴炸顯示畫面
private static final byte Bombing_lr = 2; ///暴炸顯示畫面
private static final byte Bombing_lt = 3; ///暴炸顯示畫面
private static final byte Bombing_rt = 4; ///暴炸顯示畫面
private static final byte Bombing_ut = 6; ///暴炸顯示畫面
private static final byte Bombing_dt = 7; ///暴炸顯示畫面
private static final byte Bombing_wall = 20; ///暴炸顯示時間
///////////////////////////////////////////////////////////////////////////////////
// city_hunter game variables //
private static int m_life;
private static int m_iTopScore;
private static int m_iCounter;
private static int m_iTimeLeft;
private static int m_iTimeBase;
private static int m_iScore;
// Key //
private static final int KEY_NONE = 0;
private static final int KEY_L = 1;
private static final int KEY_R = 2;
private static final int KEY_UP = 4;
private static final int KEY_DOWN = 8;
private static final int KEY_LEFT = 16;
private static final int KEY_RIGHT = 32;
private static final int KEY_OK = 64;
private static final int KEY_NUM = 0;
private static final byte KEY_FIRE = 5;
private static final String TEXT_UI[] = {
"Loading...",
"Confirm quit?",
"# Yes",
"* No",
"SETTING",
"Sound",
"Vibrate",
"Auto-upload",
"Difficulity",
"OFF",
"ON", // 10
"On a simple defend mission,",
"your colleague are attack",
"by enemy. Only you can safe",
"their lives and win the war.",
"[2] = Up",
"[8] = Down",
"[4] = Left",
"[6] = Right",
"[5] = Fire",
"RANKING", // 20
"LEVEL ",
"Back to menu?",
"CREDIT LIST",
"Producer: Pacess",
"Programmer: Pacess",
"Designer: JoJo",
"Assistant: Sharon",
"Tester: Game Team",
"Presented by GameisLive",
"All rights reserved", // 30
"Loading...",
"Network error ",
"Score: ",
"Live: ",
"Grade:",
"Killed:",
"Score:",
"LEVEL CLEARED",
"Start",
"Exit", // 40
"Change",
"Back",
"Next",
"Yes",
"No"};
// Object type //
private static final byte LEVEL_TOY[] =
{
16, 24, 36, 56, 80};
private static final int LEVEL_TIME[] =
{
1000, 1200, 1400, 1700, 2000};
//====================//
// System variables //
//====================//
private static final Random m_rRandom = new Random();
private static Thread m_pThread = null;
private static GameMIDlet m_pParent;
private static pRank m_pRank;
private static pEffect m_pEffect;
private static boolean m_bRefresh;
private static boolean m_bPainting;
private static byte m_iPlayed;
private static int m_iScreenX, m_iScreenY;
private static int m_iImageLoaded;
private static int m_iKey;
// Game variables //
// private static Sprite m_pSprite[];
private static boolean m_bVibrateOn;
private static boolean m_bSoundOn;
private static boolean m_bPause;
private static byte m_iOption;
// private static byte m_iLevel;
// private static int m_iTopScore;
// private static int m_iCounter;
// private static int m_iTimeLeft;
// private static int m_iTimeBase;
private static long lTimeStart;
//==================================//
// Execute once object is created //
//==================================//
private static int m_iQuitL, m_iQuitR;
private static int m_iQuitID;
private static Command m_pNext;
private static Command m_pBack;
// Variables for RMS //
private static int m_iRecord;
private static int m_pScore[], m_pScoreI[];
private static byte m_pLevel[], m_pLevelI[];
private static String m_pName[], m_pNameI[];
private static boolean m_bSound;
private static boolean m_bVibrate;
private static boolean m_bAutoUpload;
private static byte m_iGameLevel;
private static byte m_iLevel;
private static String m_sName;
private static String m_sPhoneNo;
//===============//
// Constructor //
//===============//
GameLogic(GameMIDlet pMIDlet) {
// super(true);
m_pParent = pMIDlet;
// m_pEffect = new GameEffect();
m_bPause = false;
m_iStage = 0;
m_iStage = STAGE_GAME; //////////////////本不因放這的測試用的
Loaddatabase(); //////////////////////////本不因放這的測試用的
m_life = 3; // 測試用。。。。
m_iTimeLeft = 2000;
// try {
// title = Image.createImage("/image/1.png");
// }
// catch (Exception e) {
// }
}
public final void Setup() {
m_iLevel = 0;
m_bSound = true;
m_bVibrate = false;
m_bAutoUpload = false;
m_sName = RANK_NAME[rand(RANK_NAME.length)];
m_sPhoneNo = "85290009000";
m_iRankNo = 10;
m_pRank = new pRank(this);
m_pEffect = new pEffect(Display.getDisplay(m_pParent));
m_pEffect.LoadSound("/key.mid", (byte)1);
m_pEffect.LoadSound("/explose.mid", (byte)2);
// Reset local ranking table //
m_pName = new String[MAX_RECORD];
m_pScore = new int[MAX_RECORD];
m_pLevel = new byte[MAX_RECORD];
for (i=0; i<MAX_RECORD; i++) {
m_pName[i] = RANK_NAME[i];
m_pScore[i] = 100*(MAX_RECORD-i);
m_pLevel[i] = 0;
}
// Reset internet ranking table //
m_pNameI = new String[MAX_RECORD];
m_pScoreI = new int[MAX_RECORD];
m_pLevelI = new byte[MAX_RECORD];
for (i=0; i<MAX_RECORD; i++) {
m_pNameI[i] = RANK_NAME[i];
m_pScoreI[i] = 100*(MAX_RECORD-i);
m_pLevelI[i] = 0;
}
}
//==================//
// Thread process //
//==================//
public synchronized void start() {
m_pThread = new Thread(this);
m_pThread.start();
}
public synchronized void stop() {
m_pThread = null;
}
public int rand_no(int a) {
int r = rand.nextInt() % a;
if (r < 0)
{
r = -r;
}
return r;
}
//====================//
// Handle key press //
//====================//
private int ConvertKeyCode(int iKeyCode) {
int iKey;
iKey = iKeyCode;
if (iKey == getKeyCode(UP) || iKey == KEY_NUM2) {iKey = KEY_UP;} else
if (iKey == getKeyCode(DOWN) || iKey == KEY_NUM8) {iKey = KEY_DOWN;} else
if (iKey == getKeyCode(LEFT) || iKey == KEY_NUM4) {iKey = KEY_LEFT;} else
if (iKey == getKeyCode(RIGHT) || iKey == KEY_NUM6) {iKey = KEY_RIGHT;} else
if (iKey == getKeyCode(FIRE) || iKey == KEY_NUM5) {iKey = KEY_FIRE;}
if (iKey == KEY_NUM1) {iKey = KEY_UP|KEY_LEFT;} else
if (iKey == KEY_NUM3) {iKey = KEY_UP|KEY_RIGHT;} else
if (iKey == KEY_NUM7) {iKey = KEY_DOWN|KEY_LEFT;} else
if (iKey == KEY_NUM9) {iKey = KEY_DOWN|KEY_RIGHT;} else
if (iKey == KEY_STAR) {iKey = KEY_L;} else
if (iKey == KEY_POUND) {iKey = KEY_R;}
return iKey;
}
public void keyPressed(int iKeyCode) {
m_iKey = ConvertKeyCode(iKeyCode);
/* switch (iKeyCode)
{
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -