|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--nankin.zheng.gatem.model.GameContainer
GameContainer is in charge of the game (frame) updating and the communications among all the roles inside it. All the work is done by a thread while game is not over. NOTE that by default, GameContainer does not care about user input.
Field Summary | |
protected Background |
background
A background reference is held seperately to update viewport. |
protected Env |
env
The game environment. |
protected StageLoader |
loader
Stage loader, which loads stage information (creates RoleView and Role objects) for this container. |
protected java.util.Vector |
roleList
Role list, containing all the active roles whose act() will be called during every frame-updating. |
protected GameScheduler |
scheduler
Game scheduler, which schedules all the game containers. |
protected int |
status
Status of the container. |
Constructor Summary | |
GameContainer(Env environ)
Constructor. |
Method Summary | |
void |
addRole(Role r)
Add a new role into the role list. |
void |
broadcastGameEvent(GameEvent gevt)
Broadcast a game event to all the roles in the roleList. |
protected void |
drawGameFrame()
This method draws all the roles onto the screen without changing their status. |
int |
getContainerStatus()
Get container status. |
StageLoader |
getStageLoader()
Get stage loader for this container. |
protected abstract void |
receiveGameEvent(GameEvent gevt)
This method works as Role.receiveGameEvent(...) since game event may also have some impact on GameContainer. |
void |
setBackground(Background b)
Sets background. |
void |
setContainerStatus(int sts)
Set container status. |
void |
setGameScheduler(GameScheduler s)
Set game scheduler. |
void |
setStageLoader(StageLoader l)
Set stage loader for this container. |
void |
testInitialization()
Verify whether this object is initialized properly. |
void |
unloadStage()
Unload this stage. |
void |
updateGameFrame()
This method updates all the roles' logical status. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected Env env
protected GameScheduler scheduler
protected int status
protected Background background
protected java.util.Vector roleList
protected StageLoader loader
Constructor Detail |
public GameContainer(Env environ) throws GameException
environ
- game environment
java.lang.NullPointerException
- if environ is null.
GameException
- if any error occured.Method Detail |
public void setBackground(Background b) throws GameException
The specified Background b should be a Role object, and should have already been added in the roleList.
b
- background
GameException
- if b is not in the roleList yet.public int getContainerStatus()
public void setContainerStatus(int sts)
sts
- status of GameContainer.public void setGameScheduler(GameScheduler s)
s
- game scheduler.public void addRole(Role r) throws java.lang.NullPointerException
r
- role
java.lang.NullPointerException
- if r is null.public void testInitialization() throws GameException
This method should be overridden to provide more strict verification.
NOTE that this method will call all the roles' testInitialization(), which means that the roles' proper initailization is the necessary condition of its proper initialization.
GameException
- if this GameContainer is not initialized properly.public void updateGameFrame() throws GameException
GameException
- may be thrown out by Role.act().protected void drawGameFrame() throws GameException
GameException
- may be thrown out by Role.draw().public void broadcastGameEvent(GameEvent gevt) throws GameException
This method is called by a role who fires a GameEvent. It will do the following two things:
gevt
- game event to be broadcast.
GameException
- may be thrown out by receiveGameEvent().protected abstract void receiveGameEvent(GameEvent gevt) throws GameException
gevt
- game event.
GameException
- may be thrown out by its subclasses.public void setStageLoader(StageLoader l)
l
- stage loader.public StageLoader getStageLoader()
public void unloadStage()
This method will clean its role list and unset its background, and then run System.gc(). This work will be done before a new stage is loaded.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |