|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--nankin.zheng.gatem.model.StageLoader
StageLoader loads a new stage and reinitialize the game.
It creates all the RoleView objects while it is constructed. While loading a new stage, it reads the stage matrix (in .gsm format, which stands for Gatem Stage Matrix), creates Role objects according to the matrix, and then adds all these objects into the game container. It may also update the game background image.
NOTE: this class is planned to be rewritten using Apache Jakarta Commons Digester package.
Field Summary | |
protected BackgroundView |
bgView
BackgroundView reference. |
protected GameContainer |
container
Game container. |
protected Controller |
controller
Controller. |
protected DisplayCache |
displayCache
Display cache, which is needed while creating RoleView objects. |
protected Env |
env
Game environment, which contains some common variables. |
protected java.util.Vector |
roleViews
RoleView vector. |
protected java.lang.String |
stageBgimage
Current stage background image file name. |
protected java.lang.String |
stageDesc
Current stage description. |
protected int |
stageId
Current stage Id. |
protected java.lang.String |
stageName
Current stage name. |
protected DOMTree |
stages
stages contains a DOM tree, each of whose children represents a stage. |
Constructor Summary | |
StageLoader(Env environ,
DisplayCache dc,
GameContainer c,
Controller ctrl,
java.lang.String fname)
Constructor, sets data members and creates RoleView objects. |
Method Summary | |
private AnchoredImage |
createAnchoredImage(DOMTree aimgTree,
java.lang.String basedir)
Create one AnchoredImage object from a DOMTree like |
private AnchoredImage[] |
createAnchoredImageArray(DOMTree imgsTree,
java.lang.String basedir)
Create one AnchoredImage array from a DOMTree like |
private RoleView |
createRoleView(DOMTree rvTree)
Create one RoleView object from a DOMTree like |
protected RoleView |
getRoleView(java.lang.String rname)
Get a RoleView object from its vector roleViews by role name. |
boolean |
hasNextStage()
Whether there are more stages. |
void |
loadNextStage()
Load next stage. |
protected abstract void |
loadStageData(java.io.InputStream fin)
Load a stage data file and create Role objects according to it. |
protected abstract RoleView |
newRoleViewInstance(java.lang.String rname,
AnchoredImage[] aimgs)
Create a RoleView object according to the role name and image file names. |
void |
readStageScript(java.lang.String fname)
Read the stage script (in xml format) and generate a DOM tree from it. |
void |
reloadStage()
Reload this stage. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected Env env
protected DisplayCache displayCache
protected GameContainer container
protected Controller controller
protected java.util.Vector roleViews
protected BackgroundView bgView
protected DOMTree stages
protected int stageId
protected java.lang.String stageName
protected java.lang.String stageDesc
protected java.lang.String stageBgimage
Constructor Detail |
public StageLoader(Env environ, DisplayCache dc, GameContainer c, Controller ctrl, java.lang.String fname) throws GameException
Constructor creates only RoleView objects but not Role objects. Role objects will be created and initialized by loadNextStage() method.
NOTE that unrecognizable tags are ignored, and they do not invoke parsing errors. Parsing errors are invoked only when an expected tag cannot be found.
roleviews
environ
- Game environmentdc
- DisplayCachec
- GameContainerctrl
- Controllerfname
- file name of the RoleView initialization script
GameException
- if any error occured.Method Detail |
private RoleView createRoleView(DOMTree rvTree) throws GameException
roleview
rvTree
- a GameException
- if cannot create a RoleView object.private AnchoredImage[] createAnchoredImageArray(DOMTree imgsTree, java.lang.String basedir) throws GameException
images
imgsTree
- a basedir
- base directory of the file name.
GameException
- if any error occured.private AnchoredImage createAnchoredImage(DOMTree aimgTree, java.lang.String basedir) throws GameException
aimage
aimgTree
- a basedir
- base directory of the file name.
GameException
- if cannot create an AnchoredImage object.protected RoleView getRoleView(java.lang.String rname) throws GameException
NOTE that this method will never return null.
rname
- role name.
GameException
- if cannot find the expected RoleView object.public void readStageScript(java.lang.String fname) throws GameException
NOTE that the DOM tree generated contains the information of all the stages.
fname
- stage script file name
GameException
- if any I/O error or parsing error occured.public boolean hasNextStage() throws GameException
GameException
- if stages are not loaded.public void reloadStage() throws GameException
GameException
public void loadNextStage() throws GameException
After loading, stage name, description and id will be updated, and all the Role objects will be created and added to GameContainer. The background image may be changed if necessary.
GameException
- if any error occured.protected abstract void loadStageData(java.io.InputStream fin) throws GameException
NOTE 1: The format of the stage data file is self-defined.
NOTE 2: The InputStream object will be closed after this method.
fin
- an InputStream object connected to the stage data file.
GameException
- if any error occured.protected abstract RoleView newRoleViewInstance(java.lang.String rname, AnchoredImage[] aimgs) throws GameException
NOTE that this method never returns null. If it cannot create a RoleView object, it will throw out a GameException.
rname
- role name
GameException
- if any error occured.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |