What would be the best way to store information for a game like Pokemon?

So, I started making a game for a school project. This is a simpler version of Pokemon without graphics, just text. Currently my problem is that I do not know how I will store the entire Pokemon database (with each individual status), moves (with statistics), etc.

Each Pokemon (151 others) has statistics, and specific information about each and every move (about 100) has certain statistics and information. Therefore, I cannot make a Pokemon class and a 151 class that extends from it. I could make an array of Pokemon and Moves classes and have a Pokemon class constructor (or move the class) with statistics.

I'm having problems with how to give Pokemon (let's roll with Pikachu) to the player (or the enemy I'm fighting) and edit statistics, level, experience, etc. this pokemon. I do not want to change the level of each Pikachu in the game, just a specific Pikachu for the player and a specific Pokemon for the enemy. It makes sense?

I'm new to Java and I'm not sure what I would do. I saw some people try to do the same, and people recommend using XML or something else? I am trying to save all this in Java.

+4
source share
6 answers

A very simple solution would be (pseudocode)

class Pokemon:
   String name
   String/int... other_stats
   Array<Move> moves // This is a simple strategy to store any moves 
                     // you want to associate with this pokemon.

class Move:
   String name
   int power
   [...other move stats...]

Pokemon , Pokemon (, "Pikachu" ), "Move", Pokemon. , :

ArrayList<Move> moves = new ArrayList<Move>();
moves.add( new Move("Thunderbolt", 16) );
moves.add( new Move("Foobar", 10) );
Pokemon pikachu = new Pokemon( "Pikachu", moves )
// and now you can give pikachu to any player you want.

- , , ​​ .

, toString, JSON/XML, .

. , , .

+1

" , Pokemon ( pikachu) ( , ), , , .. ONE Pokemon. , . ?"

, Pokemon :

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

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

- Pokemon, Pokemon Java.

ArrayList, .

, Pokemon, / . DataOutputStream DataInputStream, , , , .

, , , :

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 :

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

/ ASCII, :

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

FILE - , , , .

, . , , :

// 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);
}

, , , .

, , , IO.

+1

, . , . , . .

, , . . , pokemon, .

, , , . , Move, . , , , ( , , ), info , . , , , .

0

Pikachu.

Pikachu, , , , , .. , . .

, " ", Pikachu, , .

, .

(, .)

0

strategy, abstract factory 3 .

, , . , . .

, , , Vistor.

. . factory.

0

, , 2D Pokemon Archon. . , , .

1. , , Pokemon, , , hp, , , .

2: ( ) Pokemon, id. JDBC . :

public enumeration PokeId{
    Pikachu(),
    Mew(),
    Ditto();
}

public class Pokemon{

   private PokeId id;

   public Pokemon(PokeId id){
      this.id = id;
      if(id == PokeId.Pikachu){
         //load from derby

      }
   }

}

, . , , , . !

0

All Articles