" , 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 - , , , .
, . , , :
while () {
Pokemon pToAdd = new Pokemon();
pToAdd.level = dis.readInt();
pToAdd.xp = dis.readLong();
playerPokemon.add(pToAdd);
}
, , , .
, , , IO.