|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--nankin.zheng.gatem.model.Role
This class represents a logical role who lives and acts inside a game container.
Field Summary | |
protected AttributeSet |
attrSet
Role's logical attribute set. |
protected GameContainer |
container
GameContainer is in charge of the communication with other roles. |
private static int |
createdInstanceCount
|
protected Env |
env
Env is the environment of the game. |
protected RoleView |
view
RoleView is in charge of drawing. |
Constructor Summary | |
Role(GameContainer gcont,
Env environ,
RoleView v)
Constructor. |
Method Summary | |
abstract void |
act()
Role's action rules. |
void |
draw()
Ask its RoleView object to draw the role itself. |
static int |
getCreatedInstanceCount()
|
void |
init(Position pos,
int dir,
int sts)
Initialize a role object. |
abstract void |
receiveGameEvent(GameEvent gevt)
This method tries a GameEvent, decides whether to accept it or not, and if yes, take actions accordingly. |
void |
testInitialization()
Verify whether this object is initialized properly. |
java.lang.String |
toString()
Convert to String. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
private static int createdInstanceCount
protected RoleView view
protected GameContainer container
protected Env env
protected AttributeSet attrSet
Constructor Detail |
public Role(GameContainer gcont, Env environ, RoleView v) throws GameException
gcont
- game container, cannot be null.environ
- game environment, cannot be null.v
- RoleView object, cannot be null.
java.lang.NullPointerException
- if any of the parameters is null.
GameException
- exception may be thrown out by its subclasses.Method Detail |
public static int getCreatedInstanceCount()
public void init(Position pos, int dir, int sts)
pos
- position, cannot be nulldir
- directionsts
- status
java.lang.NullPointerException
- if pos is null.
(thrown from AttributeSet.setPosition(pos))public void testInitialization() throws GameException
NOTE that this method will call RoleView.testInitialization(), which means that its RoleView's proper initailization is the necessary condition of its proper initialization.
This method is called before game starts.
GameException
- if this role is not initialized properly.public abstract void act() throws GameException
This method is called by GameContainer during every frame-updating. It describes the behaviour of a role, but it does NOT draw the role.
GameException
- exception may be thrown out by its subclasses.public void draw() throws GameException
This method is called by GameContainer during every frame-updating. It asks its RoleView object to draw itself onto screen. But it does NOT change the role's attributes. It gives its attribute set to its RoleView object.
NOTE that in a special game container, if AttributeSet is extended to provide more complex role attribute set, this method MUST be overwritten, to pass the new XAttributeSet instance to the Role's View object.
GameException
- may be thrown out by its view.public abstract void receiveGameEvent(GameEvent gevt) throws GameException
Role a.receiveGameEvent(...) may be called by its GameContainer, while some other role fires a game event and the GameContainer broadcasts it. a.receiveGameEvent(...) may also be called by Role b, while b receives an event from a, gets a reference of a from the event, and reacts to it.
gevt
- game event that it receives.
GameException
- may be thrown out by its subclasses.public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |