public class PhysObject extends Object implements Comparable<Object>
Modifier and Type | Field and Description |
---|---|
private boolean |
animated
Robots are animated.
|
private boolean |
cliff
An object that represents a hole that the robots could potentially fall into.
|
private Color |
color
The fill color of the object.
|
private boolean |
corporeal
An object that can activate the robot's bump sensors and through which a robot can't move.
|
private boolean |
deleted
Signals that this object's
exit() method has been called. |
protected Environment |
env
A reference to the environment.
|
private boolean |
labeled
True causes the object to be labeled when it's drown.
|
private boolean |
movable
An object that will move it's bumped.
|
private String |
name
The name of the object.
|
private boolean |
paint
An object that represents paint on the floor.
|
private boolean |
persistent
If persistent is set to true, this object is saved when you exit CASA normally.
|
private Shape |
shape
The Shape of the object.
|
(package private) static Double |
twoPI
Just a constant because it's used so much in this class
|
private boolean |
vWall
An object that represents the field of a virtual wall.
|
private int |
zOrder
The Z-order.
|
Constructor and Description |
---|
PhysObject(String s)
Constructs a PhysObject from a sting that was produced by
toString() . |
PhysObject(String name,
Shape shape)
Convenience constructor: calls
PhysObject(name, shape, color=random, persistent=true, animated=false) . |
PhysObject(String name,
Shape shape,
Color color,
boolean persistent,
boolean animated) |
Modifier and Type | Method and Description |
---|---|
boolean |
allowMovement(PhysObject obj,
Shape from,
Shape to)
Meant to indicate whether an object can be moved by an impact with another object or not.
|
int |
compareTo(Object o)
The compareTo operator help maintain the Z-order, so it first compares the
Z-order, and then the name.
|
void |
draw(Graphics2D g)
Draws this object (it's shape with the fill color) on the graphics surface.
|
boolean |
equals(Object obj)
Overrides the default equals method to be compatible with
compareTo(Object) . |
void |
exit() |
double |
getAngle() |
int |
getAngleDeg() |
Color |
getColor() |
String |
getName() |
Shape |
getShape() |
static String |
getShowHeader() |
int |
getWidth() |
long |
getX() |
long |
getY() |
int |
getZOrder() |
boolean |
hasExited() |
boolean |
isAnimated() |
boolean |
isCliff() |
boolean |
isCorporeal() |
boolean |
isLabeled() |
boolean |
isMovable() |
boolean |
isPaint() |
boolean |
isPersistent() |
boolean |
isVWall() |
void |
moveTo(int x,
int y) |
static Double |
normalizeAngle(Double angle) |
protected void |
processMouseEvent(MouseEvent e) |
protected void |
processMouseMoveEvent(MouseEvent e) |
void |
replace(String header,
byte[] buffer) |
void |
replace(String header,
byte[] buffer,
String title,
String value) |
void |
setAnimated(boolean animated)
An animated object must have it's Z-order between -100 and 100, so it it's not already in that range, it's set to 0 if animated is set to true.
|
void |
setCliff(boolean cliff)
A cliff object must have it's Z-order less than -99, so it it's not already in that range, it's set to -100.
|
void |
setColor(Color color) |
void |
setCorporeal(boolean corporeal)
A corporeal object must have it's Z-order between -100 and 100, so it it's not already in that range, it's set to 0 if corporeal is set to true.
|
void |
setLabeled(boolean labeled) |
void |
setMovable(boolean movable)
A movable object os also an animated object and a corporeal object.
|
void |
setName(String name)
Since name is used by
compareTo(Object) , it can't be changed easily: this method will unregister this object, change the name, then re-register it to ensure it gets placed in the environment's data structures correctly. |
void |
setPaint(boolean paint) |
void |
setPersistent(boolean persistent)
An animated object will never persist, so this setting is ignored for animated objects.
|
void |
setShape(Shape shape) |
void |
setVWall(boolean vw) |
void |
setZOrder(int order)
Since name is used by
compareTo(Object) , it can't be changed easily: this
method will unregister this object, change the name, then re-register it to ensure
it gets placed in the environment's data structures correctly. |
String |
show() |
String |
toString()
Creates a String that can be used with the
PhysObject(String) constructor
to recreate this object later. |
static final Double twoPI
private String name
compareTo(Object)
method.private int zOrder
compareTo(Object)
method, and is important in drawing
and animating the environment correctly.private Shape shape
protected Environment env
Environment.getInstance()
method.private Color color
private boolean persistent
private boolean animated
private boolean corporeal
private boolean movable
private boolean cliff
private boolean paint
private boolean vWall
private boolean labeled
private boolean deleted
exit()
method has been called.public PhysObject(String name, Shape shape, Color color, boolean persistent, boolean animated) throws Exception
name
- the object nameshape
- it's shapecolor
- it's colorpersistent
- if set true, the object will be saved when you exit CASA normallyanimated
- true for robotsException
- If a instance of the Environment can't be foundpublic PhysObject(String name, Shape shape) throws Exception
PhysObject(name, shape, color=random, persistent=true, animated=false)
.name
- the object nameshape
- it's shapeException
- If a instance of the Environment can't be foundpublic PhysObject(String s) throws Exception
toString()
. Used
bye CASA's persistence system.s
- the string created by a call to toString()
.Exception
public static String getShowHeader()
public String show()
public void replace(String header, byte[] buffer)
protected void processMouseEvent(MouseEvent e)
protected void processMouseMoveEvent(MouseEvent e)
public String toString()
PhysObject(String)
constructor
to recreate this object later. Used by CASA's persistence system.toString
in class Object
Object.toString()
public Shape getShape()
public String getName()
public void setName(String name) throws InstantiationException
compareTo(Object)
, it can't be changed easily: this method will unregister this object, change the name, then re-register it to ensure it gets placed in the environment's data structures correctly.name
- The new name of the objectInstantiationException
public int getZOrder()
public void setZOrder(int order) throws InstantiationException
compareTo(Object)
, it can't be changed easily: this
method will unregister this object, change the name, then re-register it to ensure
it gets placed in the environment's data structures correctly. In addition, there
are restrictions on Z-order numbers: Cliff objects need to have a zOrder
less than -99. Corporial objects
between -99 and +99. Other non-corporial objects greater than 99. The Z-order
is used in the compareTo(Object)
method, and is important in drawing
and animating the environment correctly. The Z-order will be adjusted
to -100, 0, or 100 if they don't conform to their types.order
- the new Z-order number.InstantiationException
public boolean isLabeled()
public void setLabeled(boolean labeled)
labeled
- the labeled to setpublic Color getColor()
public void setColor(Color color)
color
- public boolean isPersistent()
public void setPersistent(boolean persistent)
persistent
- true if this object will persistpublic boolean isAnimated()
public void setAnimated(boolean animated)
animated
- public boolean isCorporeal()
public boolean isMovable()
public void setCorporeal(boolean corporeal)
corporeal
- true to make this object corporealpublic void setMovable(boolean movable)
movable
- true to make the object movable.public void setVWall(boolean vw)
public boolean isVWall()
public boolean isCliff()
public void setCliff(boolean cliff)
cliff
- public void setShape(Shape shape)
shape
- public int compareTo(Object o)
compareTo
in interface Comparable<Object>
obj
- the object to compare with.Comparable.compareTo(java.lang.Object)
public boolean equals(Object obj)
compareTo(Object)
.equals
in class Object
obj
- the object to compare with.compareTo(Object)
is equal to 0.Object.equals(java.lang.Object)
public void draw(Graphics2D g)
g
- the graphics surface to draw to.public boolean isPaint()
public void setPaint(boolean paint)
paint
- the paint to setpublic boolean allowMovement(PhysObject obj, Shape from, Shape to)
obj
- the object requesting the move.from
- the old position of the requesting object.to
- the proposed new position of the requesting object.public long getX()
public long getY()
public double getAngle()
public int getAngleDeg()
getAngle()
.public int getWidth()
public void exit()
public boolean hasExited()
exit()
method has been called.