FaultInOurPong  1
startGame.GameController Class Reference

Classes

class  GameListener
 action listener for the game page
 
class  ModeListener
 action listener for the game mode page
 
class  TutorialListener
 action listener for the tutorial page
 
class  WelcomepageListener
 action listener for the welcome page
 

Public Member Functions

 GameController (GameView v, GameModel m) throws ArithmeticException
 this is the constructor for the controller More...
 
void display ()
 sets the display More...
 
int getVelX ()
 returns the velocity of ball in the x direction. More...
 
int getVelY ()
 returns the velocity of ball in the y direction. More...
 
int getbombVelX ()
 returns the velocity of bomb in the x direction. More...
 
int getbombVelY ()
 returns the velocity of bomb in the y direction. More...
 

Private Member Functions

void checkGameOver ()
 checks whether the game ends More...
 
void getElapsedTime ()
 obtains the time the user plays. More...
 
void resetGame ()
 resets to initial when the player exits a game. More...
 
void setSpeed ()
 resets speed to ball and bomb More...
 

Private Attributes

GameView v
 
GameModel m
 
Welcome w
 
Mode mode
 
Tutorial tut
 
HashSet< String > keys = new HashSet<String>()
 
JFrame gameFrame
 
int frameWidth
 
PongGameDisplay gameDisplay
 
int velX =1
 
int padWidth
 
int bottomPadX
 
Ball b
 
Paddle paddle_player
 
int ballX
 
int scoreTop
 
int inset
 
final int SINGLE = 0
 
final int ADVANCE = 1
 
int gameMode
 
Ball bomb
 
int bombX
 
int bombVelX
 
Player player
 
Player ai
 
Timer t
 
HighScore displayScore
 
long startTime
 
long endTime
 
double timeElapsed
 
JButton pause
 
JButton resume
 
JButton save
 
JButton exit
 

Constructor & Destructor Documentation

§ GameController()

startGame.GameController.GameController ( GameView  v,
GameModel  m 
) throws ArithmeticException

this is the constructor for the controller

contains methods for detecting environment variables and passing variables between model and view.

Parameters
vis the view framework
mis the model framework
Exceptions
ArithmeticExceptionobject position could not be out of the game frame

Set default game mode to be single

Set up velocities

Obtain the window frame dimentions

Setups for ball in the Model

Setups for the bomb in the Model

Setups for the paddles in the Model

  • obtain paddle dimensions
  • initialize paddle positions for the player paddle
  • initialize paddle positions for the ai paddle

Setups for the players in the Model

  • initialize number of life for the player and the ai

Setups for the View

  • obtain windows from the view
  • add action listener for different windows

Initialize the start time and end time for a player

Member Function Documentation

§ checkGameOver()

void startGame.GameController.checkGameOver ( )
private

checks whether the game ends

if the score of one side is 0, redirect to the ending state (stop the game and display message).

Exceptions
IOExceptioncannot find and read the highScore.txt
  • If the number of life for the ai is 0, the player wins
  • If the number of life for the player is 0, the ai wins.
  • Calculate the time a player has played, if breaks the record, save the record.

§ display()

void startGame.GameController.display ( )

sets the display

opens a window

§ getbombVelX()

int startGame.GameController.getbombVelX ( )

returns the velocity of bomb in the x direction.

Returns
bombVelX

§ getbombVelY()

int startGame.GameController.getbombVelY ( )

returns the velocity of bomb in the y direction.

Returns
bombVelY

§ getElapsedTime()

void startGame.GameController.getElapsedTime ( )
private

obtains the time the user plays.

calculates the time elapsed and save it into a variable.

§ getVelX()

int startGame.GameController.getVelX ( )

returns the velocity of ball in the x direction.

Returns
velX

§ getVelY()

int startGame.GameController.getVelY ( )

returns the velocity of ball in the y direction.

Returns
velY

§ resetGame()

void startGame.GameController.resetGame ( )
private

resets to initial when the player exits a game.

re-initializes the variables in the game model and update the variables in view and model.

Reset player scores/lives in the model.

Reset the game mode

Reset ball and bomb position

Reset the ball and bomb speed

Re-obtain scores/lives from the model

Reset scores in the view

§ setSpeed()

void startGame.GameController.setSpeed ( )
private

resets speed to ball and bomb

re-initialize by randomized values

Randomize the velocity for bomb

Member Data Documentation

§ ADVANCE

final int startGame.GameController.ADVANCE = 1
private

§ ai

Player startGame.GameController.ai
private

§ b

Ball startGame.GameController.b
private

§ ballX

int startGame.GameController.ballX
private

§ bomb

Ball startGame.GameController.bomb
private

§ bombVelX

int startGame.GameController.bombVelX
private

§ bombX

int startGame.GameController.bombX
private

§ bottomPadX

int startGame.GameController.bottomPadX
private

§ displayScore

HighScore startGame.GameController.displayScore
private

§ endTime

long startGame.GameController.endTime
private

§ exit

JButton startGame.GameController.exit
private

§ frameWidth

int startGame.GameController.frameWidth
private

§ gameDisplay

PongGameDisplay startGame.GameController.gameDisplay
private

§ gameFrame

JFrame startGame.GameController.gameFrame
private

Variable declarations for the game

  • frame dimension
  • paddle information
  • ball information
  • bomb information
  • player information

§ gameMode

int startGame.GameController.gameMode
private

§ inset

int startGame.GameController.inset
private

§ keys

HashSet<String> startGame.GameController.keys = new HashSet<String>()
private

Declare a variable for storing the key pressed records

§ m

GameModel startGame.GameController.m
private

§ mode

Mode startGame.GameController.mode
private

§ paddle_player

Paddle startGame.GameController.paddle_player
private

§ padWidth

int startGame.GameController.padWidth
private

§ pause

JButton startGame.GameController.pause
private

§ player

Player startGame.GameController.player
private

§ resume

JButton startGame.GameController.resume
private

§ save

JButton startGame.GameController.save
private

§ scoreTop

int startGame.GameController.scoreTop
private

§ SINGLE

final int startGame.GameController.SINGLE = 0
private

§ startTime

long startGame.GameController.startTime
private

§ t

Timer startGame.GameController.t
private

§ timeElapsed

double startGame.GameController.timeElapsed
private

§ tut

Tutorial startGame.GameController.tut
private

§ v

GameView startGame.GameController.v
private

Import model and view to the controller (this interface).

§ velX

int startGame.GameController.velX =1
private

§ w

Welcome startGame.GameController.w
private

Variable declarations for storing the game view windows

  • welcome page
  • mode page for showing different modes
  • tutorial page for giving instructions to the students

The documentation for this class was generated from the following file: