|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectvooga.gameEngine.game.GameRelatedObject
vooga.gameEngine.game.AbstractGame
public abstract class AbstractGame
AbstractGame
is main class implemented by all games. It provides
methods required for general game-running, such as starting and ending the
whole game or the current level. AbstractGame
objects hold a
reference to a GameManager
object. This manager has several methods
useful in executing a game, such as adding or removing an Object
from the game. If, during game play, the game necessitates the addition or
removal of a particular game Object
, the suggested solution is
to do so by firing an event. The AbstractGame
should listen for
this event and then call the proper method in the GameManager
.
Constructor Summary | |
---|---|
AbstractGame(GameManager manager)
Creates a game given its GameManager . |
Method Summary | |
---|---|
abstract boolean |
endGame()
Ends the current game. |
abstract boolean |
endLevel()
Ends the current level. |
abstract java.lang.Integer[] |
getAllowedPlayerNumbers()
Specifies what number of players are allowed in a network game. |
abstract CameraController |
getCameraController()
Provides access to the CameraController for this game. |
GameManager |
getManager()
Provides access to the manager for this AbstractGame . |
boolean |
loadLevel(java.util.Collection<? extends java.lang.Object> items)
Loads all the Object s of the level into memory and readies
the level. |
boolean |
loadLevel(java.io.File level)
Parses an XML file of all the Object s in a level, loads the
items into memory, and readies the level. |
void |
pauseStatusChanged(PauseEvent e)
Pauses or resumes all aspects of the game. |
abstract boolean |
quitGame()
Quits the current game. |
void |
removeAllKeyInputs()
Removes all assignments made by setKeyInput(KeyStroke, Class) or
setKeyInput(KeyStroke, Class, EventListener) . |
void |
removeAllKeyInputs(java.util.Collection<javax.swing.KeyStroke> keyStrokes)
Removes the assignments made by setKeyInput(keyStroke, Class) or
setKeyInput(keyStroke, Class, EventListener , where keyStroke
represents an entry of keyStrokes. |
void |
removeKeyInput(javax.swing.KeyStroke keyStroke)
Removes the assignment made by setKeyInput(keyStroke, Class) or
setKeyInput(keyStroke, Class, EventListener . |
boolean |
restartLevel()
Restarts the current level. |
void |
setKeyInput(javax.swing.KeyStroke keyStroke,
java.lang.Class<? extends java.util.EventObject> event)
Assigns a particular KeyStroke to an event in the game. |
void |
setKeyInput(javax.swing.KeyStroke keyStroke,
java.lang.Class<? extends java.util.EventObject> event,
java.util.EventListener listener)
Assigns a particular KeyStroke to an event in the game and to a
specific listener. |
void |
setMouseInput(java.lang.Integer mouseButtonID,
java.lang.Class<? extends java.util.EventObject> event)
Assigns a particular MouseEvent to an event in the game. |
abstract boolean |
startGame()
Initializes anything necessary for the game to start, and starts the game. |
abstract boolean |
startLevel()
Initializes anything necessary for a level to start, and starts the level. |
abstract void |
whenPaused(boolean gameLoopPaused)
Determines what should occur game-wise during an attempt to pause a game. |
abstract void |
whenResumed()
Defines what should occur game-wise during an attempt to resume the game. |
Methods inherited from class vooga.gameEngine.game.GameRelatedObject |
---|
addEventListener, clearListeners, equals, fire, fire, fire, getEventListeners, getID, getListenerCount, removeEventListener |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public AbstractGame(GameManager manager)
GameManager
. If manager is
set to null, an exception will be thrown, as all games must have a
GameManager
.
manager
- the GameManager
managing this gameMethod Detail |
---|
public abstract boolean startGame()
AbstractGame
need not call this method.
public abstract boolean endGame()
AbstractGame
when it is determined that the game is over.
public void pauseStatusChanged(PauseEvent e)
whenPaused(boolean)
or whenResumed()
.
pauseStatusChanged
in interface PauseListener
e
- the PauseEvent
public abstract void whenPaused(boolean gameLoopPaused)
pauseStatusChanged(PauseEvent)
.
gameLoopPaused
- whether the game loop was successfully pausedpublic abstract void whenResumed()
pauseStatusChanged(PauseEvent)
.
public abstract boolean quitGame()
endGame()
in that this method
would be called if the user attempts to quit in the middle of a game.
This method should be called by the instance of an
AbstractGame
when it is determined that a quit is desired.
public boolean loadLevel(java.util.Collection<? extends java.lang.Object> items)
Object
s of the level into memory and readies
the level. Note that this method WILL add these Object
s
through the GameManager
to the collection of items for the
current level.
items
- the Collection of Object
s that are needed for a
particular level
public boolean loadLevel(java.io.File level)
Object
s in a level, loads the
items into memory, and readies the level. Note that this method WILL add
these Object
s to the level.
level
- the XML file containing all the Object
s for a
particular level.
public abstract boolean startLevel()
loadLevel(java.util.Collection extends java.lang.Object>)
, so all
GameItems
s have already been loaded. Note: There is a
StartLevelListener
-StartLevelEvent
pair provided for
convenience. If used, the startLevelRequested
method of the
StartLevelListener
should contain a call to this method.
Moreover, if one has a collection of items that define a particular level
or a file that contains such items, this method can call
loadLevel(Collection)
or loadLevel(File)
rather than
adding them to the manager directly.
public abstract boolean endLevel()
AbstractGame
when it is determined that the current level
is over. Note: There is a EndLevelListener
-EndLevelEvent
pair provided for convenience. If used, the
endLevelRequested
method of the
EndLevelListener
should contain a call to this method.
public boolean restartLevel()
public void setKeyInput(javax.swing.KeyStroke keyStroke, java.lang.Class<? extends java.util.EventObject> event)
KeyStroke
to an event in the game. When the
KeyStroke
is made, the event is fired to all listeners for
this event.
keyStroke
- a particular key strokeevent
- The Class
of the event to be fired if the given
key stroke is pressed (or released).public void setKeyInput(javax.swing.KeyStroke keyStroke, java.lang.Class<? extends java.util.EventObject> event, java.util.EventListener listener)
KeyStroke
to an event in the game and to a
specific listener. When the specific KeyStroke
is made, the
event will be fired ONLY to the given listener.
keyStroke
- a particular key strokeevent
- The Class
of the event to be fired if the given
key stroke is pressed (or released).listener
- The listener to whom the event should be firedpublic void setMouseInput(java.lang.Integer mouseButtonID, java.lang.Class<? extends java.util.EventObject> event)
MouseEvent
to an event in the game.
mouseButton
- a MouseEvent
event
- The Class
of the event to be fired if the given
MouseEvent
is fired.public void removeKeyInput(javax.swing.KeyStroke keyStroke)
setKeyInput(keyStroke, Class)
or
setKeyInput(keyStroke, Class, EventListener
.
keyStroke
- to removepublic void removeAllKeyInputs(java.util.Collection<javax.swing.KeyStroke> keyStrokes)
setKeyInput(keyStroke, Class)
or
setKeyInput(keyStroke, Class, EventListener
, where keyStroke
represents an entry of keyStrokes.
keyStrokes
- to removepublic void removeAllKeyInputs()
setKeyInput(KeyStroke, Class)
or
setKeyInput(KeyStroke, Class, EventListener)
.
public abstract CameraController getCameraController()
CameraController
for this game. This
method will be called by the GameManager
in order to set the
CameraController
.
CameraController
public GameManager getManager()
AbstractGame
.
Changed to public
for the development team.
GameManager
for this gamepublic abstract java.lang.Integer[] getAllowedPlayerNumbers()
Array
of
Integers specifying which numbers
of players are allowed during network play. Thus a game which supports 2 and 4 players
but not 3 should return an array {2,4}. It is unlikely that a network game would ever allow
a single player and thus should not return {1,...}. Games which are not networked need not implement this method.
- Returns:
- An array specifying all allowed numbers of players for a
networked instance of a game.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |