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

📄 gamelogic.java.bak

📁 一个类似炸弹人的游戏(city hunter)
💻 BAK
📖 第 1 页 / 共 5 页
字号:

  //====================================//
  //  Title screen: Wait select option  //
  //====================================//
  private void Flow_TITLE() {

  }

  //===============//
  //  Help screen  //
  //===============//
  private void Flow_HELP() {

  }

  //===================//
  //  Gameover screen  //
  //===================//
  private void Flow_GAMEOVER() {

  }

  //===============//
  //  Game screen  //
  //===============//


//----  Graphics engine  ---------------------------------------------------//

  private void Loaddatabase() {




    ///////////////////读配备文件

    InitGAMEimage(); ///////////////////地图初始化
///////////////////////////////////////////以下是本在配备文件中做的///////////////////////////

    //0生命  1X 2Y 3方向 4力量 5速度 6炸数.


  }

  private void ReadCPUPlaySet() {
    Toll_Gate = m_iLevel;
    String str = readfile(Toll_Gate, 0); ///////////得到文件内容
    int a[]  = new int[7];
    if (str.equals("filenull"))
    {
      StrErr = "Toll_Gate file Can't open";
    }
    else
    {
      String no = "";
      int k = str.length();
      int j = -1;
      for (int i = 0; i < k; i++)
      {
        char ch = str.charAt(i);
        if (ch == ',')
        {
          if (j == -1)
          { ///第一个放CPU数
            m_iCPUPlayNo = (byte) Integer.parseInt(no);
            System.out.println(m_iCPUPlayNo);
            M_iCPlay = new int[m_iCPUPlayNo][7];
          }
          //    if (j == -2)
          //     { ///怪物种类
          //       m_inocpu = (byte) Integer.parseInt(no);

          //     }
          else if (j / 7 == m_iCPUPlayNo)
          { //////////最后7个放玩家自己的信息
            a[j % 7] = (byte) Integer.parseInt(no);
          }
          else
          {
            M_iCPlay[j / 7][j % 7] = (byte) Integer.parseInt(no);
          }
          j = j + 1;
          no = "";
        }
        else
        {
          no = no + ch;
        }
      }
      for (j = 0; j < m_iCPUPlayNo; j++)
      {
        M_iCPlay[j][1] = M_iCPlay[j][1] << 4;
        M_iCPlay[j][2] = M_iCPlay[j][2] << 4;
      }
      M_iHPlay[0] = a[0];
      M_iHPlay[1] = a[1] << 4;
      M_iHPlay[2] = a[2] << 4;
      M_iHPlay[3] = a[3];
      for ( j = 4 ; j < 7 ; j++ )
      {
         if (  M_iHPlay[j] < a[j] )
           M_iHPlay[j] = a[j];

      }
    }
  }

  private void readmapSet() {
    String str = readfile(Toll_Gate, 1);
    if (str.equals("filenull"))
    {
      StrErr = "Toll_Gatemap file Can't open";
    }
    else
    {
      String no = "";
      int k = str.length();
      int j = -2;
      for (int i = 0; i < k; i++)
      {
        char ch = str.charAt(i);
        if (ch == ',')
        {
          if (j == -2)
          {
            m_imapnoW = Integer.parseInt(no);
          }
          else if (j == -1)
          {
            m_imapnoH = Integer.parseInt(no);
            M_imapno = new byte[m_imapnoH][m_imapnoW];
          }
          else
          {
            M_imapno[j / m_imapnoW][j %
                m_imapnoW] = (byte) (Integer.parseInt(no));
          }
          j = j + 1;
          no = "";
        }
        else
        {
          no = no + ch;
        }
      }
    }
  }

  private String readfile(int i, int type) {
    String filename = "";
    if (i <= 9 && type == 0)
    {
      filename = "/image/Toll_Gate" + "0" + i + ".png";
    }
    else if (i >= 10 && type == 0)
    {
      filename = "/image/Toll_Gate" + i + ".png";
    }
    else if (i <= 9 && type == 1)
    {
      filename = "/image/Toll_Gatemap" + "0" + i + ".png";
    }
    else if (i >= 10 && type == 1)
    {
      filename = "/image/Toll_Gatemap" + i + ".png";
    }
    try
    {
      byte[] buffer1 = new byte[1024];
      InputStream is = null;
      String buf = new String();
      is = this.getClass().getResourceAsStream(filename);
      while (is.read(buffer1) < 0)
      {}
      is.close();
      filename = new String(buffer1);
    }
    catch (Exception ex)
    {
      filename = "filenull";
    }
    return filename;
  }

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

  //==================================//
  //  Read content from record store  //
  //==================================//
  private static int ReadRecord() {
    ByteArrayInputStream pArray;
    DataInputStream pStream;
    RecordEnumeration pRecordID;
    RecordStore pRecord;
    int iID, i;
    byte[] bByte;


    iID = 0;
    try
    {
      //---------------------//
      //  Open record store  //
      //---------------------//

  //  RecordStore.deleteRecordStore(RMS_NAME);

    pRecord = RecordStore.openRecordStore(RMS_NAME, true);

       //pRecord.deleteRecord(1);


      //-----------------------------//
      //  Read record store content  //
      //-----------------------------//
      bByte = null;

      //  Get valid record id  //
      pRecordID = pRecord.enumerateRecords(null, null, true);
      i = pRecordID.numRecords();
      if (i > 0)
      {
        while (pRecordID.hasNextElement())
        { // ID in descending order
          iID = pRecordID.nextRecordId();
          bByte = pRecord.getRecord(iID);

          try
          {
            pArray = new ByteArrayInputStream(bByte);
            pStream = new DataInputStream(pArray);

            m_bSound = pStream.readBoolean();
            m_bVibrate = pStream.readBoolean();
            m_bAutoUpload = pStream.readBoolean();
            m_iGameLevel = pStream.readByte();
            m_iScore = pStream.readInt();
            m_iLive = pStream.readByte();

            System.out.println(m_iLive);
            m_iLevel = pStream.readByte();
            System.out.println(m_iLevel);
            m_sName = pStream.readUTF();
            m_sPhoneNo = pStream.readUTF();

            for (i = 0; i < MAX_RECORD; i++)
            {
              m_pName[i] = pStream.readUTF();
              m_pScore[i] = pStream.readInt();
              m_pLevel[i] = pStream.readByte();
            }
          }
          catch (IOException e)
          {
            System.out.println(e.toString());
          }
        }
      }
      else
      {
        //---------------------//
        //  Create new record  //
        //---------------------//
        iID = UpdateRecord(false);
      }

      //----------------------//
      //  Close record store  //
      //----------------------//
      pRecord.closeRecordStore();
    }
    catch (RecordStoreException e)
    {
      System.out.println(e.toString());
    }
    pRecord = null;
    return iID;
  }

  private static int UpdateRecord(boolean bUpdate) {
    ByteArrayOutputStream pArray;
    DataOutputStream pStream;
    RecordStore pRecord;
    byte[] bByte;
    int iID, i;

    //---------------------//
    //  Open record store  //
    //---------------------//
    iID = m_iRecordID;
    try
    {
      pRecord = RecordStore.openRecordStore(RMS_NAME, true);

      //----------------//
      //  Prepare data  //
      //----------------//
      pArray = new ByteArrayOutputStream();
      pStream = new DataOutputStream(pArray);

      try
      {
        pStream.writeBoolean(m_bSound);
        pStream.writeBoolean(m_bVibrate);
        pStream.writeBoolean(m_bAutoUpload);
        pStream.writeByte(m_iGameLevel);
        pStream.writeInt(m_iScore);
        pStream.writeByte(m_iLive);
        pStream.writeByte(m_iLevel);
        pStream.writeUTF(m_sName);
        pStream.writeUTF(m_sPhoneNo);

        for (i = 0; i < MAX_RECORD; i++)
        {
          pStream.writeUTF(m_pName[i]);
          pStream.writeInt(m_pScore[i]);
          pStream.writeByte(m_pLevel[i]);
        }
      }
      catch (IOException e)
      {
        System.out.println(e.toString());
      }

      if (bUpdate == false)
      {
        //--------------------//
        //  Add a new record  //
        //--------------------//
        bByte = pArray.toByteArray();
        try
        {
          iID = pRecord.addRecord(bByte, 0, bByte.length);
        }
        catch (RecordStoreException e)
        {
          System.out.println(e.toString());
        }
      }
      else
      {
        //--------------------------//
        //  Update existing record  //
        //--------------------------//
        bByte = pArray.toByteArray();
        try
        {
          pRecord.setRecord(iID, bByte, 0, bByte.length);
        }
        catch (RecordStoreException e)
        {
          System.out.println(e.toString());
        }
      }

      //----------------------//
      //  Close record store  //
      //----------------------//
      pRecord.closeRecordStore();
    }
    catch (RecordStoreException e)
    {
      System.out.println(e.toString());
    }
    pRecord = null;
    return iID;
  }

  //===================//
  //  Load and Del a PNG file  //
  //===================//
  private void DelImage(int start, int end) {

  }

  private void DelImage(int start) {

  }

  private void LoadImage(int start, int end) {

  }

  private static Image LoadImage(int iID) {
    String sString;
    sString = "image/monster";
    if (iID < 10)
    {
      sString += "0";
    }
    sString += "" + iID;
    return LoadImage("/" + sString + ".png");
  }

  private static Image LoadImage(String sImageFile) {
    Image pImage = null;
    try
    {
      pImage = Image.createImage(sImageFile);
    }
    catch (Exception e)
    {
      System.out.println("[CANVAS] Error loading image: " + sImageFile);
      System.out.println(e);
    }
    return pImage;
  }

  //=======================//
  //  Draw screen routine  //
  //=======================//

  private static void DrawBorderText(Graphics g, String sText, int iX, int iY,
                                     int iStyle) {
    if (sText == null || "".equals(sText))
    {
      return;
    }
    g.setColor(0xffffff);
    g.drawString(sText, iX - 1, iY, iStyle);
    g.drawString(sText, iX + 1, iY, iStyle);
    g.drawString(sText, iX, iY - 1, iStyle);
    g.drawString(sText, iX, iY + 1, iStyle);
    g.setColor(0x000000);
    g.drawString(sText, iX, iY, iStyle);
  }

//================//
  //  Screen paint  //
  //================//
  protected final void paint(Graphics g) {
    int i, j, iX, iY, iX2, iY2, iValue, iValue2;
    int iID, iDistance;
    String sValue, sValue2;
    boolean bFail;
    int diecpu= 0;
    Graphics pScreen;
    int k, l, iPercent, iFrame;

    //----------------------//
    //  Center game screen  //
    //----------------------//

    //--------------------//
    //  Loading graphics  //
    //--------------------//
    if (m_iStage >= STAGE_INIT && m_iStage < STAGE_MENU)
    {
      //  1st entry : Preload  //
      if (m_iStage == STAGE_INIT)
      {
        //  Clear full canvas  //
        g.setColor(0x505050);
        g.fillRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);

        //  Setup screen  //
        g.setFont(Font.getFont(Font.FACE_PROPORTIONAL,
                               Font.STYLE_PLAIN,
                               Font.SIZE_SMALL));
        DrawBorderText(g, TEXT_UI[0], (SCREEN_WIDTH - 4), (SCREEN_HEIGHT - 6),
                       (Graphics.RIGHT | Graphics.BOTTOM));

        //  Sometimes, m_pImage have not been allocated,  //
        //  so there is a checking to prevent exception.  //
        if (m_pImage != null)
        {
          m_pImage[IMG_MENU] = LoadImage( (byte) 25);
          m_iStage++;
          m_iCounter = 0;
          m_iImageLoaded = 1;

          //  Read setting and ranking data  //
          m_iRecordID = ReadRecord();
          m_icurScore = m_iScore;
          System.out.println("Level=" + m_iLeve

⌨️ 快捷键说明

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