import java.util.*; public class Shot extends GameItem implements Cloneable { public static final double DEFAULT_RADIUS = 0.03; public static final double SHOT_DURATION = 3.0; public static final double SHOT_DAMAGE = 0.27; public long createTime; public Integer id; public Shot(Integer id, long createTime, double x, double y) { this.id = id; this.createTime = createTime; this.radius = DEFAULT_RADIUS; this.x = x; this.y = y; this.dx = 0; this.dy = 0; } public Shot clone() { Shot s = new Shot(id, createTime, x, y); s.dx = dx; s.dy = dy; return s; } public boolean equals(Shot other) { return this.createTime == other.createTime && this.radius == other.radius && this.x == other.x && this.y == other.y && this.dx == other.dx && this.dy == other.dy; } public String toString() { return String.format("%d:%.3f:%.3f:%.3f:%.3f:%.3f", id, radius, x, y, dx, dy); } public void fromString(String s) { StringTokenizer st = new StringTokenizer(s, ":"); Vector tokens = new Vector(); while (st.hasMoreTokens()) { tokens.add(st.nextToken()); } String[] arr = tokens.toArray(new String[1]); if (arr.length != 6) return; id = Integer.parseInt(arr[0]); radius = Double.parseDouble(arr[1]); x = Double.parseDouble(arr[2]); y = Double.parseDouble(arr[3]); dx = Double.parseDouble(arr[4]); dy = Double.parseDouble(arr[5]); } }