|
||||||||||
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
games.pong.Pong
public class Pong
The main Pong game. A Paddle
is created on each side of the screen,
and a Ball
bounces between the two. A player scores a point when the
Ball
passes one of the Paddles
. By default, a human player
controls the Paddle
on the left.
Constructor Summary | |
---|---|
Pong(GameManager manager)
Construct a new Pong game with the given GameManager . |
Method Summary | |
---|---|
void |
beginGame(StartEvent e)
Triggers when the user decides to start a game. |
void |
changeBallImage(BallChangeEvent e)
Triggers when the user tries to change the image of the ball. |
void |
changePaddleImage(PaddleChangeEvent e)
Triggers when the user tries to change the image of the paddle. |
boolean |
endGame()
Ends the current game. |
void |
endGame(QuitGameEvent e)
Triggers when the user tries to quit a game. |
boolean |
endLevel()
Turn off controller input and remove the ball |
java.lang.Integer[] |
getAllowedPlayerNumbers()
Specifies what number of players are allowed in a network game. |
Ball |
getBall()
|
CameraController |
getCameraController()
Provides access to the CameraController for this game. |
Paddle |
getLeftPaddle()
|
Paddle |
getRightPaddle()
|
int |
getScore()
|
boolean |
isGameOver(Position pos)
Determine if the ball has passed beyond one of the paddles (a player scored a point). |
static void |
main(java.lang.String[] args)
|
void |
positionChanged(PositionChangedEvent e)
This is called whenever a Tangible object updates its position. |
void |
processAddRequest(AddGameObjectEvent e)
Optionally checks whether it is okay to add the item requesting addition to the game and then adds that item to the game. |
void |
processRemoveRequest(RemoveGameObjectEvent e)
Removes the source object of the RemoveGameObjectEvent
parameter or checks to see if this remove is possible before taking
action. |
void |
processScore(Position pos)
Determine which player scored, increment the appropriate score, and end the level if the score reached the GAME_END_SCORE |
boolean |
quitGame()
Quits the current game. |
void |
resetLevel(GameResetEvent e)
Triggers when the user try to manually reset the level |
boolean |
startGame()
Create a paddle for the left and the right side of the screen. |
boolean |
startLevel()
Create a new ball in the center of the screen and set it in motion |
void |
whenPaused(boolean gameLoopPaused)
Determines what should occur game-wise during an attempt to pause a game. |
void |
whenResumed()
Defines what should occur game-wise during an attempt to resume the game. |
Methods inherited from class vooga.gameEngine.game.AbstractGame |
---|
getManager, loadLevel, loadLevel, pauseStatusChanged, removeAllKeyInputs, removeAllKeyInputs, removeKeyInput, restartLevel, setKeyInput, setKeyInput, setMouseInput |
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 Pong(GameManager manager)
GameManager
. Create
a CameraController and assign it to the GameManager
.
manager
- a GameManager
provided by the Game EngineMethod Detail |
---|
public boolean startGame()
startGame
in class AbstractGame
public boolean startLevel()
startLevel
in class AbstractGame
public boolean endGame()
AbstractGame
AbstractGame
when it is determined that the game is over.
endGame
in class AbstractGame
public boolean endLevel()
endLevel
in class AbstractGame
public CameraController getCameraController()
AbstractGame
CameraController
for this game. This
method will be called by the GameManager
in order to set the
CameraController
.
getCameraController
in class AbstractGame
CameraController
public boolean quitGame()
AbstractGame
AbstractGame.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.
quitGame
in class AbstractGame
public java.lang.Integer[] getAllowedPlayerNumbers()
AbstractGame
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.
- Specified by:
getAllowedPlayerNumbers
in class AbstractGame
- Returns:
- An array specifying all allowed numbers of players for a
networked instance of a game.
public void whenPaused(boolean gameLoopPaused)
AbstractGame
AbstractGame.pauseStatusChanged(PauseEvent)
.
whenPaused
in class AbstractGame
gameLoopPaused
- whether the game loop was successfully pausedpublic void whenResumed()
AbstractGame
AbstractGame.pauseStatusChanged(PauseEvent)
.
whenResumed
in class AbstractGame
public int getScore()
public boolean isGameOver(Position pos)
PositionChangedListener
when the
Ball's position changes.
pos
- the current position of the ball
public void processScore(Position pos)
GAME_END_SCORE
pos
- the position of the ballpublic void positionChanged(PositionChangedEvent e)
PositionChangeListener
Tangible
object updates its position.
positionChanged
in interface PositionChangeListener
e
- the PositionChangedEvent
public void resetLevel(GameResetEvent e)
GameFlowListener
resetLevel
in interface GameFlowListener
public void beginGame(StartEvent e)
GameFlowListener
beginGame
in interface GameFlowListener
public void endGame(QuitGameEvent e)
GameFlowListener
endGame
in interface GameFlowListener
public void changeBallImage(BallChangeEvent e)
GameFlowListener
changeBallImage
in interface GameFlowListener
public void changePaddleImage(PaddleChangeEvent e)
GameFlowListener
changePaddleImage
in interface GameFlowListener
public Paddle getLeftPaddle()
public Paddle getRightPaddle()
public Ball getBall()
public void processAddRequest(AddGameObjectEvent e)
AddRemoveGameObjectListener
processAddRequest
in interface AddRemoveGameObjectListener
e
- The event which holds a GameItem
requesting to be
added to the game.public void processRemoveRequest(RemoveGameObjectEvent e)
AddRemoveGameObjectListener
RemoveGameObjectEvent
parameter or checks to see if this remove is possible before taking
action.
processRemoveRequest
in interface AddRemoveGameObjectListener
e
- The event whose source is the Object
desiring
removalpublic static void main(java.lang.String[] args)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |