SerializableKarel (KarelOOP2)
Retired DISLab
/* * Copyright 2020 Sangwon Park @ DISLab, HUFS */ package cp.java.ch11.io; import java.awt.Point; import java.io.IOException; import java.io.Serializable; import hufs.dislab.karel.SimpleKarel; /** * * @author Sangwon Park * @since KarelOOP 2 (2020.10.4) */ public class SerializableKarel extends SimpleKarel implements Serializable { /** * */ private static final long serialVersionUID = 1L; private void writeObject(java.io.ObjectOutputStream out) throws IOException { Point pt = getLocation(); int dir = getDirection(); int beepers = getBeepersInBag(); out.writeInt(pt.x); out.writeInt(pt.y); out.writeInt(dir); out.writeInt(beepers); } private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException { int x = in.readInt(); int y = in.readInt(); int dir = in.readInt(); int beepers = in.readInt(); setLocation(x, y); setDirection(dir); setBeepersInBag(beepers); } }