nankin.zheng.gatem.view
Class RoleView

java.lang.Object
  |
  +--nankin.zheng.gatem.view.RoleView
Direct Known Subclasses:
BackgroundView

public abstract class RoleView
extends java.lang.Object

RoleView object saves all the image resources of a Role, and it is in charge of mapping a role's logical attributes to a certain appearance.

Version:
1.0, Date 2003-04-11
Author:
ZHENG Zhong

Field Summary
protected  AnchoredImage[] aImages
          All the image resources that will be needed while drawing a role.
private static int createdInstanceCount
           
protected  DisplayCache displayCache
          DisplayCache reference that accepts DrawCommand and helps drawing.
protected  Env env
          Environment
protected  java.lang.String roleName
          Role name.
 
Constructor Summary
RoleView(Env environ, DisplayCache dc, java.lang.String rname, AnchoredImage[] aimgs)
          Constructor, initialize image resources.
 
Method Summary
abstract  void draw(AttributeSet attrSet)
          Draw the role according to its logical attribute set.
static int getCreatedInstanceCount()
           
 java.lang.String getRoleName()
          Get role name.
 void testInitialization()
          Verify whether this object is initialized properly.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

createdInstanceCount

private static int createdInstanceCount

roleName

protected java.lang.String roleName
Role name.


env

protected Env env
Environment


aImages

protected AnchoredImage[] aImages
All the image resources that will be needed while drawing a role.


displayCache

protected DisplayCache displayCache
DisplayCache reference that accepts DrawCommand and helps drawing.

Constructor Detail

RoleView

public RoleView(Env environ,
                DisplayCache dc,
                java.lang.String rname,
                AnchoredImage[] aimgs)
         throws GameException
Constructor, initialize image resources.

Parameters:
environ - environment.
dc - DisplayCache, which will be used while drawing.
rname - role name.
aimgs - anchored image array.
Throws:
java.lang.NullPointerException - if any of the parameters is null.
GameException - may be thrown out by its subclasses.
Method Detail

getCreatedInstanceCount

public static int getCreatedInstanceCount()

getRoleName

public java.lang.String getRoleName()
Get role name.

Returns:
role name.

testInitialization

public void testInitialization()
                        throws GameException
Verify whether this object is initialized properly.

Before a game is started, all the role view objects should be initialized properly. This method verifies the initialization of the RoleView object. If it is not initialized properly, a GameException will be thrown out.

This method should be overwritten by its subclasses to provide more strict verification.

Throws:
GameException - while is not initialized properly

draw

public abstract void draw(AttributeSet attrSet)
                   throws GameException
Draw the role according to its logical attribute set.

It creates a DrawCommand object according to the role's logical attribute set, and pass this command to DisplayCache as following:

   DrawCommand cmd = createDrawCommandFromAttrSet(attrSet);
   displayCache.addToCache(cmd);
   

NOTE that all the DrawCommand objects are cached by DisplayCache object, and flushed to screen once every frame updating.

Parameters:
attrSet - role's logical attribute set.
Throws:
GameException - may be thrown out by its subclasses.