games.pong
Class Pong

java.lang.Object
  extended by vooga.gameEngine.game.GameRelatedObject
      extended by vooga.gameEngine.game.AbstractGame
          extended by games.pong.Pong
All Implemented Interfaces:
GameFlowListener, java.io.Serializable, java.util.EventListener, AddRemoveGameObjectListener, PauseListener, PositionChangeListener

public class Pong
extends AbstractGame
implements PositionChangeListener, GameFlowListener, AddRemoveGameObjectListener

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.

Author:
Lucas Best, Ben Getson
See Also:
Serialized Form

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

Pong

public Pong(GameManager manager)
Construct a new Pong game with the given GameManager. Create a CameraController and assign it to the GameManager.

Parameters:
manager - a GameManager provided by the Game Engine
Method Detail

startGame

public boolean startGame()
Create a paddle for the left and the right side of the screen. For now, designate the left paddle as human input, and the right as computer.

Specified by:
startGame in class AbstractGame
Returns:
true if the game successfully started; false otherwise

startLevel

public boolean startLevel()
Create a new ball in the center of the screen and set it in motion

Specified by:
startLevel in class AbstractGame
Returns:
true if the level was started successfully; false otherwise

endGame

public boolean endGame()
Description copied from class: AbstractGame
Ends the current game. This method should be called by the instance of an AbstractGame when it is determined that the game is over.

Specified by:
endGame in class AbstractGame
Returns:
true if the game successfully ended; false otherwise

endLevel

public boolean endLevel()
Turn off controller input and remove the ball

Specified by:
endLevel in class AbstractGame
Returns:
true if the level was ended successfully; false otherwise

getCameraController

public CameraController getCameraController()
Description copied from class: AbstractGame
Provides access to the CameraController for this game. This method will be called by the GameManager in order to set the CameraController.

Specified by:
getCameraController in class AbstractGame
Returns:
the CameraController

quitGame

public boolean quitGame()
Description copied from class: AbstractGame
Quits the current game. Differs from 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.

Specified by:
quitGame in class AbstractGame
Returns:
true if quit was successful; false otherwise

getAllowedPlayerNumbers

public java.lang.Integer[] getAllowedPlayerNumbers()
Description copied from class: AbstractGame
Specifies what number of players are allowed in a network game. This method returns an 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.

whenPaused

public void whenPaused(boolean gameLoopPaused)
Description copied from class: AbstractGame
Determines what should occur game-wise during an attempt to pause a game. Note that this method will be called by AbstractGame.pauseStatusChanged(PauseEvent).

Specified by:
whenPaused in class AbstractGame
Parameters:
gameLoopPaused - whether the game loop was successfully paused

whenResumed

public void whenResumed()
Description copied from class: AbstractGame
Defines what should occur game-wise during an attempt to resume the game. Note that this method will be called by AbstractGame.pauseStatusChanged(PauseEvent).

Specified by:
whenResumed in class AbstractGame

getScore

public int getScore()
Returns:
the score of the game. In this case, the score is the number of rebounds.

isGameOver

public boolean isGameOver(Position pos)
Determine if the ball has passed beyond one of the paddles (a player scored a point). This method is called by the PositionChangedListener when the Ball's position changes.

Parameters:
pos - the current position of the ball
Returns:
if a player scored a point

processScore

public void processScore(Position pos)
Determine which player scored, increment the appropriate score, and end the level if the score reached the GAME_END_SCORE

Parameters:
pos - the position of the ball

positionChanged

public void positionChanged(PositionChangedEvent e)
Description copied from interface: PositionChangeListener
This is called whenever a Tangible object updates its position.

Specified by:
positionChanged in interface PositionChangeListener
Parameters:
e - the PositionChangedEvent

resetLevel

public void resetLevel(GameResetEvent e)
Description copied from interface: GameFlowListener
Triggers when the user try to manually reset the level

Specified by:
resetLevel in interface GameFlowListener

beginGame

public void beginGame(StartEvent e)
Description copied from interface: GameFlowListener
Triggers when the user decides to start a game. Implementation will need to determine how many players are required by the event which is fired.

Specified by:
beginGame in interface GameFlowListener

endGame

public void endGame(QuitGameEvent e)
Description copied from interface: GameFlowListener
Triggers when the user tries to quit a game. Restrict success based on if the game is paused or not.

Specified by:
endGame in interface GameFlowListener

changeBallImage

public void changeBallImage(BallChangeEvent e)
Description copied from interface: GameFlowListener
Triggers when the user tries to change the image of the ball. Restrict success based on if the game is paused or not.

Specified by:
changeBallImage in interface GameFlowListener

changePaddleImage

public void changePaddleImage(PaddleChangeEvent e)
Description copied from interface: GameFlowListener
Triggers when the user tries to change the image of the paddle. Restrict success based on if the game is paused or not.

Specified by:
changePaddleImage in interface GameFlowListener

getLeftPaddle

public Paddle getLeftPaddle()

getRightPaddle

public Paddle getRightPaddle()

getBall

public Ball getBall()

processAddRequest

public void processAddRequest(AddGameObjectEvent e)
Description copied from interface: AddRemoveGameObjectListener
Optionally checks whether it is okay to add the item requesting addition to the game and then adds that item to the game.

Specified by:
processAddRequest in interface AddRemoveGameObjectListener
Parameters:
e - The event which holds a GameItem requesting to be added to the game.

processRemoveRequest

public void processRemoveRequest(RemoveGameObjectEvent e)
Description copied from interface: AddRemoveGameObjectListener
Removes the source object of the RemoveGameObjectEvent parameter or checks to see if this remove is possible before taking action.

Specified by:
processRemoveRequest in interface AddRemoveGameObjectListener
Parameters:
e - The event whose source is the Object desiring removal

main

public static void main(java.lang.String[] args)