什么是存储信息的口袋妖怪游戏类型的最佳方式? [英] What would be the best way to store information for a Pokemon type game?

查看:203
本文介绍了什么是存储信息的口袋妖怪游戏类型的最佳方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我开始做一个游戏一个学校项目。这是口袋妖怪的简化版本没有图形,只是文本。目前,我的问题是我不知道我怎么会存储所有的宠物小精灵的数据库(与每个统计),移动(与他们的统计数据),等等。

So I have started making a game for a school project. It is a simpler version of Pokemon without graphics, just text. Currently my problem is I do not know how I would store a database of all the Pokemon (with each individual stat), moves (with their stats), etc.

每个口袋妖怪(151不同)的统计数据和有关每个具体的信息,并在每次移动(100左右)有具体的统计数据和信息了。所以我真的不能使一个口袋妖怪类和151类,从其扩展。我能做的就是让口袋妖怪的数组,移动类和有一个宠物小精灵类的构造函数(或移动类)有统计数据。

Each Pokemon (151 different) has stats and specific info about each and each move (around 100) has specific stats and info too. So I can't really make a Pokemon class and 151 classes that extend from it. What I could do is make an array of Pokemon and Moves classes and have the constructor of a Pokemon class (or move class) have the stats.

我所遇到问题是搞清楚如何给宠物小精灵(让与皮卡丘卷)玩家(或者说我的敌人作战)和编辑统计,水平,经验,那等的有一个的口袋妖怪。我不想改变每皮卡丘的水平在游戏中,只是具体的皮卡丘对于玩家和敌人特定的宠物小精灵。这是否有意义?

What I am having trouble is figuring out how to give a Pokemon (lets roll with Pikachu) to the player (or enemy that I am battling) and edit the stats, level, experience, etc of that one Pokemon. I don't want to change the level of every Pikachu in the game, just a specific Pikachu for the player and a specific Pokemon for the enemy. Does that make sense?

我是新十岁上下Java和我不知道我会做什么。我见过一些人试图做同样的事情,人们推荐使用XML的东西?我试图让这一切在Java中。

I'm new-ish to Java and I'm not sure what I would do. I have seen some people try to do the same thing and people recommend using XML or something? I'm trying to keep it all within Java.

推荐答案

什么我有麻烦是搞清楚如何给宠物小精灵(让与皮卡丘辊)的播放器(或敌人,我争夺)和编辑统计,水平,经验,一个口袋妖怪等。我不想改变游戏中的每一个皮卡丘的水平,只为玩家和特定口袋妖怪敌人特定的皮卡丘。这是否化妆有意义吗?

那么你就会有一个宠物小精灵类的地方使用这些类型的字段:

Well you'll have a Pokemon class somewhere with these kinds of fields:

class PStats {
    int defense = 1;
    int attack = 1;
}

class Pokemon {
    int level = 1;
    long xp = 0;
    PStats stats = new PStats();
}

然后以某种方式决定的类型和口袋妖怪的潜在属性,无论你做口袋妖怪超类和子类,或有这些东西领域,从Java之外加载它们。

Then somehow you decide the type and potential attributes of the Pokemon, whether you make Pokemon a superclass and subclass it or have fields for these things and load them from outside Java.

那么你的球员将有您将访问一个ArrayList

Then your player will have an ArrayList that you will be accessing.

如果您希望玩家能够保存游戏并加载它们的神奇宝贝,你必须创造一个简单的文件格式和保存/每次加载。 DataOutputStream类和DataInputStream以有可能适合这个,如果你想保存混合类型没有做的所有格式为字节自己。

If you want the player to be able to save the game and load their Pokemon you'll have to invent a simple file format and save/load each time. DataOutputStream and DataInputStream are maybe suited to this if you want to save mixed types without doing all the formatting to bytes yourself.

作为一个例子,也许你有一个文件结构是这样的:

As an example maybe you have a file structure that looks like this:

header, UTF (8 bytes)     [FILE]
int, 4 bytes              [number of Pokemon]

1st Pokemon chunk id      [PKMN]
int, 4 bytes              [level]
long, 8 bytes             [experience]
                          [other fields...]

2nd Pokemon chunk id      [PKMN]
                          [level]
and so on...

在这里可以做一个简单的UTF头,像这样:

Where you can make a simple UTF header like so:

static final char[] PKMN {
    'P', 'K', 'M', 'N'
};

虽然通常页眉/场ID的ASCII码,你可以做到这一点与字节:

Though typically headers/field id are ASCII and you can do that with bytes:

static final byte[] PKMN {
    0x50, 0x4B, 0x4D, 0x4E
};

和文件头是任何你想要它是识别您的文件,所以你不依赖扩展。

And the FILE header is whatever you want it to be to identify your files so you don't rely on the extension.

当您想要将文件,你只会保存循环通过阵列和写田间地头到文件中。然后,当你想从一个文件加载你将有一个基本的结构是这样的:

When you want to save the file you will just loop through the array and write the fields to the file. Then when you want to load from a file you will have a basic structure something like this:

// read header and anything else you put at the start of the file

while (/*next bytes are the PKMN id*/) {
    Pokemon pToAdd = new Pokemon();

    pToAdd.level = dis.readInt();
    pToAdd.xp = dis.readLong();

    // and so on

    playerPokemon.add(pToAdd);
}

从什么文件指示创建的对象重塑一切玩家了。

Recreating everything the player has by creating the objects from what the file indicates.

如果你做这种方式,我建议在一张纸上勾画出你的文件结构,你拥有了它在你的面前,当你编写你的IO。

If you do it this way I'd recommend sketching out your file structure on a piece of paper so you have it in front of you when you are coding your IO.

这篇关于什么是存储信息的口袋妖怪游戏类型的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆