package games; import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; /// Base class for all game elements. public abstract class Visible implements Cloneable { private int _x; private int _y; // Make clone() public without a not-supported exception // (_all_ Visibles are cloneable) public Object clone() { try { return super.clone(); } catch (CloneNotSupportedException e) { // Should never happen: throw new InternalError(e.toString()); } } /// Draws the Visible on the given graphics context. public abstract void draw(Graphics g); /// Does any automatic movement/periodic action for the Visible. /// Returns true iff Visible should remain in the Game. public boolean doAction(Game g) {return true;} /// Moves the Visible to a specific point public void moveTo(int x, int y) {_x = x; _y = y;} /// Retrieve X coordinate of Visible public int getX() {return _x;} /// Retrieve Y coordinate of Visible public int getY() {return _y;} }