⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gamelogic.java~1~

📁 一个类似炸弹人的游戏(city hunter)
💻 JAVA~1~
📖 第 1 页 / 共 5 页
字号:
//===============================================//
//  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[][]; ////////暴炸点
  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;  //用来统计当前关卡的怪物个数
  private byte M_imapno[][];
  /*    { //////////////////////测试用的数量.
      {
      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; //////大地图中用小块地图的宽的个数.
  private int m_imapnoH; //////大地图中用小块地图的高的个数.
  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; /////手机上要画的X方向的块数
  private int m_drawy = 0; /////手机上要画的Y方向的块数
  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[][]; ////////////////奖品数组正想用来设奖品信息量的还没有用上
  private static final byte m_medaltotal = 6; //////奖品最大个数

  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; // 显示游戏分数 大图
  private Image M_imgnum[];  // 小图
  //////////////////////////////////人物是16*20.在画人时我y减了4.这样当成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;  //判断方向的标志
  int imgpoint;   // 用来 指示当前画那一帧

  private int M_iHPlay[]; ////人的性质
  private int M_iCPlay[][]; /////电脑的性质
  private Image PlayImage[]; ////人物图
  private byte m_iCPUPlayNo = 0; /////电脑数量

  private byte Toll_Gate = 0; /////当前关数
  Random rand = new Random(); ///////用来产生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)
    {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -