public class Ocean extends java.lang.Object implements OceanInterface, java.io.Serializable
Modifier and Type | Class and Description |
---|---|
class |
Ocean.EmptyListException
The Class EmptyListException.
|
static class |
Ocean.PositionOccupiedException
The Class PositionOccupiedException.
|
static class |
Ocean.PositionOutOfBoundsException
The Class PositionOutOfBoundsException.
|
Modifier and Type | Field and Description |
---|---|
private int |
age
The ocean's age.
|
private int |
animationDelay
The delay between to steps of the animation.
|
static int |
BUBBLE
The Constant BUBBLE.
|
static int |
COKE_CAN
The Constant COKE_CAN.
|
private int |
depth
The ocean's depth.
|
static int |
FISH
The Constant FISH.
|
private boolean |
isOceanRunning
Says whether or not the ocean is running.
|
private MovementThread |
mt
The ocean's movement thread.
|
private java.util.LinkedList<OceanObject> |
newObjects
Holds the objects that are added to the ocean after all the collisions have been dealt with.
|
private static int |
OceanObjectID
The Ocean object id.
|
private java.util.LinkedList<OceanObject> |
oceanObjects
The ocean's object list.
|
static java.util.LinkedList<OceanObject> |
oceanObjectTypes
The Constant oceanObjectTypes.
|
static int |
PLANT
The Constant PLANT.
|
private static long |
serialVersionUID
The Constant serialVersionUID.
|
static int |
SHARK
The Constant SHARK.
|
static int |
STONE
The Constant STONE.
|
private int |
width
The ocean's width.
|
Constructor and Description |
---|
Ocean(int width,
int depth)
Instantiates a new ocean.
|
Ocean(int width,
int depth,
java.util.LinkedList<OceanObject> oceanObjects)
Instantiates a new ocean.
|
Modifier and Type | Method and Description |
---|---|
private void |
addNewlySpawnedObjectsToOcean(java.util.LinkedList<OceanObject> newObjects)
Adds the newly spawned objects to ocean.
|
void |
addOceanObject(OceanObject obj)
This method adds the given object to the list.
|
java.lang.Boolean |
contains(OceanObject o)
This method checks the ocenObjectList; is the given object in the list?
|
int |
getAge()
Gets the ocean's age.
|
int |
getAnimationDelay()
Gets the ocean's animation delay.
|
int |
getDepth()
Gets the ocean's depth.
|
MovementThread |
getMovementThread()
Gets the movementThread.
|
java.util.LinkedList<OceanObject> |
getNewObjects()
Gets the new objects.
|
int |
getNumberOfOceanObjects()
Gets the number of ocean objects.
|
int |
getNumberOfOceanObjectsByType(int type)
Returns the number of the special objects in the ocean.
|
int |
getNumberOfOceanObjectswithoutBubbles()
Gets the number of ocean objects without bubbles.
|
java.util.LinkedList<OceanObject> |
getOceanObjects()
Returns the list of all oceanObjects.
|
Pair<java.lang.Integer,java.lang.Integer> |
getStatusPanelInfo()
The method is a helper for the statusPanel.
|
int |
getWidth()
Gets the width.
|
void |
incAge()
Increase the ocean's age.
|
boolean |
isOceanRunning()
Checks if the ocean is running.
|
java.lang.Boolean |
load(java.lang.String path,
java.io.File name)
Load a saved ocean.
|
private void |
makeNewThreadsForCokeCans()
Make new threads for coke cans after they have been loaded.
|
static int |
makeOOID()
Make the oceanObject's ID.
|
void |
move()
This method moves all the ocean's objects.
|
java.lang.Boolean |
positionOccupied(OceanObject o)
Determines whether the position of the object o is occupied
(i.e. whether the object o can be added there).
|
private void |
processStalledCollisions(java.util.LinkedList<Pair<OceanObject,OceanObject>> collisions)
This method deals with all the collisions that have occurred between ocean objects.
|
void |
removeAllDeadObjects()
Removes all the dead objects from the ocean.
|
void |
removeAllObjects()
This method removes all objects from the OceanObjectList.
|
void |
removeAllTaggedObjects()
This method removes all tagged objects from the OceanObjectList.
|
void |
removeOceanObject(OceanObject o)
This method removes a specific object from the OceanObjectList.
|
private void |
removeThreadsFromCokeCans()
Removes the threads from the coke cans.
|
java.lang.Boolean |
save(java.lang.String path,
java.io.File name)
This method saves an ocean to a file.
|
void |
setAge(int age)
Sets the ocean's age.
|
void |
setAnimationDelay(int animationDelay)
Sets the animation delay.
|
void |
setDepth(int depth)
Sets the depth.
|
void |
setMovementThread(MovementThread movementThread)
This method sets the movement thread
|
void |
setNewObjects(java.util.LinkedList<OceanObject> newObjects)
Sets the new objects.
|
void |
setOceanObjects(java.util.LinkedList<OceanObject> oceanObjects)
This method sets the ocean object list.
|
void |
setOceanRunning(boolean isRunning)
Sets the ocean running.
|
void |
setWidth(int width)
Sets the width.
|
void |
start()
This method starts the movement.
|
void |
stop()
This method stops the movement, all objects in the list freeze in the
current position.
|
java.lang.String |
toString()
Generates a textual representation of the ocean.
|
public static final int BUBBLE
public static final int COKE_CAN
public static final int FISH
private static int OceanObjectID
public static final java.util.LinkedList<OceanObject> oceanObjectTypes
public static final int PLANT
private static final long serialVersionUID
public static final int SHARK
public static final int STONE
private int age
private int animationDelay
private int depth
private boolean isOceanRunning
private MovementThread mt
private java.util.LinkedList<OceanObject> newObjects
private java.util.LinkedList<OceanObject> oceanObjects
private int width
public Ocean(int width, int depth)
width
- the ocean's widthdepth
- the ocean's depthpublic Ocean(int width, int depth, java.util.LinkedList<OceanObject> oceanObjects)
width
- the ocean's widthdepth
- the ocean's depthoceanObjects
- the ocean objectspublic int getAge()
public int getAnimationDelay()
getAnimationDelay
in interface OceanInterface
public int getDepth()
getDepth
in interface OceanInterface
public MovementThread getMovementThread()
getMovementThread
in interface OceanInterface
public java.util.LinkedList<OceanObject> getNewObjects()
public int getNumberOfOceanObjects()
public int getNumberOfOceanObjectsByType(int type)
getNumberOfOceanObjectsByType
in interface OceanInterface
type
- the object's typepublic int getNumberOfOceanObjectswithoutBubbles()
public java.util.LinkedList<OceanObject> getOceanObjects()
getOceanObjects
in interface OceanInterface
public Pair<java.lang.Integer,java.lang.Integer> getStatusPanelInfo()
getStatusPanelInfo
in interface OceanInterface
public int getWidth()
getWidth
in interface OceanInterface
public void incAge()
public boolean isOceanRunning()
isOceanRunning
in interface OceanInterface
public void setAge(int age)
age
- the new agepublic void setAnimationDelay(int animationDelay)
setAnimationDelay
in interface OceanInterface
animationDelay
- the animationDelay to setpublic void setDepth(int depth)
setDepth
in interface OceanInterface
depth
- the new depthpublic void setMovementThread(MovementThread movementThread)
OceanInterface
setMovementThread
in interface OceanInterface
movementThread
- the movement thread to setpublic void setNewObjects(java.util.LinkedList<OceanObject> newObjects)
newObjects
- the newObjects to setpublic void setOceanObjects(java.util.LinkedList<OceanObject> oceanObjects)
OceanInterface
setOceanObjects
in interface OceanInterface
oceanObjects
- the list of all OceanObjects in the ocean.public void setOceanRunning(boolean isRunning)
isRunning
- the new ocean runningpublic void setWidth(int width)
setWidth
in interface OceanInterface
width
- the new widthprivate void addNewlySpawnedObjectsToOcean(java.util.LinkedList<OceanObject> newObjects) throws java.lang.Exception
newObjects
- the new objectsOcean.PositionOccupiedException
- if the position is occupiedOcean.PositionOutOfBoundsException
- if the position is out of boundsjava.lang.Exception
public static int makeOOID()
public void addOceanObject(OceanObject obj) throws Ocean.PositionOccupiedException, Ocean.PositionOutOfBoundsException
addOceanObject
in interface OceanInterface
obj
- the object to be addedOcean.PositionOccupiedException
- if the position is occupiedOcean.PositionOutOfBoundsException
- if the position is out of boundspublic java.lang.Boolean contains(OceanObject o)
contains
in interface OceanInterface
o
- public java.lang.Boolean load(java.lang.String path, java.io.File name)
load
in interface OceanInterface
path
- the load locationname
- of the saved fileprivate void makeNewThreadsForCokeCans()
public void move() throws java.lang.Exception
OceanInterface
move
in interface OceanInterface
java.lang.Exception
- hands exception received from the
addNewlySpawnedObjects() method to the controllerpublic java.lang.Boolean positionOccupied(OceanObject o)
OceanInterface
positionOccupied
in interface OceanInterface
o
- an ocean object to be addedprivate void processStalledCollisions(java.util.LinkedList<Pair<OceanObject,OceanObject>> collisions)
collisions
- the collisionspublic void removeAllDeadObjects()
public void removeAllObjects()
OceanInterface
removeAllObjects
in interface OceanInterface
public void removeAllTaggedObjects() throws Ocean.EmptyListException
OceanInterface
removeAllTaggedObjects
in interface OceanInterface
Ocean.EmptyListException
- if no objects have been selected for removal.public void removeOceanObject(OceanObject o)
OceanInterface
removeOceanObject
in interface OceanInterface
o
- the ocean object to be removedprivate void removeThreadsFromCokeCans()
public java.lang.Boolean save(java.lang.String path, java.io.File name)
OceanInterface
save
in interface OceanInterface
path
- the location to save the ocean atname
- the file name for the oceanpublic void start()
OceanInterface
start
in interface OceanInterface
public void stop()
OceanInterface
stop
in interface OceanInterface
public java.lang.String toString()
toString
in class java.lang.Object