megabobik
JGO n00b  Posts: 12
|
 |
«
on:
2012-02-05 10:06:04 » |
|
Hi people ! i have a problem with this class. I use class Pedestrian for creating units of different types, it inherited from class Unit ,what describe vehicles and units. PTD is ingame "dictionary" of units, but actually I want to use it for creating "dictionaries" on hdd. As you can see i tried use ObjectOutputStream/ObjectInputStream , IDe said:"Nope". So how i can serialize it? Unit 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| import java.io.Serializable; import org.newdawn.slick.Image;
abstract class Unit implements Serializable { protected String uName; protected String uSpecName; protected String uRace; protected String uType; protected Image uActiveImage; protected String uActiveImageDest; protected Image uNorImage; protected String uNorImageDest; protected Image uSelImage; protected String uSelImageDest; protected String uComment; protected boolean uChosen=false; protected boolean uMoved; protected boolean uAttacked; protected int uFormCoordX; protected int uFormCoordY; protected int uCurCoordX; protected int uCurCoordY; protected String uAttacker; protected String uDefender; Unit() { } } |
Pedestrian 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| import java.io.IOException; import java.io.Serializable; import org.newdawn.slick.Image; import org.newdawn.slick.Input; import org.newdawn.slick.MouseListener; import org.newdawn.slick.SlickException; import org.newdawn.slick.util.pathfinding.Mover;
public class Pedestrian extends Unit implements Serializable, Mover { private boolean pRunned=false; private int pWS; private int pBS; private int pS; private int pT; private int pW; private int pI; private int pA; private int pLD; private int pSV; private int pNSW; private Weapon pActiveWeapon; Pedestrian () { } Pedestrian (String name,String type,String race,String image,String selimage,int pws,int pbs,int ps,int pt,int pw,int pi,int pa,int pld,int psv,int pnsw ) throws SlickException { uName=name; uRace=race; uType=type; uNorImageDest=image; uSelImageDest=selimage; uNorImage=new Image(uNorImageDest); uSelImage=new Image(uSelImageDest); pWS=pws; pBS=pbs; pS=ps; pT=pt; pW=pw; pI=pi; pA=pa; pLD=pld; pSV=psv; pNSW=pnsw; } Pedestrian (String name,String type,String race,String image,String selimage,int pws,int pbs,int ps,int pt,int pw,int pi,int pa,int pld,int psv,int pnsw,int cordX,int cordY) throws SlickException { uName=name; uRace=race; uType=type; uNorImage=new Image(image); uSelImage=new Image(selimage); pWS=pws; pBS=pbs; pS=ps; pT=pt; pW=pw; pI=pi; pA=pa; pLD=pld; pSV=psv; pNSW=pnsw; uCurCoordX=cordX; uCurCoordY=cordY; }
} |
PTD 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.ArrayList; import java.util.List; import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; import org.newdawn.slick.SlickException;
public class PTD { protected Pedestrian warior; protected Tech mahina; protected Weapon gun; protected List<Pedestrian> street = new ArrayList(); protected List<Tech> warfare = new ArrayList(); protected List<Weapon> weaponry = new ArrayList(); PTD() throws SlickException, FileNotFoundException, IOException, ClassNotFoundException { chuvak = new Pedestrian("Fire Warrior", "Pedestrian", "Tau Empire", "Resources/Graphic/Tau/Firewarrior.png", "Resources/Graphic/Tau/FirewarriorSel.png", 2, 3, 5, 4, 2, 2, 2, 8, 2, 0); street.add(chuvak); FileOutputStream fos = new FileOutputStream("tau.Infantry"); GZIPOutputStream gzos = new GZIPOutputStream(fos); ObjectOutputStream out = new ObjectOutputStream(fos); out.writeObject(warior); out.flush(); out.close(); FileInputStream fis = new FileInputStream("tau.Infantry"); GZIPInputStream gzis = new GZIPInputStream(fis); ObjectInputStream in = new ObjectInputStream(fis); Pedestrian gelezen_veld = (Pedestrian)in.readObject(); in.close(); } |
|