import javax.swing.*; import java.awt.*; /** * CS1322: Programming Assignment #6 - Fall 2002 * *
* IDBox for: GameBoard.java * * Revisions: 1.0 Nov. 24, 2002 * Created the GameBoard class * ** * Collaboration statement: * I collaborated with Roland Krystian Alberciak on this phase of the * program. * * @author Jose M. Cabank * @version Version 1.0, Nov. 24, 2002 */ /** * VIEW. * GameBoard. GameBoard extends JPanel. * Responsible for drawing or painting the board * according to the GamePiece array created in PacmanFileReader. */ public class GameBoard extends JPanel { /** Debug value for toggling System.out.* output */ public static boolean DEBUG = false; public static boolean DEBUG_CODE = false; public static boolean DEBUG_MAIN = false; /** * pieceArray. The board seen in the GUI. * This array will model the board seen in the GUI. */ private GamePiece[][] pieceArray; private PacmanFileReader pfr; private ImageIcon iiPACMAN; private ImageIcon iiGHOSTS[]; ImageIcon iiGH_RUN_AWAY; /* End of Global Declarations */ //////////////// //Constructors// //////////////// /** * Constructor * @param file_name a String file name of a board file. * file_name is also passed off to a PacmanFileReader. * @return GameBoard instance/object. */ public GameBoard(String file_name) { pfr = new PacmanFileReader(file_name); setPieceArray( pfr.getPieceArray() ); init_images(); } //end of GameBoard(String) /////////////////////// //Constructor Helpers// /////////////////////// /** * init_images. Initializes the images used in Pacman program. * initializes the provided images of the four ghosts, * the image of a ghost in run away mode, and of pacman. */ public void init_images( ) { iiPACMAN= new ImageIcon( P6Constants.PACMAN ); iiGHOSTS = new ImageIcon[4]; iiGHOSTS[0]= new ImageIcon( P6Constants.GHOST_1 ); //Ghost 1 iiGHOSTS[1]= new ImageIcon( P6Constants.GHOST_2 ); //Ghost 2 iiGHOSTS[2]= new ImageIcon( P6Constants.GHOST_3 ); //Ghost 3 iiGHOSTS[3]= new ImageIcon( P6Constants.GHOST_4 ); //Ghost 4 iiGH_RUN_AWAY= new ImageIcon( P6Constants.GH_RUN_AWAY ); } //end init_images /////////// //Methods// /////////// /** * */ protected void paintComponent( Graphics g ) { int width, height; //of rectangle Object pieceAt=null; //generic reference super.paintComponent(g); width= this.getWidth()/P6Constants.BOARD_SIZE_X; height= this.getHeight()/P6Constants.BOARD_SIZE_Y; for (int yc=0; yc