de.unifreiburg.twodeedoo.model
Class CompositeActor

java.lang.Object
  extended by de.unifreiburg.twodeedoo.model.CompositeActor
All Implemented Interfaces:
ICompositeActor, IActivity, IKeyHandler, ISchedulable

public class CompositeActor
extends java.lang.Object
implements IActivity, ICompositeActor

Simple Composite of IActors.


Field Summary
 
Fields inherited from interface de.unifreiburg.twodeedoo.view.ISchedulable
NULL_OBJECT
 
Fields inherited from interface de.unifreiburg.twodeedoo.view.IKeyHandler
NULL_OBJECT
 
Constructor Summary
CompositeActor(IScene scene)
          Create instance
 
Method Summary
 void addActor(IActor actor)
          Add an actor, becoming its container.
 IScene getScene()
          Getter for scene.
 void keyPressed(int keyCode, IGameController controller)
          Dispatch to the actor which likes that key
 void keyReleased(int keyCode, IGameController controller)
          Dispatch to the actor which likes that key
 int minimalTimeSlice()
          Do not call me more often than with this many ms between two runs.
 void removeActor(IActor actor)
          Remove this actor from the actor set.
 boolean run(int elapsedTimeMillis, IGameController controller)
          Let all the contained actors run.
 void setScene(IScene scene)
          Setter for scene.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompositeActor

public CompositeActor(IScene scene)
Create instance

Parameters:
scene - the scene for new puppets
Method Detail

run

public boolean run(int elapsedTimeMillis,
                   IGameController controller)
Let all the contained actors run. Follow their wishes for removal.

Specified by:
run in interface ISchedulable
Parameters:
elapsedTimeMillis - elapsed time since last run in ms
controller - to stop the game or switch activities
Returns:
true: this should be run again, false: finished, don't call again.

addActor

public void addActor(IActor actor)
Add an actor, becoming its container.

Actors which are already in this activity are not added again; this call becomes a noop then.

Specified by:
addActor in interface ICompositeActor
Parameters:
actor - an actor

removeActor

public void removeActor(IActor actor)
Remove this actor from the actor set. After that, I will no longer be its container.

(Think twice before using this method from the outside; usually, an actor should decide itself when he stops acting.)

Specified by:
removeActor in interface ICompositeActor
Parameters:
actor - The actor to remove. Its container will be reset iff the actor was in this activity.

setScene

public void setScene(IScene scene)
Setter for scene.

Parameters:
scene - a scene, non-null.

getScene

public IScene getScene()
Getter for scene.

Returns:
the scene.

keyPressed

public void keyPressed(int keyCode,
                       IGameController controller)
Dispatch to the actor which likes that key

Specified by:
keyPressed in interface IKeyHandler
Parameters:
keyCode - a code from KeyEvent, e.g. KeyEvent.VK_LEFT
controller - TODO

keyReleased

public void keyReleased(int keyCode,
                        IGameController controller)
Dispatch to the actor which likes that key

Specified by:
keyReleased in interface IKeyHandler
Parameters:
keyCode - a code from KeyEvent, e.g. KeyEvent.VK_LEFT
controller - TODO

minimalTimeSlice

public int minimalTimeSlice()
Description copied from interface: IActivity
Do not call me more often than with this many ms between two runs.

Specified by:
minimalTimeSlice in interface IActivity
Returns:
millisecond delay