ppJava.serie04.oceanlife
Class OceanObject

java.lang.Object
  extended by ppJava.serie04.oceanlife.OceanObject
All Implemented Interfaces:
java.io.Serializable, java.lang.Runnable
Direct Known Subclasses:
Bubble, Fish, Plant, Stone

public abstract class OceanObject
extends java.lang.Object
implements java.lang.Runnable, java.io.Serializable

Objects in the Ocean

Author:
bpei,ken
See Also:
Serialized Form

Field Summary
private  java.util.concurrent.CyclicBarrier barrier
           
private  int[] borders
           
private  javax.swing.ImageIcon imageIcon
           
private  java.lang.String imagePath
           
private  int imageSize
           
private  int[] moveVector
           
private static int objectCount
           
private  int[] offset
           
private  int[] position
           
private static long serialVersionUID
           
 
Constructor Summary
OceanObject()
          Constructor for an Object, increases the object Count
 
Method Summary
 int calcAbsDistance(int[] pos1, int[] pos2)
          Calculate the distance between two positions
 void changeDirections(OceanObject tempRefObject)
          Change the direction in which to move of the object
 void checkBarrier()
           
 void checkPosition(Ocean ocean)
          Check if the position is in the Ocean
protected  javax.swing.ImageIcon createImageIcon(java.lang.String path, java.lang.String description)
          Returns an ImageIcon, or null if the path was invalid.
 int[] genRandomVector()
          Generates a random vector for moving
 java.util.concurrent.CyclicBarrier getBarrier()
           
 int[] getBorders()
          Return the borders in which the object is allowed to move
 java.lang.String getClassName()
           
 int[] getDiffVector(int[] position)
          Calculate the difference of the X- and Y-Values of two positions
 int getDistance(int[] position)
          Get the Distance to a position
 javax.swing.ImageIcon getImageIcon()
          Return the Image to the object
 java.lang.String getImageResource()
          Return the path of the Image to the Object
 int getImageSize()
          Return the size of the Image to the Object
 int[] getMoveVector()
          Return the move vector of the object
static int getObjectCount()
          Get the object count
 int[] getOffset()
          Return the width and the height of the object
 int[] getPosition()
          get the position of an object
 boolean hasSameDirection(OceanObject tempRefObject)
          Have two objects the same X-direction?
 void incPosX(int i)
          Increase the X-Value of the position by i
 void incPosY(int i)
          Increase the Y-Value of the position by i
 boolean isVulnerableTo(OceanObject tempRefObject)
          Can an object be eaten by another object?
 void moveStep()
          Make one step in movement
 void normalizeImage()
          Resizes the sprite of oceanObject
 void setBarrier(java.util.concurrent.CyclicBarrier barrier)
           
 void setBorders(int[] borders)
          Sets the borders in which the object is allowed to move
 void setImageIcon(javax.swing.ImageIcon image)
          Sets the Image to the object
 void setImageResource(java.lang.String imageResource)
          Set the path of the Image to the Object
 void setImageSize(int imageSize)
          Sets the size of the Image
 void setMoveVector(int[] moveVector)
          Sets the move vector of the object
 void setOffset(int[] offset)
          Sets the width and the height of the object
 void setPosition(int[] position)
          Sets the position of an object
 void switchMovementDirection(int[] signs)
          Switch the direction in which to move
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.lang.Runnable
run
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

position

private int[] position

moveVector

private int[] moveVector

borders

private int[] borders

offset

private int[] offset

objectCount

private static int objectCount

barrier

private transient java.util.concurrent.CyclicBarrier barrier

imagePath

private java.lang.String imagePath

imageIcon

private javax.swing.ImageIcon imageIcon

imageSize

private int imageSize
Constructor Detail

OceanObject

public OceanObject()
Constructor for an Object, increases the object Count

Method Detail

getClassName

public java.lang.String getClassName()

genRandomVector

public int[] genRandomVector()
Generates a random vector for moving

Returns:
a random vector for moving

checkBarrier

public void checkBarrier()

getObjectCount

public static int getObjectCount()
Get the object count

Returns:
the object count

getPosition

public int[] getPosition()
get the position of an object

Returns:
the position of an object

setPosition

public void setPosition(int[] position)
Sets the position of an object

Parameters:
position -

incPosX

public void incPosX(int i)
Increase the X-Value of the position by i

Parameters:
i -

incPosY

public void incPosY(int i)
Increase the Y-Value of the position by i

Parameters:
i -

switchMovementDirection

public void switchMovementDirection(int[] signs)
Switch the direction in which to move

Parameters:
signs - of the movement before switching

getDistance

public int getDistance(int[] position)
Get the Distance to a position

Parameters:
position -
Returns:
the distance to a position

calcAbsDistance

public int calcAbsDistance(int[] pos1,
                           int[] pos2)
Calculate the distance between two positions

Parameters:
pos1 -
pos2 -
Returns:
the distance between two positions

getDiffVector

public int[] getDiffVector(int[] position)
Calculate the difference of the X- and Y-Values of two positions

Parameters:
position -
Returns:
the difference of the X- and Y-Values of two positions

checkPosition

public void checkPosition(Ocean ocean)
                   throws OceanException
Check if the position is in the Ocean

Parameters:
ocean -
Throws:
OceanException - - if the position is not in the Ocean

moveStep

public void moveStep()
Make one step in movement


changeDirections

public void changeDirections(OceanObject tempRefObject)
Change the direction in which to move of the object

Parameters:
tempRefObject -

hasSameDirection

public boolean hasSameDirection(OceanObject tempRefObject)
Have two objects the same X-direction?

Parameters:
tempRefObject -
Returns:
true if they move in the same X-direction

isVulnerableTo

public boolean isVulnerableTo(OceanObject tempRefObject)
Can an object be eaten by another object?

Parameters:
tempRefObject -
Returns:
true if it can be eaten

createImageIcon

protected javax.swing.ImageIcon createImageIcon(java.lang.String path,
                                                java.lang.String description)
Returns an ImageIcon, or null if the path was invalid. (source: oracle)


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

setImageResource

public void setImageResource(java.lang.String imageResource)
Set the path of the Image to the Object

Parameters:
imageResource -

getImageResource

public java.lang.String getImageResource()
Return the path of the Image to the Object

Returns:
the path of the Image to the Object

setMoveVector

public void setMoveVector(int[] moveVector)
Sets the move vector of the object

Parameters:
moveVector -

getMoveVector

public int[] getMoveVector()
Return the move vector of the object

Returns:
the move vector of the object

setBorders

public void setBorders(int[] borders)
Sets the borders in which the object is allowed to move

Parameters:
borders -

getBorders

public int[] getBorders()
Return the borders in which the object is allowed to move

Returns:
the borders in which the object is allowed to move

setOffset

public void setOffset(int[] offset)
Sets the width and the height of the object

Parameters:
offset -

getOffset

public int[] getOffset()
Return the width and the height of the object

Returns:
the width and the height of the object

normalizeImage

public void normalizeImage()
Resizes the sprite of oceanObject


setImageIcon

public void setImageIcon(javax.swing.ImageIcon image)
Sets the Image to the object

Parameters:
image -

getImageIcon

public javax.swing.ImageIcon getImageIcon()
Return the Image to the object

Returns:
the Image to the object

getImageSize

public int getImageSize()
Return the size of the Image to the Object

Returns:
the size of the Image to the Object

setImageSize

public void setImageSize(int imageSize)
Sets the size of the Image

Parameters:
imageSize -

setBarrier

public void setBarrier(java.util.concurrent.CyclicBarrier barrier)
Parameters:
barrier - the barrier to set

getBarrier

public java.util.concurrent.CyclicBarrier getBarrier()
Returns:
the barrier