infpp.oceanlife
Class Ocean

java.lang.Object
  extended by infpp.oceanlife.Ocean
All Implemented Interfaces:
OceanInterface, java.io.Serializable

public class Ocean
extends java.lang.Object
implements OceanInterface, java.io.Serializable

Implements the constructor of oceans, the ocean objects and the addition and removal of ocean objects.

Author:
tdu, akue
See Also:
Serialized Form

Field Summary
private  int animationSpeed
          The sleep time for ocean object threads.
private  java.lang.String BubbleIconLocation
          The location of the icon to use for bubbles.
private  java.awt.Point ClickPosition
          The position of the last mouse click
private  int depth
          The width of the ocean.
private  java.lang.String FishIconLeftwardLocation
          The location of the icon to use if the fish swims leftward and is not highlighted.
private  java.lang.String FishIconRightwardLocation
          The location of the icon to use if the fish swims rightward and is not highlighted.
private  java.lang.String HighlightedBubbleIconLocation
          The location of the icon to use for highlighted bubbles.
private  java.lang.String HighlightedFishIconLeftwardLocation
          The location of the icon to use if the fish swims leftward and is highlighted.
private  java.lang.String HighlightedFishIconRightwardLocation
          The location of the icon to use if the fish swims rightward and is highlighted.
private  java.lang.String HighlightedPlantIconLocation
          The location of the icon to use for highlighted plants.
private  java.lang.String HighlightedStoneIconLocation
          The location of the icon to use for highlighted stones.
private  int numberOfHighlightedObjects
          Gives the number of currently highlighted objects.
private  java.awt.Color oceanBackgroundColor
          The ocean background colour
private  boolean oceanGUIRunning
          Indicates whether the GUI thread is currently running.
private  java.util.LinkedList<OceanObject> oceanObjects
          The linked list that holds the information about ocean objects.
private  java.lang.String[] OceanObjectStrings
          The types of ocean object available
private  java.lang.String OilBlobLocation
          The location of the icon to use for oil blobs.
private  boolean oilCatastrophe
          Indicates whether an oil catastrophe is happening.
private  java.lang.String PlantIconLocation
          The location of the icon to use for plants.
private  java.lang.String StoneIconLocation
          The location of the icon to use for stones.
private  int width
          The width of the ocean.
 
Constructor Summary
Ocean(int width, int depth, java.util.LinkedList<OceanObject> oceanObjects)
           
 
Method Summary
 void addOceanObject(OceanObject obj)
           
 boolean collisionDetected(OceanObject toAdd)
           
 int getAnimationSpeed()
           
 java.lang.String getBubbleIconLocation()
           
 int getClassIndex(OceanObject obj)
           
 java.awt.Point getClickPosition()
           
 int getDepth()
           
 java.lang.String getFishIconLeftwardLocation()
           
 java.lang.String getFishIconRightwardLocation()
           
 java.lang.String getHighlightedBubbleIconLocation()
           
 java.lang.String getHighlightedFishIconLeftwardLocation()
           
 java.lang.String getHighlightedFishIconRightwardLocation()
           
 java.lang.String getHighlightedPlantIconLocation()
           
 java.lang.String getHighlightedStoneIconLocation()
           
 int getNumberOfHighlightedObjects()
           
 int getObjectIndexFromClickPosition(java.awt.Point p)
           
 java.awt.Color getOceanBackgroundColor()
           
 java.util.LinkedList<OceanObject> getOceanObjects()
           
 java.lang.String[] getOceanObjectStrings()
           
 java.lang.String getOilBlobLocation()
           
 java.lang.String getPlantIconLocation()
           
 java.lang.String getStoneIconLocation()
           
 int getWidth()
           
 void highlight(OceanObject obj)
           
 void initialiseOceanObjects(java.util.LinkedList<OceanObject> oceanObjects)
           
 boolean isOceanGUIRunning()
           
 boolean isOilCatastrophe()
           
 boolean isPositionValid(OceanObject obj)
           
 void removeOceanObject(int x)
           
 void setAnimationSpeed(int animationSpeed)
           
 void setClickPosition(java.awt.Point clickPosition)
           
 void setDepth(int depth)
           
 void setFishIconLeftwardLocation(java.lang.String fishIconLeftwardLocation)
           
 void setFishIconRightwardLocation(java.lang.String fishIconRightwardLocation)
           
 void setHighlightedFishIconLeftwardLocation(java.lang.String highlightedFishIconLeftwardLocation)
           
 void setHighlightedFishIconRightwardLocation(java.lang.String highlightedFishIconRightwardLocation)
           
 void setNumberOfHighlightedObjects(int numberOfHighlightedObjects)
           
 void setOceanBackgroundColor(java.awt.Color oceanBackgroundColor)
           
 void setOceanGUIRunning(boolean oceanRunning)
           
 void setOceanObjectStrings(java.lang.String[] oceanObjectStrings)
           
 void setOilBlobLocation(java.lang.String oilBlobLocation)
           
 void setOilCatastrophe(boolean oilCatastrophe)
           
 void setWidth(int width)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

width

private int width
The width of the ocean.


depth

private int depth
The width of the ocean.


animationSpeed

private int animationSpeed
The sleep time for ocean object threads.


oceanObjects

private final java.util.LinkedList<OceanObject> oceanObjects
The linked list that holds the information about ocean objects.


oceanBackgroundColor

private java.awt.Color oceanBackgroundColor
The ocean background colour


oilCatastrophe

private boolean oilCatastrophe
Indicates whether an oil catastrophe is happening.


ClickPosition

private java.awt.Point ClickPosition
The position of the last mouse click


numberOfHighlightedObjects

private int numberOfHighlightedObjects
Gives the number of currently highlighted objects.


oceanGUIRunning

private boolean oceanGUIRunning
Indicates whether the GUI thread is currently running.


OceanObjectStrings

private java.lang.String[] OceanObjectStrings
The types of ocean object available


FishIconLeftwardLocation

private java.lang.String FishIconLeftwardLocation
The location of the icon to use if the fish swims leftward and is not highlighted.


FishIconRightwardLocation

private java.lang.String FishIconRightwardLocation
The location of the icon to use if the fish swims rightward and is not highlighted.


HighlightedFishIconLeftwardLocation

private java.lang.String HighlightedFishIconLeftwardLocation
The location of the icon to use if the fish swims leftward and is highlighted.


HighlightedFishIconRightwardLocation

private java.lang.String HighlightedFishIconRightwardLocation
The location of the icon to use if the fish swims rightward and is highlighted.


OilBlobLocation

private java.lang.String OilBlobLocation
The location of the icon to use for oil blobs.


StoneIconLocation

private java.lang.String StoneIconLocation
The location of the icon to use for stones.


HighlightedStoneIconLocation

private java.lang.String HighlightedStoneIconLocation
The location of the icon to use for highlighted stones.


BubbleIconLocation

private java.lang.String BubbleIconLocation
The location of the icon to use for bubbles.


HighlightedBubbleIconLocation

private java.lang.String HighlightedBubbleIconLocation
The location of the icon to use for highlighted bubbles.


PlantIconLocation

private java.lang.String PlantIconLocation
The location of the icon to use for plants.


HighlightedPlantIconLocation

private java.lang.String HighlightedPlantIconLocation
The location of the icon to use for highlighted plants.

Constructor Detail

Ocean

public Ocean(int width,
             int depth,
             java.util.LinkedList<OceanObject> oceanObjects)
      throws java.lang.Exception
Parameters:
width - width of the ocean
depth - depth of the ocean
oceanObjects - objects in the ocean
Throws:
java.lang.Exception
Method Detail

getFishIconLeftwardLocation

public java.lang.String getFishIconLeftwardLocation()
Returns:
The location of the icon to use if the fish swims leftward and is not highlighted.

getFishIconRightwardLocation

public java.lang.String getFishIconRightwardLocation()
Returns:
The location of the icon to use if the fish swims rightward and is not highlighted.

getHighlightedFishIconLeftwardLocation

public java.lang.String getHighlightedFishIconLeftwardLocation()
Returns:
The location of the icon to use if the fish swims leftward and is highlighted.

getHighlightedFishIconRightwardLocation

public java.lang.String getHighlightedFishIconRightwardLocation()
Returns:
The location of the icon to use if the fish swims rightward and is not highlighted.

setFishIconLeftwardLocation

public void setFishIconLeftwardLocation(java.lang.String fishIconLeftwardLocation)
Parameters:
fishIconLeftwardLocation - The location of the icon to use if the fish swims leftward and is not highlighted.

setFishIconRightwardLocation

public void setFishIconRightwardLocation(java.lang.String fishIconRightwardLocation)
Parameters:
fishIconRightwardLocation - The location of the icon to use if the fish swims rightward and is not highlighted.

setHighlightedFishIconLeftwardLocation

public void setHighlightedFishIconLeftwardLocation(java.lang.String highlightedFishIconLeftwardLocation)
Parameters:
highlightedFishIconLeftwardLocation - The location of the icon to use if the fish swims leftward and is highlighted.

setHighlightedFishIconRightwardLocation

public void setHighlightedFishIconRightwardLocation(java.lang.String highlightedFishIconRightwardLocation)
Parameters:
highlightedFishIconRightwardLocation - The location of the icon to use if the fish swims rightward and is highlighted.

getOilBlobLocation

public java.lang.String getOilBlobLocation()
Returns:
The location of the icon to use for oil blobs.

setOilBlobLocation

public void setOilBlobLocation(java.lang.String oilBlobLocation)
Parameters:
oilBlobLocation - The location of the icon to use for oil blobs.

toString

public java.lang.String toString()
Specified by:
toString in interface OceanInterface
Overrides:
toString in class java.lang.Object
Returns:
Returns a string of the status of the ocean including width, depth and objects.
See Also:
Object.toString()

getDepth

public int getDepth()
Specified by:
getDepth in interface OceanInterface
Returns:
Depth of the ocean.
See Also:
OceanInterface.getDepth()

isOceanGUIRunning

public boolean isOceanGUIRunning()
Returns:
Returns true if the thread of the OceanGUI is running.

setOceanGUIRunning

public void setOceanGUIRunning(boolean oceanRunning)
Parameters:
oceanRunning - a boolean indicating whether or not the GUI should run.

getAnimationSpeed

public int getAnimationSpeed()
Returns:
the animationSpeed

setAnimationSpeed

public void setAnimationSpeed(int animationSpeed)
Parameters:
animationSpeed - the animationSpeed to set

getWidth

public int getWidth()
Specified by:
getWidth in interface OceanInterface
Returns:
width of the ocean

setDepth

public void setDepth(int depth)
              throws java.lang.Exception
Specified by:
setDepth in interface OceanInterface
Parameters:
depth - the depth of the ocean to set
Throws:
exception - for negative value
java.lang.Exception - if the depth is negative

setWidth

public void setWidth(int width)
Specified by:
setWidth in interface OceanInterface
Parameters:
width - set the width of the ocean
Throws:
exception - for negative value

getOceanObjectStrings

public java.lang.String[] getOceanObjectStrings()
Returns:
the oceanObjectStrings

setOceanObjectStrings

public void setOceanObjectStrings(java.lang.String[] oceanObjectStrings)
Parameters:
oceanObjectStrings - the oceanObjectStrings to set

getOceanBackgroundColor

public java.awt.Color getOceanBackgroundColor()
Returns:
the oceanBackgroundColor

setOceanBackgroundColor

public void setOceanBackgroundColor(java.awt.Color oceanBackgroundColor)
Parameters:
oceanBackgroundColor - the oceanBackgroundColor to set

isOilCatastrophe

public boolean isOilCatastrophe()
Returns:
a boolean indicating whether an oil catastrophe is happening.

setOilCatastrophe

public void setOilCatastrophe(boolean oilCatastrophe)
Parameters:
oilCatastrophe - a boolean signalling an impending oil catastrophe

getStoneIconLocation

public java.lang.String getStoneIconLocation()
Returns:
The location of the icon to use for stones.

getHighlightedStoneIconLocation

public java.lang.String getHighlightedStoneIconLocation()
Returns:
The location of the icon to use for highlighted stones.

getBubbleIconLocation

public java.lang.String getBubbleIconLocation()
Returns:
The location of the icon to use for bubbles.

getHighlightedBubbleIconLocation

public java.lang.String getHighlightedBubbleIconLocation()
Returns:
The location of the icon to use for highlighted bubbles.

getPlantIconLocation

public java.lang.String getPlantIconLocation()
Returns:
The location of the icon to use for plants.

getHighlightedPlantIconLocation

public java.lang.String getHighlightedPlantIconLocation()
Returns:
The location of the icon to use for highlighted plants.

getOceanObjects

public java.util.LinkedList<OceanObject> getOceanObjects()
Specified by:
getOceanObjects in interface OceanInterface
Returns:
the objects in the ocean

getClickPosition

public java.awt.Point getClickPosition()
Returns:
the position of the last mouse click

setClickPosition

public void setClickPosition(java.awt.Point clickPosition)
Parameters:
clickPosition - the position of the last mouse click as reported by the GUI.

isPositionValid

public boolean isPositionValid(OceanObject obj)
Returns:
Returns true if the position of the ocean object is valid insofar as it is inside the ocean. Collision detection is not done here.

collisionDetected

public boolean collisionDetected(OceanObject toAdd)
Parameters:
toAdd - an oceanObject that should be added to the ocean.
Returns:
Returns true if the ocean object collides with another ocean object.

initialiseOceanObjects

public void initialiseOceanObjects(java.util.LinkedList<OceanObject> oceanObjects)
                            throws java.lang.Exception
Specified by:
initialiseOceanObjects in interface OceanInterface
Parameters:
oceanObjects - Sets ocean objects.
Throws:
java.lang.IllegalArgumentException - Throws exceptions for invalid ocean object positions.
java.lang.Exception - if something went wrong during the initialisation, such as objects being outside of the ocean.

getObjectIndexFromClickPosition

public int getObjectIndexFromClickPosition(java.awt.Point p)
Returns:
Returns the listIndex (in the linked list oceanObjects) of the ocean object on the given point in the ocean.

getClassIndex

public int getClassIndex(OceanObject obj)
Parameters:
obj - the ocean object whose type we wish to know
Returns:
an integer specifying the object type

highlight

public void highlight(OceanObject obj)
Parameters:
obj - the object to highlight or unhighlight.

getNumberOfHighlightedObjects

public int getNumberOfHighlightedObjects()
Returns:
the number of highlighted objects

setNumberOfHighlightedObjects

public void setNumberOfHighlightedObjects(int numberOfHighlightedObjects)
Parameters:
numberOfHighlightedObjects - the number of highlighted objects to set, should this be necessary in the future.

addOceanObject

public void addOceanObject(OceanObject obj)
                    throws java.lang.Exception
Specified by:
addOceanObject in interface OceanInterface
Parameters:
obj - the object to add
Throws:
java.lang.Exception - if the object cannot be added, eg due to a collision with an existing object or it being added outside of the ocean.

removeOceanObject

public void removeOceanObject(int x)
                       throws java.lang.Exception
Specified by:
removeOceanObject in interface OceanInterface
Parameters:
x - the list index of the object in question.
Throws:
java.lang.Exception - if no object exists at the given index.