org.globalse.arena.frag.objects
Class FRAGObject

java.lang.Object
  |
  +--org.globalse.arena.frag.objects.FRAGObject
Direct Known Subclasses:
Adventurer, Item, Landscape, MissionXML, Tile

public abstract class FRAGObject
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable

FRAGObject is the abstract superclass for creating and dealing with entities in the game; entities are e.g. Adventurers, Items (sword, spell, parts of the landscape). It contains general object state information and methods for state update management. In order to create/implement an entity, FRAGObject has to be subclassed. To specify custom behavior and functionality, some methodes needs to be implemented, and some variables needs to be overwritten, which are specified later in this text. Modified objects can only be detected, when the changes are done during handling an ObjectActionEvent (e.g. PickUpItemEvent or TimerEvent). Detection of changes are done by the ObjectManager, which broads them. It's very important, that subclasses of FRAGObject never reference to e.g. any other subclass of FRAGObject or to not unserializable object (e.g. ObjectManager, GameManager, any object from the visualisation package). This reference would be followed by the serialization algorithm of java, and therefore these objects would also be broadcasted on every state update or an Exception during serialization would occur. To bypass the reference probleme, other FRAGObjects can simply be stored as strings and obtained from the ObjectManager, which can be accessed by, as well as the GameManager, the getter methods in FRAGObject. controlAccquired and controLost methods: When a peer accquires control over a FRAGObject this methode is called. To create independently (from the player) moving objects or objects with a static speed (as done in Adventurer), timers, which are subclasses of ObjectActionEvent, should be set on this object. Timer send periodically ObjectActionEvents and the corresponding object can act. To set a timer on an object the getTimer() methode of TimerRegistry should be called and after that, the enable method from timer. The oppositional way need to be done in controlLost, where the disable method of the timer need to be called. checkCollision This method is used to avoid collisions of objects or to climb mountains. In abstraction it is used to interact with other objects. It is called, when one object changes its position on all other objects and returns the distance the moved object is allowed to go. The simplest way to keep objects from running over other objects, is to use a sphere (as done in SWORD), that can't be crossed from others. As the landscape is divided into tiles, which are FRAGObjects, these objects should keep other objects from running over water. draw Each FRAGObject needs to specify, what and where it should be drawn. This methode is called periodically from the DrawManager. To draw the object methods from DrawManager need to be used (e.g. drawImage or drawArea). actionEvent This method is called when an ObjectActionEvent (or a subclass) addressed to this object arrives at the ObjectManager. As mentioned before, changes to a FRAGObject are only noticed, when done during this method and the mark method is called at the end of the method. To control e.g. the Adventurer, comands from the GUI should be passed to it by using ObjectActionEvents. Now let's face to the attributs and there use. The gameName and objectName need to be set at initialization. The objectName need to be unique in the game and objects are stored in the ObjectManager's hashtable with the key: objectName The owner attribute is just set, when an object is owned by a peer (e.g. Adventurer) and other peers aren't allowed to take over control. In order to manipulate an object the peer needs to be the controller of that object. The visibiltyRange should indicate, the distance this object can be seen. Maybe the most important variable is the influenceRange. When a peer is in this range and it is not yet controlled by another peer, it takes over control. For further ideas look at the implemented subclasses of FRAGObject: Adventurer, Item in the engine package.

See Also:
Serialized Form

Field Summary
 java.lang.String controller
           
 java.lang.String gameName
           
protected  double influenceRange
           
 java.lang.String objectName
           
 java.lang.String owner
           
protected  MathVector position
          member for the position for the object.
protected  double visibilityRange
           
 
Constructor Summary
FRAGObject()
           
 
Method Summary
abstract  void actionEvent(ObjectActionEvent event)
          Processes the ObjectActionEvents that the ObjectManager receives for this object.
 boolean checkAndResetMark()
          Returns a boolean value, wether the object data was modified and sets the new status to false.
abstract  MathVector checkCollision(java.lang.String other, MathVector oldPos, MathVector delta)
          Called whenever another object has changed its position to allow the current object to react.
 boolean checkMark()
          Returns a boolean value, wether the object data was modified.
 java.lang.Object clone()
          Returns a copy of the object data
 void controlAcquired()
          Called whenever the current peer has acquired control over the object.
 void controlLost()
          Called when the peer decides or is forced to release control over an object.
 void draw(DrawManager drawManager)
          THIS METHOD MUST BE IMPLEMENTED FROM THE REAL OBJECT E.G.
 GameManager getGameManager()
          Returns the GameManager of the current game.
 double getInfluenceRange()
          Returns the actual InfluenceRange 0 for none and MAX_VALUE for all
 ObjectManager getObjectManager()
          Returns the ObjectManager of the current game.
 java.lang.String getObjectName()
          returns the name of the object as string
 MathVector getPosition()
          Returns a copy of the coordinates of the object.
 void killed()
          Called when the object is killed.
 void mark()
          Increments the version number.
 boolean newerVersion(FRAGObject other)
          Checks if the passed FRAGObject is newer than this object.
 void setInfluenceRange(double d)
          Sets the actual InfluenceRange of the Object
 void setPosition(MathVector position)
          Sets the coordinates of the object.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

gameName

public java.lang.String gameName

objectName

public java.lang.String objectName

owner

public java.lang.String owner

controller

public java.lang.String controller

visibilityRange

protected double visibilityRange

influenceRange

protected double influenceRange

position

protected MathVector position
member for the position for the object.
Constructor Detail

FRAGObject

public FRAGObject()
Method Detail

clone

public java.lang.Object clone()
Returns a copy of the object data
Returns:
copy of the object data
Overrides:
clone in class java.lang.Object

mark

public void mark()
Increments the version number. This must be called after class variables have been modified.

checkMark

public boolean checkMark()
Returns a boolean value, wether the object data was modified.
Returns:
boolean value, if the data was modified

checkAndResetMark

public boolean checkAndResetMark()
Returns a boolean value, wether the object data was modified and sets the new status to false.
Returns:
boolean value, if the data was modified

newerVersion

public boolean newerVersion(FRAGObject other)
Checks if the passed FRAGObject is newer than this object.
Parameters:
other - FRAGObject object to check
Returns:
True if passed FRAGObject is newer

getGameManager

public GameManager getGameManager()
Returns the GameManager of the current game.
Returns:
the GameManager of the current game
See Also:
GameManager

getObjectManager

public ObjectManager getObjectManager()
Returns the ObjectManager of the current game.
Returns:
the ObjectManager of the current game
See Also:
ObjectManager

getPosition

public MathVector getPosition()
Returns a copy of the coordinates of the object.
Returns:
the coordinates of the object

setPosition

public void setPosition(MathVector position)
Sets the coordinates of the object. Calling this method is only allowed to the ObjectManager, specifically the actionEvent handling part of its processEvent method.
Parameters:
position - MathVector new position of the object.

controlAcquired

public void controlAcquired()
Called whenever the current peer has acquired control over the object.

controlLost

public void controlLost()
Called when the peer decides or is forced to release control over an object.

checkCollision

public abstract MathVector checkCollision(java.lang.String other,
                                          MathVector oldPos,
                                          MathVector delta)
Called whenever another object has changed its position to allow the current object to react.
Parameters:
other - the name of the FRAGObject that changed its position
oldPos - the old Position (instanceOf MathVector)
delta - the delta vector, that the other instance has moved
Returns:
MathVector returns a correction vector for the object which is then the actual position. This method must be implemented from the game.

actionEvent

public abstract void actionEvent(ObjectActionEvent event)
Processes the ObjectActionEvents that the ObjectManager receives for this object.
Parameters:
event - the event, that took place

killed

public void killed()
Called when the object is killed.

draw

public void draw(DrawManager drawManager)
THIS METHOD MUST BE IMPLEMENTED FROM THE REAL OBJECT E.G. DRAWCIRCLE
Parameters:
drawManager - INSTANCE OF DRAWMANAGER .

getObjectName

public java.lang.String getObjectName()
returns the name of the object as string
Returns:
String returns the name of the object.

setInfluenceRange

public void setInfluenceRange(double d)
Sets the actual InfluenceRange of the Object
Parameters:
d - The Influence Range: 0 for none and MAX_VALUE for all

getInfluenceRange

public double getInfluenceRange()
Returns the actual InfluenceRange 0 for none and MAX_VALUE for all
Returns:
double returns the influence range.



This page is hosted by the Chair for Applied Software Engineering of the Technische Universität München.
Imprint (Impressum)