Pac Man Architecture page Iteration 3

History of Revisions
11/01/02 Chris Epsom Initial Document Creation
11/14/02 Chris Epsom Addition of Class descriptions
11/24/02 Chris Epsom Defect Repair

Overhead View The actual program has no "main" because it will actually be run by the OS running on the device that the application is stored on (now on referred to as "phone"). See the Overhead Architecture View document. The phone OS supplies the menu option to start the program and will return the phone to the state it started in after ending the application. If a phone call is received during gameplay, the application is suspended by the phone OS and can be resumed after the call is complete.


Overall Functionality
The OS of the phone will start the MIDlet by calling startApp() in pacman.java. The GameCanvas will have the Display set to the display returned by the pacman.java that is unique to the MIDlet. GameCanvas will display each different type of screen and then change to different screens when needed. The type of screen displayed will defined in a variable and pushing different keys will only affect valid screens through if statements in GameCanvas.keyPressed(int). The actual game board will be created in GameBoardFactory by splitting the screen into different squares and adding walls at hardcoded points to make a maze for Pac Man. Different levels are created by just adding walls at different places and using the same other sections of the code. The squares will be GridNode objects and will have 4 pointers to neighboring GridNodes if there is no wall between the two and a pointer to NULL if there is a wall which is used for navigation of Pac Man and the Ghosts as well as drawing the walls on the screen. FrameTrigger will be a thread that runs during the course of the program that sleeps for a certain amount of time in order to make the animation. It will repaint the screen at defined intervals making a smooth transition. Also in order to make animation smooth, the value of the key being pressed by the user is only checked at the center of each square making direction changes only occur when they are valid. The game ends when all of the dots are gone, then the end game screen is displayed. When the user selects "Pause" and is prompted to save if desired, the saved game will be a GameBoard.java object written to a file so that the exact location of all pixels will be accounted for.


Pacman.java
Description: The class will act like the "main" of the program. It extends javax.microedition.midlet.MIDlet and will be the overhead control of the program that is called by the OS on the phone.
Attributes: GameCanvas canvas is an object that will control what is displayed on the screen.
IntroScreen intro will be used to control the introduction screen.
ExitScreen exitScreen will be used to control the exit screen.
HighScoreScreen highScore will be used to control the high score screen.
SetLevelScreen setLevel will be used to control the set level screen.
LoadScreen loadScrn will be used to control the load game screen.
ChangeControlScreen changeControl will be used to control the change game controls screen.
int screenType will be used to define which screen to show.
Methods: Pacman() is the constructor that initializes the Display and GameCanvas.
startApp() redefines the abstract method in MIDlet to start displaying things to the screen.
pauseApp() redefines the abstract method in MIDlet to be used to pause the game.
destroyApp(boolean) redefines the abstract method in MIDlet to be used by the OS on the phone to terminate the application.

GameCanvas.java
Description: This class controls all of the displays and animation for the game. The class extends javax.microedition.lcdui.Canvas.
Attributes: Display disp is an object that holds the information about how to access the display on the phone and is a J2ME library class. disp was initialized by pacman.java.
GameBoard gameBoard is an object that holds level grid pieces and actors.
FrameTrigger frameTrigger is an object that controls the delay time in between animation of each screen.
Methods: GameCanvas(Display) is the constructor that initializes the gameBoard and the frameTrigger.
paint(Graphics) is the method that redefines the abstract method from Canvas and clears the screen and starts all of the animation.
show() is the method that actually starts the animation.
advanceFrame() is the method that moves animation forward one frame.
keyPressed(int) is used to tell the program which key is being pressed on the phone.


GameBoard.java
Description: This class holds the vectors of level grid sections and actors. It also directly controls what is painted in each section of the screen and when the actors should advance to a different section.
Attributes: Vector nodes is a java.util.Vector object that holds GridNode objects.
Vector ghosts is a java.util.Vector object that holds GhostActors.
PacmanActor pacman is an object that keeps the current information about how many pellets have been eaten as well as the location and animation step of Pac Man.
boolean isPaused is used to tell the program whether or not the game is currently paused.
boolean isCollision will be used to tell if Pac Man has been hit by a Ghost.
boolean gameOver will be used to tell if the game is over and initialized to false.
Methods: GameBoard() is the constructor that initializes the Vectors.
addGridNode(GridNode) is used to add a new GridNode object to the nodes vector.
paint(Graphics) is used to start the display of each grid section as well as the actors.
advanceFrame() is used to advance all of the actors one space.
setPacman(PacmanActor) is used to initialize the PacmanActor object in the class.
getPacman() is used to return the PacmanActor object in the class.
addGhost(GhostActor) is used to add a GhostActor object to the ghosts vector.
removeGhost() is used to reset the Ghost's position after being eaten by Pac Man.
setPaused() is used to set the isPaused flag and is called by GameCanvas.keyPressed().
saveGame() is used to write the current GameBoard.java object to disk on the phone so it can be accessed later.
isCollision() will be used to test if Pac Man has been hit by a Ghost or vice versa.
isGameOver() will test to see if Pac Man has no more lives left.

GameBoardFactory.java
Description: This class is used to hold all of the information for each level in array of arrays form.
Attributes: GridNode levelNodes[][] is used to hold all of the sections of the screen and what is present in each.
Methods: getLevelOne() will be the method that sets all of the levelNodes[][] according to a predefined, hard-coded set sections of the screen that sets where walls are as well as where pacman and the ghosts start.
getLevelTwo() will be the same as above, just with different starting positions and wall locations.
There can be as many different levels as desired or allowed by memory.
UDLink(int, int, int, int) is used to set a certain GridNode to either have a wall on the top or bottom.
LRLink(int, int, int, int) is used to set a certain GridNode to either have a wall on the left or right.

FrameTrigger.java
Description: This class is the thread that causes the animation to happen, and will extend java.lang.Thread. There will be a sleep here that is set in GameCanvas.java that will control animation speed.
Attributes: GameCanvas game will be used to be able to reference the GameCanvas that created this FrameTrigger.
int frameDelay will be the number used by the sleep to determine animation speed.
private boolean stopped will be the boolean that will determine whether or not the thread is running.
Methods: FrameTrigger(GameCanvas, int) is the constructor that will be used to set the frameDelay and the game variables.
stopTrigger() is used to stop the thread.
run() is used to start the thread and will infinite loop until stopTrigger() is called.

GridNode.java
Description: This class is used to describe exactly which pixels in each section of the screen will be colored or not based on presence or lack of presence of pellets, super pellets and walls.
Attributes: static final int NO_PELLET, SMALL_PELLET, BIG_PELLET, are all different integers that are used to tell what kind of pellet is in the node.
int size is the size of the grid square in pixels.
int pellet contains one of the static final ints from above.
GridNode left, right, up, down are used to be pointers to the next GridNode object on the corresponding section of the screen. If they are null, then this means a wall is present, if there is a pointer, then the program knows where to move the actor next.
int gridPosX is the GridNode left to right position on the screen in units of GridNodes.
int gridPosY is the GridNode up/down position on the screen in units of GridNodes.
int pixelULX is the left-right pixel position in the Upper Left corner of the GridNode.
int pixelULY is the up-down pixel position in the Upper Left corner of the GridNode.
int pixelLRX is the left-right pixel position in the Lower Right corner of the GridNode.
int pixelLRY is the up-down pixel position in the Upper Left corner of the GridNode.
int pixelCX, pixelCY are the X and Y coordinates of the center of the GridNode in pixels.
Methods: GridNode(int, int) is the constructor that creates a new GridNode object with all wall pointers set to null at the passed coordinates.
getpixelCenterX(), getpixelCenterY() return the X and Y coordinates in pixels of the center of the GridNode.
setLeft(GridNode), setRight(GridNode), setUp(GridNode), setDown(GridNode) are used to set the wall pointers to other GridNodes.
getLeft(), getRight(), getUp(), getDown() are used to return the GridNodes at the end of each wall pointer.
setPellet(int) is used to change the static final int of the pellet status.
getSize() is used to return the size in pixels of each GridNode.
paint(Graphics) is used to fill in the necessary pixels for the walls and pellets.


Actor.java
Description: This class is a super class for the PacmanActor and the GhostActor. It holds common attributes for both.
Attributes: static final int NONE, UP, DOWN, LEFT, RIGHT are used to define the direction of movement for the Actor.
GridNode myNode is the current location of the Actor.
int pixelX, pixelY are used to tell the current center position of the Actor in pixels.
int newPixelX, newPixelY are used to tell the next center position of the Actor in pixels based on user input.
Methods advanceFrame() is used to animate the movement of the actor.
goToNode(GridNode) is used to change the X and Y position of the Actor.

PacmanActor.java
Description: This class is used to describe the location of the Pac Man icon as well as how many pellets have been eaten. It extends Actor.java. The animation of the mouth and the location of the next GridNode to move to is also controlled here.
Attributes: int pelletsEaten is the number of pellets that have been eaten.
int direction is an integer that holds one of the static final ints from above.
int mouthAngle is the current value of the openness of Pac Man?s mouth.
int mouthAngleChange is the value that defines how quickly the angle changes.
int livesLeft is the number of remaing lives that Pac Man has.
Methods: PacmanActor(Gridnode) is the constructor that creates Pac Man to start at the GridNode passed.
getPelletsEaten() returns the total number of pellets eaten by Pac Man.
setDesiredDirection(int) sets the direction variable.
goToNode(GridNode) changes the newPixelX and newPixelY values when a movement is needed.
advanceFrame() is used to animate the movement of Pac Man.
paint(Graphics) is used to display the pixels that Pac Man is taking up at the current time.


GhostActor.java
DescriptionL This class is used to describe a single Ghost position and movement either towards Pac Man if the game is in normal state, or away from Pac Man if Pac Man has eaten a super dot. It extends Actor.java.
Attributes: static boolean runFromPac is used to tell whether or not the Ghosts are running away from Pac Man or not. It is static so that all Ghosts will do the same.
PacmanActor target is the PacmanActor object so the Ghost can run towards or away from it.
Methods: GhostActor(GridNode, PacmanActor) is the constructor and initializes the Ghost in the desired GridNode.
setRunFromPac(boolean) is used to set the variable for whether or not the Ghosts are running from Pac Man or not.
advanceFrame() is used to move the Ghost around the board based on an algorithm that tries to move closer to Pac Man first in the Y direction, then in the X.
moveTowards(int, int, int, int) is used to select if the Ghosts are running towards or away from Pac Man.
goInDirection(int) is used to choose the best direction for the Ghost to move based on whether it is running away from or towards Pac Man.
goToNode(GridNode) actually returns the best route.
paint(Graphics) draws the Ghost to the screen.


PacScreen.java
Description: This class is the super class for all screens other than the Game Board.
Attributes: Canvas canvas will hold all of the information that is needed to display to the screen.
Methods: setCanvas(Display) is used to initialize the canvas object.
advanceFrame() is an abstract class that is used in each individual screen.
paint(Graphics) is an abstract class that is used in each individual screen.


IntroScreen.java
Description: This class is used to define the Introduction screen for the game and is displayed by GameCanvas and extends javax.microedition.lcdui.Form.
Attributes: int isHighlighted is used to tell paint which menu option to highlight.
Item[] menuList will be an array of menu items that are displayed to the scree.
ChangeControlScreen changeScreen will be used to display the Change Controls menu item when selected.
LoadScreen loadScreen will be used to display the Load Game menu item when selected.
HighScoreScreen highScores will be used to display the High Score Screen when selected from the menu.
SetLevelScreen setLevel is used to display the Set Level screen when selected from the menu.
Methods: IntroScreen() is the constructor and is used to initialize the screen and fill the menuList[].
advanceFrame() is used to check for user input in order to procede to the game mode.
paint(Graphics) is used to display the Introduction Screen to the display on the phone.


LoadScreen.java
Description: This class is used to make the screen that lists the saved games for the user to select in order to begin playing from a saved point and extends PacScreen.java.
Attributes: int isHighlighted is used to tell paint which menu option to highlight.
Methods: LoadScreen() is the constructor and is used to initialize the screen.
advanceFrame() is used to check for user input in order to procede to the game mode or move the highlighted option.
paint(Graphics) displays the information to the screen.
getSaved() returns the information for the saved games.

ExitScreen.java
Description: This class is used to make the screen that is displayed when Pac Man loses all of his lives or the User exits and extends PacScreen.java.
Attributes:
Methods: ExitScreen() is the constructor and is used to initialize the screen.
advanceFrame() is used to check to see if the user has clicked through to the next screen. paint(Graphics) displays the information to the screen.


SetLevelScreen
Description: This class is used to make the screen that is used to change the starting level of the Pac Man game and extends PacScreen.java. It is chosen from the main menu.
Attributes: int level is the current starting level,
int isHighlighted is used to tell which level choice is highlighted.
Methods: SetLevelScreen() is the constructor and is used to initialize the screen.
setLevel(int levelChoice) is used to set the current starting level.
getLevel() is used to return the current starting level.
advanceFrame() is used to see if the user has selected to change screens.
paint() is used to display the information to the screen.

ChangeControlScreen
Description: This class is used to make the screen that is used to change the User Controls for the Pac Man game and extends PacScreen.java. It is chosen from the main menu.
Attributes: int up is the value of the keypad input of the device defined for "up".
int down is the value of the keypad input of the device defined for "down".
int left is the value of the keypad input of the device defined for "left".
int right is the value of the keypad input of the device defined for "right".
Methods: ChangeControlScreen() is the constructor and initializes the screen.
setLeft(int userChoice) is used to set the keypad input for "left".
setRight(int userChoice) is used to set the keypad input for "right".
setDown(int userChoice) is used to set the keypad input for "down".
setUp(int userChoice) is used to set the keypad input for "up".
advanceFrame() is used to step through the prompted inputs for the user.
paint() is used to display the information to the screen.

HighScoreScreen
Description: This class is used to describe the screen that displays the high score for the Pac Man game. It extends PacScreen.java.
Attributes: String name is used to store the new name for the high score for the game.
int score is the value of the high score that the user is entering their name for.
Methods: HighScoreScreen() is the constructor and initializes the screen.
setHighScore(int userScore) is used to write the new high score to disk.
getHighScore(int numScore) is used to return the corresponding high score from disk.
getName(int numScore) is used to return the corresponding name associated with the high score from disk.
setName(String userName) is used to write the name that corresponds to the new high score to disk.
advanceFrame() is used to cycle through the screens for user inputs.
paint() is used to display the information to the screen.


Pac Man Architecture Iteration 4