0

I'm guessing that the best way to do this is by using XML. Here's the issue, tho:

    Hero hero;
    PictureBox heroPB;
    Dictionary <string,Point> pokedex;
    Boss boss;
    PictureBox bossPB;
    Attack attack;
    PictureBox attackPB;
    HPMeter bossHP;
    PictureBox bossHPPB;
    PPMeter heroPP;
    PictureBox heroPPPB;

    System.Timers.Timer animateAttack;
    System.Timers.Timer animateBoss;
    System.Timers.Timer checkHit;
    System.Timers.Timer winFade;
    Thread tr;
    Rectangle bossRect;
    Rectangle attackRect;
    Panel whiteout;

    int heroState = 2;
    int stepRate = 5;
    int attackDirection;
    int attackLoop = 0;
    int contadorPaso = 0;
    int contadorPasoBoss = 0;
    int bossTop, bossLeft;
    int bossState = 6;
    int bossHealth = 0;
    int bossHPCap = 0;
    int opa = 0;
    int battlesWon = 0;
    int mainBossCounter = 0;
    int ppleft = 0;
    bool paso = false;
    bool inStadium = false;
    bool fading = true;
    bool fightingMainBoss = false;
    bool fainted;
    string currentPokemon = "";

    Rectangle[] frames;
    Rectangle[] entrances;
    PictureBox[] boundaries;
    Random r;
    Random eth;

    public delegate void BeginFade();
    BeginFade fade;

I have more than a few objects/primitives which are constantly changing. Is there an efficient way to serialize the whole thing and load it the next time the program runs?

4

1 回答 1

1

真的没有简单的方法来保存这些数据。我个人认为 XML 不是最好的途径。这对对象很好,对其他一切都不好。我更倾向于将其编写为带有“杂项”对象的 JSON,该对象具有所有单独的原语。实际上,我最倾向于制作自己的配置文件读取器/写入器并编写更像 csv 的东西。我工作地点的大多数配置文件至少有这么多数据。我们使用key=value所有的原语。每个对象都有自己的部分,其中它们的原语以key=value格式列出,列表将是key=value1,value2,value3. 我个人认为这是一种相当简单的做事方式,编写读写器类不会花费很长时间。事实上,从头开始制作一个简单的读取器/写入器可能比在 JSON 或 XML 序列化类之上构建一个更快。我真的没有看到这两种格式中的任何一种对你有多大好处。

于 2012-12-14T00:42:26.153 回答