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

📄 player.java

📁 liu7788414
💻 JAVA
字号:
package staticdata;

/**
 * <p>Title: Reader.java</p>
 * <p>Description: read and convert xml file</p>
 * <p>Copyright: Gameloft 2004</p>
 * <p>Company: Gameloft Shanghai</p>
 * @author Yi Wen Hu
 * @version 1.0
 */

import javax.xml.parsers.*;
import org.w3c.dom.*;

import java.util.Vector;
import java.io.*;

public class Player {
  public String m_name;
  private int m_id;
  private int m_power;
  private int m_precision;
  private int m_rotation;
  private int m_mentation;
  private int m_ballIndex;
  private int m_modelIndex;
  private String m_ballTraceFile;
  private int m_ballStepsCount;
  private int[][] m_ballPos;
  private int[][] m_ballRot;

  private int m_actionCount;
  private Action[] m_actions;
  private String[] m_cloths;
  //Qiu Li add, 2005/2/2
  private short[] m_decor;
  //Qiu Li

  public Player(Element e) {
    m_id = Integer.valueOf(e.getAttribute(Reader.XML_PLAYER_ID)).intValue();
    m_name = e.getAttribute(Reader.XML_PLAYER_NAME);
    m_power = Integer.valueOf(e.getAttribute(Reader.XML_PLAYER_POWER)).intValue();
    m_precision = Integer.valueOf(e.getAttribute(Reader.XML_PLAYER_PRECISION)).
        intValue();
    m_rotation = Integer.valueOf(e.getAttribute(Reader.XML_PLAYER_ROTATION)).
        intValue();

//    String m_ms=e.getAttribute(Reader.XML_PLAYER_MENTATION);
//    m_mentation = Reader.getIndexOfString(Reader.XML_PLAYER_MENTATION,Reader.XML_PLAYER_MENTATION,e)
    int t = Reader.getIndexOfString(e.getAttribute(Reader.XML_PLAYER_MENTATION),
                                    Reader.XML_PLAYER_MENTATION_VALUE);
    if (t >= 0)
      m_mentation = t;

    m_ballIndex = Integer.valueOf(e.getAttribute(Reader.XML_PLAYER_BALL)).
        intValue();
    m_modelIndex = Integer.valueOf(e.getAttribute(Reader.XML_PLAYER_MODEL)).
        intValue();

    m_ballTraceFile = e.getAttribute(Reader.XML_PLAYER_BALLTRACE);
    if (m_ballTraceFile.trim().length() != 0)
      ReadTraceFile(m_ballTraceFile);

    NodeList list = e.getElementsByTagName(Reader.XML_ACTIONTABLE);
    m_actionCount = list.getLength();

    m_actions = new Action[m_actionCount];

    for (int i = 0; i < m_actionCount; i++)
      m_actions[i] = new Action( (Element) list.item(i));

    list = e.getElementsByTagName(Reader.XML_PLAYER_CLOTH);
    if (list == null)
    {
      m_cloths = null;
      //Qiu Li add, 2005/2/2
      m_decor = null;
      //Qiu Li end
    }
    else {
      m_cloths = new String[list.getLength()];
      //Qiu Li add, 2005/2/2
      m_decor = new short[list.getLength()];
      //Qiu Li end

      for (int i = 0; i < m_cloths.length; i++)
      {
        m_cloths[i] = ( (Element) list.item(i)).getAttribute(Reader.
            XML_PLAYER_CLOTH_FILENAME);
        //Qiu Li add, 2005/2/2
        if( ( (Element) list.item(i)).hasAttribute(Reader.XML_PLAYER_DECOR_FLAG))
          m_decor[i] = Integer.valueOf( ( (Element) list.item(i)).getAttribute(
              Reader.XML_PLAYER_DECOR_FLAG)).shortValue();
        else
          m_decor[i] = 0;
        //Qiu Li end
      }
    }

  }

  public void save(FileOutputStream fos) {
    int count;
    byte[] data;
    try {
      // name
      Reader.WriteString(m_name, fos);

      // power
      Reader.WriteShort( (short) m_power, fos);

      // precision
      Reader.WriteShort( (short) m_precision, fos);

      // rotation
      Reader.WriteShort( (short) m_rotation, fos);

      // mentation
      Reader.WriteShort( (short) m_mentation, fos);

      // model index
      fos.write( (byte) m_modelIndex);

      // ball index
      fos.write( (byte) m_ballIndex);

      // ball trace info
      Reader.WriteShort( (short) m_ballStepsCount, fos);
      for (int i = 0; i < m_ballStepsCount; i++) {
        for (int j = 0; j < 3; j++)
          Reader.WriteInt(m_ballPos[i][j], fos);

        for (int j = 0; j < 3; j++)
          Reader.WriteInt(m_ballRot[i][j], fos);
      }

      // action count
      Reader.WriteInt(m_actionCount, fos);
      for (int i = 0; i < m_actionCount; i++)
        m_actions[i].save(fos);

      if (m_cloths == null)
        Reader.WriteInt(0, fos);
      else {
        Reader.WriteInt(m_cloths.length, fos);
        for (int i = 0; i < m_cloths.length; i++)
        {
          Reader.WriteString(m_cloths[i], fos);
          //Qiu Li add, 2005/2/2
          Reader.WriteShort(m_decor[i], fos);
          //Qiu Li end
        }
      }


    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }



  public void test() {
    System.out.print("player:");
    System.out.print("m_id=" + m_id);
    System.out.print(",m_name=" + m_name);
    System.out.print(",m_power=" + m_power);
    System.out.print(",m_precision=" + m_precision);
    System.out.print(",m_rotation=" + m_rotation);
    System.out.print(",m_mentation=" + m_mentation);
    System.out.print(",m_ballIndex=" + m_ballIndex);
    System.out.println(",m_modelIndex=" + m_modelIndex);
    System.out.println(",m_ballTraceFile=" + m_ballTraceFile);
    System.out.println(",m_ballStepsCount=" + m_ballStepsCount);

    for (int i = 0; i < m_ballStepsCount; i++) {
      for (int j = 0; j < 3; j++)
        System.out.print(m_ballPos[i][j] + ",");
      for (int j = 0; j < 3; j++)
        System.out.print(m_ballRot[i][j] + ",");
    }

    for (int i = 0; i < m_actions.length; i++) {
      m_actions[i].test();
    }
  }



  private void ReadTraceFile(String filename) {
    try {
      FileInputStream fis = new FileInputStream(filename);
      int charsCount = fis.available();
      String context = "";
      for (int i = 0; i < charsCount; i++)
        context += (char) fis.read();

      context.trim();
      String[] lines = context.split("\n");
      m_ballStepsCount = 0;
      // ignore fisrt line
      for (int i = 1; i < lines.length; i++)
        if (lines[i].trim().length() != 0)
          m_ballStepsCount++;

      m_ballPos = new int[m_ballStepsCount][3];
      m_ballRot = new int[m_ballStepsCount][3];
      String[] tmpStrings;

      int count = 0;
      // ignore fisrt line
      for (int i = 1; i < lines.length; i++) {
        if (lines[i].trim().length() == 0)continue;
        String[] items = lines[i].split(";");
        if (items.length < 2)continue;

        tmpStrings = items[0].split(",");
        for (int j = 0; j < 3; j++)
          m_ballPos[count][j] = Integer.valueOf(tmpStrings[j].trim()).intValue();

        tmpStrings = items[1].split(",");
        for (int j = 0; j < 3; j++)
          m_ballRot[count][j] = Integer.valueOf(tmpStrings[j].trim()).intValue();

        count++;
      }
    }
    catch (Exception e) {
      e.printStackTrace();
    }

  }

  public class Action {
    public int m_start;
    public int m_end;
    public int m_interval;
    public int m_keep;

    public Action(Element e) {
      String str;
      str = e.getAttribute(Reader.XML_ACTIONTABLE_START);
      if (str.length() != 0)
        m_start = Integer.valueOf(str).intValue();

      str = e.getAttribute(Reader.XML_ACTIONTABLE_END);
      if (str.length() != 0)
        m_end = Integer.valueOf(str).intValue();

      str = e.getAttribute(Reader.XML_ACTIONTABLE_INTERVAL);
      if (str.length() != 0)
        m_interval = Integer.valueOf(str).intValue();

      str = e.getAttribute(Reader.XML_ACTIONTABLE_KEEP);
      if (str.length() != 0)
        m_keep = Integer.valueOf(str).intValue();

    };

    public void save(FileOutputStream fos) {
      Reader.WriteInt(m_start, fos);
      Reader.WriteInt(m_end, fos);
      Reader.WriteInt(m_interval, fos);
      Reader.WriteInt(m_keep, fos);
    };

    public void test() {
      System.out.println("start=" + m_start);
      System.out.println("end=" + m_end);
      System.out.println("interval=" + m_interval);
      System.out.println("keep=" + m_keep);
    };

  }

}

⌨️ 快捷键说明

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