first commit

This commit is contained in:
Jose Caban
2025-06-07 01:59:34 -04:00
commit 388ac241f0
3558 changed files with 9116289 additions and 0 deletions

View File

@@ -0,0 +1,233 @@
/**
* CS1322: Programming Assignment #6 - Fall 2002
*
* <PRE>
* IDBox for: FloorPiece.java
*
* Revisions: 1.0 Nov. 21, 2002
* Created the FloorPiece class
*
* </PRE>
*
* Collaboration statement:
* "I worked on the homework assignment alone, using only
* course materials."
*
* @author
<A HREF="mailto:gtg142g@mail.gatech.edu">Roland Krystian Alberciak</A>
* @version Version 1.0, Nov. 21, 2002
*/
// imports are listed above IDBox
/**
* MODEL.
* Floorpiece. Floorpiece extends GamePiece.
* Adds the functionality of nibbles (The dots that Pacman eats).
* Each FloorPiece can have a regular nibble, a special nibble
* (one that allows Pacman to chase the ghosts),
* or neither (but not both).
*/
public class FloorPiece extends GamePiece
{
/** Debug value for toggling System.out.* output */
public static boolean DEBUG = false;
public static boolean DEBUG_MAIN = false;
/*
// =======================================================================
// Constructors
// =======================================================================
*/
/**
* Constructor 1. Specified default-overriding constructor for FloorPiece.
* @param void No parameters.
* @return FloorPiece instance/object.
*
public FloorPiece()
{
} //end of FloorPiece()
*/
/**
* Constructor 2. Specified default-overloading constructor for FloorPiece.
* Takes in the location and storage of a FloorPiece::GamePiece object
* @param x the location along the x-axis.
* @param y the location along the y-axis.
* @param hasNibble whether this FloorPiece should have a nibble
* @param hasSpecial whether this FloorPiece should have a special
* @return FloorPiece instance/object.
*/
public FloorPiece(int x, int y, boolean hasNibble, boolean hasSpecial)
{
// STUB
//if then for if both are true? override with hasSpecial=true;
super(x,y); //Chains to the super constructor. (GamePiece)
this.setNibble(hasNibble);
this.setSpecial(hasSpecial);
} //end of FloorPiece(int, int, boolean, boolean)
/*
// =======================================================================
// Methods which override class Object methods
// =======================================================================
*/
/**
* Equal instance comparison. Compares if two instances are equal.
* @param o object-type reference of (hopefully) an FloorPiece.
* @return boolean whether objects are equal.
*
public boolean equals (Object o)
{
} //end of equals(Object)
*/
/**
* toString instance printer. Prints properties of FloorPiece.
* @return System.out.println(FloorPiece instance) instance print.
*/
public String toString()
{
String result="";
if ( (getNibble()==false) && (getSpecial()==false) )
result= P6Constants.FLOOR;
else if ( (getNibble()==true) && (getSpecial()==false) )
result= P6Constants.NIBBLE;
else if ( (getNibble()==false) && (getSpecial()==true) )
result= P6Constants.SPECIAL;
else //if ( (getNibble()==true) && (getSpecial()==true) )
result= "E"; //for error. Flag to programmer.
result = result+" "; //cleanup, autoprepare for output
return result;
} //end of toString()
/*
// =======================================================================
// Class specific methods local to this instance
// =======================================================================
*/
/*
// =======================================================================
// Methods dealing directly with the data within this instance
// (accessors, modifiers, etc)
// =======================================================================
*/
/**
* Get the value of hasNibble.
* @return value of hasNibble.
*/
public boolean getNibble()
{
return hasNibble;
}
/**
* Set the value of hasNibble.
* @param v Value to assign to hasNibble.
*/
public void setNibble(boolean v)
{
this.hasNibble = v;
}
/**
* Get the value of hasSpecial.
* @return value of hasSpecial.
*/
public boolean getSpecial()
{
return hasSpecial;
}
/**
* Set the value of hasSpecial.
* @param v Value to assign to hasSpecial.
*/
public void setSpecial(boolean v)
{
this.hasSpecial = v;
}
/*
// =======================================================================
// Private Variables local to this instance
// =======================================================================
*/
/**
* hasNibble. Whether floorpiece has a regular nibble.
* Represents whether or not this FloorPiece has a nibble that Pacman eats
* (the regular ones, not the ones that lets Pacman chase Ghosts)
*/
private boolean hasNibble;
/**
* hasSpecial. Whether floorpiece has a special nibble.
* Represents whether or not this FloorPiece has a special nibble
* (the special ones which allows Pacman to chase Ghosts.)
*/
private boolean hasSpecial;
/*
// =======================================================================
// Main method (overrides this commenting system for readibility reasons)
// =======================================================================
*/
/**
* Debugging main for class FloorPiece.
* This method will rigorously test my code.
*
* <br><br>
* @param args a String array of command line arguments.
*/
public static void main(String[] args)
{
if ( (args.length==1) && (args[0].equals("-db") ) )
DEBUG_MAIN=true; //else leave false: ignore input.
if (DEBUG_MAIN)
{ // NOTE: This {} encapsulates most of main and is leftmost margin as a flag.
// redundant ifs left in, in case the main if(DEBUG) statement was ommitted,
// this would then print out neat output, as an example of real running.
FloorPiece f1 = new FloorPiece(4,7, false, false);
FloorPiece f2 = new FloorPiece(3,7, false, true);
FloorPiece f3 = new FloorPiece(2,7, true, false);
FloorPiece f4 = new FloorPiece(1,7, true, true);
System.out.println(f1);
System.out.println(f2);
System.out.println(f3);
System.out.println(f4);
if (DEBUG) System.out.println("end main(String[] args) call:");
} //end of DEBUG if
} //end of main(String[] args)
} //end of class FloorPiece

View File

@@ -0,0 +1,298 @@
import javax.swing.*;
import java.awt.*;
/**
* CS1322: Programming Assignment #6 - Fall 2002
*
* <PRE>
* IDBox for: GameBoard.java
*
* Revisions: 1.0 Nov. 24, 2002
* Created the GameBoard class
*
* </PRE>
*
* Collaboration statement:
* I collaborated with Roland Krystian Alberciak on this phase of the
* program.
*
* @author <A HREF="mailto:gtg184g@mail.gatech.edu">Jose M. Cabank</A>
* @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<P6Constants.BOARD_SIZE_Y; yc=yc+1)
{
for (int xc=0; xc<P6Constants.BOARD_SIZE_Y; xc=xc+1)
{
try{
pieceAt= pieceArray[xc][yc];
}catch (Exception e){ //Perhaps NullPointerException, perhaps not.
String err="";
err= "Perhaps pieceArray[][] has not been initialized?";
System.out.println(err);
}
if (pieceAt instanceof WallPiece){
g.setColor(P6Constants.WALL_COLOR);
g.drawRect(xc*width,yc*height,width,height);//draw
g.fillRect(xc*width,yc*height,width,height);//then fill
} //endif
else if (pieceAt instanceof FloorPiece)
{
FloorPiece fpTemp = (FloorPiece)pieceAt;
// First we make a default floor Piece, where we assume
// (fpTemp.getNibble()==false) && (fpTemp.getSpecial()==false)
g.setColor(P6Constants.FLOOR_COLOR);
g.drawRect(xc*width,yc*height,width,height);//draw
g.fillRect(xc*width,yc*height,width,height);//then fill
//then we modify over it.
if (
(fpTemp.getNibble()==true)
&& (fpTemp.getSpecial()==false)
) //Floor with Nibble but not a Special.
{
g.setColor(P6Constants.NIBBLE_COLOR);
g.drawRect(xc*width+width/2-width/4,
yc*height+height/2-height/4,
width/4,
height/4);//draw
g.fillRect(xc*width+width/2-width/4,
yc*height+height/2-height/4,
width/4,
height/4);//then fill
}//endif
else if (
(fpTemp.getNibble()==false)
&& (fpTemp.getSpecial()==true)
)
{
g.setColor(P6Constants.SPECIAL_COLOR);
g.drawRect(xc*width+width/2-width/4,
yc*height+height/2-height/4,
width/4,
height/4);//draw
g.fillRect(xc*width+width/2-width/4,
yc*height+height/2-height/4,
width/4,
height/4);//then fill
}// endelse
//for error. Flag to programmer to correct something.
else if (
(fpTemp.getNibble()==true)
&& (fpTemp.getSpecial()==true)
)
{
String errMsg="";
errMsg=" Error: Cannot draw Nibble with Special";
String fpWas="";
fpWas="A floorpiece of:"+ fpTemp.toString()+" ";
System.out.println(this.getClass()+fpWas+"\n"+errMsg);
} //endelse
}//endelse
}//end xc-for
}//end yc-for
//Now to draw Pacman, Ghosts.
// First, Pacman.
g.drawImage(iiPACMAN.getImage(),
pfr.getPacman().getX()*width, //get X position on board..
pfr.getPacman().getY()*height, //get Y position on board..
iiPACMAN.getImageObserver()
);
// Now, the Ghosts.
for (int loop=0; loop<iiGHOSTS.length; loop=loop+1)
{
Ghost tempG = pfr.getGhosts()[loop];
if (tempG.getRunAwayFlag()==false) //draw normal Ghost
g.drawImage(iiGHOSTS[loop].getImage(),
tempG.getX()*width, //get X position on board..
tempG.getY()*height, //get Y position on board..
iiGHOSTS[loop].getImageObserver()
);
else // if (tempG.getRunAwayFlag()==true) //draw spooked Ghost
g.drawImage(iiGH_RUN_AWAY.getImage(),
tempG.getX()*width, //get X position on board..
tempG.getY()*height, //get Y position on board..
iiGH_RUN_AWAY.getImageObserver()
);
}//endfor-go through ghosts
} //end PaintComponent(Graphics)
///////////////////////
//Accessors/Modifiers//
///////////////////////
/**
* Get the value of pieceArray.
* @return value of pieceArray.
*/
public GamePiece[][] getPieceArray()
{
return pieceArray;
}
/**
* Set the value of pieceArray.
* @param v Value to assign to pieceArray.
*/
public void setPieceArray(GamePiece[][] v)
{
this.pieceArray = v;
}
/**
* Get the value of pfr.
* @return value of pfr.
*/
public PacmanFileReader getPfr()
{
return pfr;
}
/**
* Set the value of pfr.
* @param v Value to assign to pfr.
*/
public void setPfr(PacmanFileReader v)
{
this.pfr = v;
}
/*
// =======================================================================
// Main method (overrides this commenting system for readibility reasons)
// =======================================================================
*/
/**
* Debugging main for class GameBoard.
* This method will rigorously test my code.
*
* <br><br>
* @param args a String array of command line arguments.
*/
public static void main(String[] args)
{
if ( (args.length==1) && (args[0].equals("-db") ) )
DEBUG_MAIN=true; //else leave false: ignore input.
if (DEBUG_MAIN)
{ // NOTE: This {} encapsulates most of main and is leftmost margin as a flag.
// redundant ifs left in, in case the main if(DEBUG) statement was ommitted,
// this would then print out neat output, as an example of real running.
if (DEBUG) System.out.println("end main(String[] args) call:");
} //end of DEBUG if
} //end of main(String[] args)
} //end of class GameBoard

View File

@@ -0,0 +1,214 @@
/**
* CS1322: Programming Assignment #6 - Fall 2002
*
* <PRE>
* IDBox for: GamePiece.java
*
* Revisions: 1.0 Nov. 21, 2002
* Created the GamePiece class
*
* </PRE>
*
* Collaboration statement:
* "I worked on the homework assignment alone, using only
* course materials."
*
* @author
<A HREF="mailto:gtg142g@mail.gatech.edu">Roland Krystian Alberciak</A>
* @version Version 1.0, Nov. 21, 2002
*/
// imports are listed above IDBox
/**
* MODEL.
* GamePiece. GamePiece is abstract.
* This class is the super class to all pieces of the game board.
*/
public abstract class GamePiece
{
/** Debug value for toggling System.out.* output */
public static boolean DEBUG = false;
public static boolean DEBUG_MAIN = false;
/*
// =======================================================================
// Constructors
// =======================================================================
*/
/**
* Constructor 1. Specified default-overriding constructor for GamePiece.
* @param void No parameters.
* @return GamePiece instance/object.
*
public GamePiece()
{
} //end of GamePiece()
*/
/**
* Constructor 2. Specified default-overloading constructor for GamePiece.
* @param x the location along the x-axis.
* @param y the location along the y-axis.
* @return GamePiece instance/object.
*/
public GamePiece( int x, int y )
{
this.setPosition(x,y);
} //end of GamePiece(int, int)
/*
// =======================================================================
// Methods which override class Object methods
// =======================================================================
*/
/**
* Equal instance comparison. Compares if two instances are equal.
* @param o object-type reference of (hopefully) an GamePiece.
* @return boolean whether objects are equal.
*
public boolean equals (Object o)
{
} //end of equals(Object)
*/
/**
* toString instance printer. Prints properties of GamePiece.
* @return System.out.println(GamePiece instance) instance print.
*
public String toString()
{
} //end of toString()
*/
/*
// =======================================================================
// Class specific methods local to this instance
// =======================================================================
*/
/**
* setPosition. Sets the location variables to passed in x,y parameters.
* @param x the new location along the x-axis.
* @param y the new location along the y-axis.
*/
public void setPosition( int x, int y )
{
this.setX(x);
this.setY(y);
} //end of setPosition(int, int)
/*
// =======================================================================
// Methods dealing directly with the data within this instance
// (accessors, modifiers, etc)
// =======================================================================
*/
/**
* Get the value of x.
* @return value of x.
*/
public int getX()
{
return x;
} //end of getX()
/**
* Set the value of x.
* @param v Value to assign to x.
*/
public void setX(int v)
{
this.x = v;
} //end of setX(int)
/**
* Get the value of y.
* @return value of y.
*/
public int getY()
{
return y;
} //end of getY()
/**
* Set the value of y.
* @param v Value to assign to y.
*/
public void setY(int v)
{
this.y = v;
} //end of setY(int)
/*
// =======================================================================
// Private/Protected Variables local to this instance
// =======================================================================
*/
/**
* Together these two variables represent the exact location of the
* board this particular piece is in. The location (0,0) is the
* upper left hand corner of the game board.
*/
/**
* x. Column placeholder.
* This variable represents which column the piece is in.
* i.e., it's location along the x-axis.(the top edge of the screan)
*/
protected int x;
/**
* y. Row placeholder.
* This variable representswhich row the piece is in.
* i.e., it's location along the y-axis. (the side edge of the screan)
*/
protected int y;
/*
// =======================================================================
// Main method (overrides this commenting system for readibility reasons)
// =======================================================================
*/
/**
* Debugging main for class GamePiece.
* This method will rigorously test my code.
*
* <br><br>
* @param args a String array of command line arguments.
*/
public static void main(String[] args)
{
if ( (args.length==1) && (args[0].equals("-db") ) )
DEBUG_MAIN=true; //else leave false: ignore input.
if (DEBUG_MAIN)
{ // NOTE: This {} encapsulates most of main and is leftmost margin as a flag.
// redundant ifs left in, in case the main if(DEBUG) statement was ommitted,
// this would then print out neat output, as an example of real running.
if (DEBUG) System.out.println("end main(String[] args) call:");
} //end of DEBUG if
} //end of main(String[] args)
} //end of class GamePiece

View File

@@ -0,0 +1,396 @@
/**
* CS1322: Programming Assignment #6 - Fall 2002
*
* <PRE>
* IDBox for: Ghost.java
*
* Revisions: 1.0 Nov. 23, 2002
* Created the Ghost class
*
* </PRE>
*
* Collaboration statement:
* "I worked on the homework assignment alone, using only
* course materials."
*
* @author
<A HREF="mailto:gtg142g@mail.gatech.edu">Roland Krystian Alberciak</A>
* @version Version 1.0, Nov. 23, 2002
*/
// imports are listed above IDBox
/**
* MODEL.
* Ghost. Ghost extends MoveablePiece.
* This class will model the Ghost piece which the AI will control.
*/
public class Ghost extends MoveablePiece
{
/** Debug value for toggling System.out.* output */
public static boolean DEBUG = false;
public static boolean DEBUG_CODE = false;
public static boolean DEBUG_MAIN = false;
/*
// =======================================================================
// Constructors
// =======================================================================
*/
/**
* Constructor 1. Specified default-overriding constructor for Ghost.
* @param void No parameters.
* @return Ghost instance/object.
*
public Ghost()
{
} //end of Ghost()
*/
/**
* Constructor 2. Specified default-overloading constructor for Ghost.
* @param x the location along the x-axis.
* @param y the location along the y-axis.
* @param ghostNum this ghost's number.
* @return Ghost instance/object.
*/
public Ghost( int x, int y, int ghostNum )
{
super(x,y);
this.setStartX(x);
this.setStartY(y);
this.setGhostNum(ghostNum);
} //end of Ghost(int, int, int)
/*
// =======================================================================
// Methods which override class Object methods
// =======================================================================
*/
/**
* Equal instance comparison. Compares if two instances are equal.
* @param o object-type reference of (hopefully) an Ghost.
* @return boolean whether objects are equal.
*
public boolean equals (Object o)
{
} //end of equals(Object)
*/
/**
* toString instance printer. Prints properties of Ghost.
* @return System.out.println(Ghost instance) instance print.
*/
public String toString()
{
String result="";
result = "I am Ghost #"+getGhostNum()+
" located at (x,y): (" +getX()+", "+getY()+")";
return result;
} //end of toString()
/*
// =======================================================================
// Class specific methods local to this instance (ex: forced by interface)
// =======================================================================
*/
/**
* runAway. Modifies this instance's runAwayFlag and runAwayCount.
* [1.]: Sets runAwayFlag to true and
* [2.]: Initializes runAwayCount to RUN_AWAY_DURATION from P6Constants
*/
public void runAway()
{
this.setRunAwayFlag(true);
this.setRunAwayCount(P6Constants.RUN_AWAY_DURATION);
}
/**
* resetGhost. Modifies this instance's runAwayFlag and startX, startY
* This method will be invoked if this ghost is eaten by Pacman.
* [1.]: Turns runAwayFlag to false and
* [2.]: Returns the ghost to its start coordinates.
*/
public void resetGhost()
{
this.setRunAwayFlag(false);
setPosition( getStartX(), getStartY() );
}
/**
* getMove. Calculate the array of size four containing this ghost's choices
of movement as described above. Feel free to use the GhostAI
class. Keep in mind however that the getGhostMove method
provided assumes the ghost is chasing pacman. You will need to
modify the array to have the ghost run away from Pacman if this
is the case. If the Ghost is indeed running from Pacman, be sure
to deduct a turn from runAwayCount and check to see if
runAwayCount is zero, in which case you should have the ghost no
longer run from Pacman. This method will not actually set the
location of the ghost based on the GhostAI method. It simply
returns the array of choices. We do this because this ghost has
no clue whether any of its choices will take it into a wall. A
class later in the project will process the choices and decide
which moves are legal for this ghost. The ghost will then be
told which way to move.
* @param pacmanX Pacman's x location.
* @param pacmanY Pacman's y location.
* @return int[] Ghost's choices of movement (as done in GhostAI)
*/
public int[] getMove( int pacmanX, int pacmanY ) // Pacman's x, y
{
int result[];
if (getRunAwayFlag() == false) // ghost chasing pacman
{
result = GhostAI.getGhostMove(
getX(), //ghost's X (from GamePiece)
getY(), //ghost's Y (from GamePiece)
pacmanX, //pacman's X (from parameter)
pacmanY //pacman's Y (from parameter)
);
}
else // (getRunAwayFlag() == true) // ghost fleeing pacman
{
result = GhostAI.getGhostMove(
getX(), //ghost's X (from GamePiece)
getY(), //ghost's Y (from GamePiece)
pacmanX, //pacman's X (from parameter)
pacmanY //pacman's Y (from parameter)
);
int temp;
int left= 0;
int right= result.length-1;
while (left < right) //reverse result array (flip across middle)
{
temp = result[left];
result[left]=result[right];
result[right]=temp;
left=left+1;
right=right-1;
} //endwhile
// Preferable to a switch statement because of the >0. (case 1,2,3...)
if (getRunAwayCount() > 0) //for all integers I such that I>=1
this.setRunAwayCount( getRunAwayCount()-1 );
else if (getRunAwayCount()==0) //0 is min value & known at this point.
this.setRunAwayFlag(false); //get Pacman!
else // (getRunAwayCount()<0) //Error condition
System.out.println("An error has occurred, getRunAwayCount<0");
}
return result;
}
/*
// =======================================================================
// Methods dealing directly with the data within this instance
// (accessors, modifiers, etc)
// =======================================================================
*/
/**
* Get the value of ghostNum.
* @return value of ghostNum.
*/
public int getGhostNum()
{
return ghostNum;
}
/**
* STUB - MAKE PRIVATE
* Set the value of ghostNum.
* @param v Value to assign to ghostNum.
*/
private void setGhostNum(int v)
{
this.ghostNum = v;
}
/**
* Get the value of runAwayFlag.
* @return value of runAwayFlag.
*/
public boolean getRunAwayFlag()
{
return runAwayFlag;
}
/**
* STUB - MAKE PRIVATE
* Set the value of runAwayFlag.
* @param v Value to assign to runAwayFlag.
*/
private void setRunAwayFlag(boolean v)
{
this.runAwayFlag = v;
}
/**
* STUB - REVIEW MAKE PRIVATE
* Get the value of runAwayCount.
* @return value of runAwayCount.
*/
public int getRunAwayCount()
{
return runAwayCount;
}
/**
* STUB - MAKE PRIVATE
* Set the value of runAwayCount.
* @param v Value to assign to runAwayCount.
*/
private void setRunAwayCount(int v)
{
this.runAwayCount = v;
}
/**
* Get the value of startX.
* @return value of startX.
*/
public int getStartX()
{
return startX;
}
/**
* STUB - MAKE PRIVATE
* Set the value of startX.
* @param v Value to assign to startX.
*/
private void setStartX(int v)
{
this.startX = v;
}
/**
* Get the value of startY.
* @return value of startY.
*/
public int getStartY()
{
return startY;
}
/**
* STUB - MAKE PRIVATE
* Set the value of startY.
* @param v Value to assign to startY.
*/
private void setStartY(int v)
{
this.startY = v;
}
/*
// =======================================================================
// Protected Variables local to this instance
// =======================================================================
*/
/*
// =======================================================================
// Private Variables local to this instance
// =======================================================================
*/
/**
* ghostNum. The number of the ghost.
*/
private int ghostNum;
/**
* runAwayFlag. Flag representing whether or not ghost is hunting Pacman.
* true if this Ghost is running from Pacman, and
* false if the Ghost is chasing Pacman.
*/
private boolean runAwayFlag;
/**
* runAwayCount. Contains the number of returns remaining
* for this ghost to run from Pacman.
* (A ghost will run from Pacman for a fixed number of moves
* if Pacman eats a special nibble).
*/
private int runAwayCount;
/**
* startX. Contains the starting x coordinate for this ghost.
*/
private int startX;
/**
* startY. Contains the starting y coordinate for this ghost.
*/
private int startY;
/*
// =======================================================================
// Main method (overrides this commenting system for readibility reasons)
// =======================================================================
*/
/**
* Debugging main for class Ghost.
* This method will rigorously test my code.
*
* <br><br>
* @param args a String array of command line arguments.
*/
public static void main(String[] args)
{
if ( (args.length==1) && (args[0].equals("-db") ) )
DEBUG_MAIN=true; //else leave false: ignore input.
if (DEBUG_MAIN)
{ // NOTE: This {} encapsulates most of main and is leftmost margin as a flag.
// redundant ifs left in, in case the main if(DEBUG) statement was ommitted,
// this would then print out neat output, as an example of real running.
Ghost g1 = new Ghost(4,6,1);
Ghost g2 = new Ghost(7,3,2);
Ghost g3 = new Ghost(8,5,3);
Ghost g4 = new Ghost(4,4,4);
System.out.println(g1);
System.out.println(g2);
System.out.println(g3);
System.out.println(g4);
System.out.println("Ghost's class is:" +g1.getClass().getName());
if (DEBUG) System.out.println("end main(String[] args) call:");
} //end of DEBUG if
} //end of main(String[] args)
} //end of class Ghost

View File

@@ -0,0 +1,197 @@
/**
* CS1322: Programming Assignment #6 - Fall 2002
*
* <PRE>
* IDBox for: MoveablePiece.java
*
* Revisions: 1.0 Nov. 21, 2002
* Created the MoveablePiece class
*
* </PRE>
*
* Collaboration statement:
* "I worked on the homework assignment alone, using only
* course materials."
*
* @author
<A HREF="mailto:gtg142g@mail.gatech.edu">Roland Krystian Alberciak</A>
* @version Version 1.0, Nov. 21, 2002
*/
// imports are listed above IDBox
/**
* MODEL.
* MoveablePiece. MoveablePiece is abstract and extends GamePiece.
* This class will be the super class of both Ghost and Pacman.
*/
public abstract class MoveablePiece extends GamePiece
{
/** Debug value for toggling System.out.* output */
public static boolean DEBUG = false;
public static boolean DEBUG_MAIN = false;
/*
// =======================================================================
// Constructors
// =======================================================================
*/
/**
* Constructor 1. Specified default-overriding constructor for MoveablePiece.
* @param void No parameters.
* @return MoveablePiece instance/object.
*
public MoveablePiece()
{
} //end of MoveablePiece()
*/
/**
* Constructor 2. Specified default-overloading constructor for MoveablePiece.
* @param x the location along the x-axis.
* @param y the location along the y-axis.
* @return MoveablePiece instance/object.
*/
public MoveablePiece( int x, int y )
{
super(x,y); //Chains to the super constructor. (GamePiece)
} //end of MoveablePiece(int, int)
/*
// =======================================================================
// Methods which override class Object methods
// =======================================================================
*/
/**
* Equal instance comparison. Compares if two instances are equal.
* @param o object-type reference of (hopefully) an MoveablePiece.
* @return boolean whether objects are equal.
*
public boolean equals (Object o)
{
} //end of equals(Object)
*/
/**
* toString instance printer. Prints properties of MoveablePiece.
* @return System.out.println(MoveablePiece instance) instance print.
*
public String toString()
{
} //end of toString()
*/
/*
// =======================================================================
// Class specific methods local to this instance
// =======================================================================
*/
/*
// =======================================================================
// Methods dealing directly with the data within this instance
// (accessors, modifiers, etc)
// =======================================================================
*/
/**
* move. Moves the GamePiece.
* Takes in an int representing a direction. In this
* method the piece is "moved".
* (The piece has it's x or y location modifed accordingly.)
* Remember: (0,0) is the top left corner of the board.
* @param direction direction to move GamePiece.
* Is either NORTH, EAST, SOUTH, or WEST from P6Constants.
* Represents up, right, down and left respectively.
*/
public void move( int direction )
{
switch (direction)
{
case (P6Constants.NORTH):
super.setX( getX() );
super.setY( (getY()-1) );
break;
case (P6Constants.EAST):
super.setX( (getX()+1) );
super.setY( getY() );
break;
case (P6Constants.SOUTH):
super.setX( getX() );
super.setY( (getY()+1) );
break;
case (P6Constants.WEST):
super.setX( (getX()-1) );
super.setY( getY() );
break;
default:
System.out.println("An error in possible directions");
} //endswitch
/*
if (direction == NORTH)
this( getX(), getY()-1 );
else if (direction == EAST)
this( getX()+1, getY() );
else if (direction == SOUTH)
this( getX(), getY()+1 );
else if (direction == WEST)
this( getX()-1,getY() );
else
System.out.println("An error in possible directions");
*/
}
/*
// =======================================================================
// Private Variables local to this instance
// =======================================================================
*/
/*
// =======================================================================
// Main method (overrides this commenting system for readibility reasons)
// =======================================================================
*/
/**
* Debugging main for class MoveablePiece.
* This method will rigorously test my code.
*
* <br><br>
* @param args a String array of command line arguments.
*/
public static void main(String[] args)
{
if ( (args.length==1) && (args[0].equals("-db") ) )
DEBUG_MAIN=true; //else leave false: ignore input.
if (DEBUG_MAIN)
{ // NOTE: This {} encapsulates most of main and is leftmost margin as a flag.
// redundant ifs left in, in case the main if(DEBUG) statement was ommitted,
// this would then print out neat output, as an example of real running.
if (DEBUG) System.out.println("end main(String[] args) call:");
} //end of DEBUG if
} //end of main(String[] args)
} //end of class MoveablePiece

View File

@@ -0,0 +1,61 @@
/**
* CS1322: Programming Assignment #6 - Fall 2002
*
* <PRE>
* IDBox for: P6.java
*
* Revisions: 1.0 Nov. 25, 2002
* Created the P6 class
*
* </PRE>
*
* Collaboration statement:
* "I worked on the homework assignment alone, using only
* course materials."
*
* @author
<A HREF="mailto:gtg142g@mail.gatech.edu">Roland Krystian Alberciak</A>
* @version Version 1.0, Nov. 25, 2002
*/
// imports are listed above IDBox
public class P6
{
/** Debug value for toggling System.out.* output */
public static boolean DEBUG = false;
public static boolean DEBUG_CODE = false;
public static boolean DEBUG_MAIN = true;
/*
// =======================================================================
// Main method (overrides this commenting system for readibility reasons)
// =======================================================================
*/
/**
* Debugging main for class P6.
* This method will rigorously test my code.
*
* <br><br>
* @param args a String array of command line arguments.
*/
public static void main(String[] args)
{
if ( (args.length==1) && (args[0].equals("-db") ) )
DEBUG_MAIN=true; //else leave false: ignore input.
if (DEBUG_MAIN)
{ // NOTE: This {} encapsulates most of main and is leftmost margin as a flag.
// redundant ifs left in, in case the main if(DEBUG) statement was ommitted,
// this would then print out neat output, as an example of real running.
PacmanFrame pf = new PacmanFrame();
if (DEBUG) System.out.println("end main(String[] args) call:");
} //end of DEBUG if
} //end of main(String[] args)
} //end of class P6

View File

@@ -0,0 +1,86 @@
/**
* <PRE>
* P6Constants.java
*
* Revisions: 1.0 Aug. 25, 2002
* Created the P6Constants class
*
* </PRE>
*
* @author <A HREF="mailto:bsbeck@cc.gatech.edu">Brandon Beck</A>
* @version Version 1.0, Aug. 25, 2002
*/
public interface P6Constants {
//The color of Walls
public static final java.awt.Color WALL_COLOR = java.awt.Color.blue;
//The color of Floors
public static final java.awt.Color FLOOR_COLOR = java.awt.Color.black;
//The color of a regular nibble
public static final java.awt.Color NIBBLE_COLOR = java.awt.Color.yellow;
//The color of a special nibble
public static final java.awt.Color SPECIAL_COLOR = java.awt.Color.orange;
//The name of the file to parse to obtain the board
public static final String BOARD_FILE = "board_1.txt";
//The image file containing Pacman
public static final String PACMAN = "pacman.gif";
//The four image files containing each of the ghosts while chasing pacman
public static final String GHOST_1 = "gh1.gif";
public static final String GHOST_2 = "gh2.gif";
public static final String GHOST_3 = "gh3.gif";
public static final String GHOST_4 = "gh4.gif";
//The image file applied to all ghosts while running from pacman
public static final String GH_RUN_AWAY = "ghRA.gif";
//The constant representing a WallPiece in a board file
public static final String WALL = "w";
//The constant representing a FloorPiece no nibbles in a board file
public static final String FLOOR = "f";
//The constant indicating a FloorPiece with a special nibble in
//a board file
public static final String SPECIAL = "s";
//The constant indicating a FloorPiece with a regular nibble in
//a board file
public static final String NIBBLE = "n";
//The number of columns (or pieces in one row) on the board
public static final int BOARD_SIZE_X = 15;
//The number of rows (or pieces in one column) on the board
public static final int BOARD_SIZE_Y = 15;
//The constant representing "up"
public static final int NORTH = 0;
//The constant representing "right"
public static final int EAST = 1;
//The constant representing "down"
public static final int SOUTH = 2;
//The constant representing "left"
public static final int WEST = 3;
//The number of moves a Ghost makes while running from Pacman before it
//returns to the state of chasing Pacman
public static final int RUN_AWAY_DURATION = 20;
//The interval between firings of the PacmanTimer controlling Pacman movements
public static final int PACMAN_INTERVAL = 350;
//The interval between firings of the GhostTimer controlling all Ghost movements
public static final int GHOST_INTERVAL = 500;
}// end of interface P6Constants

View File

@@ -0,0 +1,189 @@
/**
* CS1322: Programming Assignment #6 - Fall 2002
*
* <PRE>
* IDBox for: Pacman.java
*
* Revisions: 1.0 Nov. 23, 2002
* Created the Pacman class
*
* </PRE>
*
* Collaboration statement:
* "I worked on the homework assignment alone, using only
* course materials."
*
* @author
<A HREF="mailto:gtg142g@mail.gatech.edu">Roland Krystian Alberciak</A>
* @version Version 1.0, Nov. 23, 2002
*/
// imports are listed above IDBox
/**
* MODEL.
* Pacman. Pacman extends MoveablePiece.
* This class will model the Pacman piece which the user will control.
*/
public class Pacman extends MoveablePiece
{
/** Debug value for toggling System.out.* output */
public static boolean DEBUG = false;
public static boolean DEBUG_CODE = false;
public static boolean DEBUG_MAIN = false;
/*
// =======================================================================
// Constructors
// =======================================================================
*/
/**
* Constructor 1. Specified default-overriding constructor for Pacman.
* @param void No parameters.
* @return Pacman instance/object.
*
public Pacman()
{
} //end of Pacman()
*/
/**
* Constructor 2. Specified default-overloading constructor for Pacman.
* Takes in the location of the Pacman::MoveablePiece::GamePiece.
* @param x the location along the x-axis.
* @param y the location along the y-axis.
* @return Pacman instance/object.
*/
public Pacman(int x, int y)
{
super(x,y); //Chains to the super constructor. (MoveablePiece)
} //end of Pacman(int, int)
/*
// =======================================================================
// Methods which override class Object methods
// =======================================================================
*/
/**
* Equal instance comparison. Compares if two instances are equal.
* @param o object-type reference of (hopefully) an Pacman.
* @return boolean whether objects are equal.
*
public boolean equals (Object o)
{
} //end of equals(Object)
*/
/**
* toString instance printer. Prints properties of Pacman.
* @return System.out.println(Pacman instance) instance print.
*/
public String toString()
{
String result="";
result = "I am Pacman!! located at (x,y): (" +getX()+", "+getY()+")";
return result;
} //end of toString()
/*
// =======================================================================
// Class specific methods local to this instance (ex: forced by interface)
// =======================================================================
*/
/*
// =======================================================================
// Methods dealing directly with the data within this instance
// (accessors, modifiers, etc)
// =======================================================================
*/
/**
* Get the value of direction.
* @return value of direction.
*/
public int getDirection()
{
return direction;
}
/**
* Set the value of direction.
* @param v Value to assign to direction.
*/
public void setDirection(int v)
{
this.direction = v;
}
/*
// =======================================================================
// Protected Variables local to this instance
// =======================================================================
*/
/*
// =======================================================================
// Private Variables local to this instance
// =======================================================================
*/
/**
* direction. Contain one of the four constants from P6Constants:
* NORTH, EAST, SOUTH, WEST.
* Represents the direction Pacman is currently heading on the board.
* This variable is by default initialized to EAST.
*/
private int direction = P6Constants.EAST;
/*
// =======================================================================
// Main method (overrides this commenting system for readibility reasons)
// =======================================================================
*/
/**
* Debugging main for class Pacman.
* This method will rigorously test my code.
*
* <br><br>
* @param args a String array of command line arguments.
*/
public static void main(String[] args)
{
if ( (args.length==1) && (args[0].equals("-db") ) )
DEBUG_MAIN=true; //else leave false: ignore input.
if (DEBUG_MAIN)
{ // NOTE: This {} encapsulates most of main and is leftmost margin as a flag.
// redundant ifs left in, in case the main if(DEBUG) statement was ommitted,
// this would then print out neat output, as an example of real running.
Pacman pm = new Pacman(2,6);
System.out.println(pm);
if (DEBUG) System.out.println("end main(String[] args) call:");
} //end of DEBUG if
} //end of main(String[] args)
} //end of class Pacman

View File

@@ -0,0 +1,342 @@
import javax.swing.*; //includes Timer
import java.awt.event.*; //ActionListener
/**
* CS1322: Programming Assignment #6 - Fall 2002
*
* <PRE>
* IDBox for: PacmanEngine.java
*
* Revisions: 1.0 Nov. 24, 2002
* Created the PacmanEngine class
*
* </PRE>
*
* Collaboration statement:
* "I worked on the homework assignment alone, using only
* course materials."
*
* @author
<A HREF="mailto:gtg142g@mail.gatech.edu">Roland Krystian Alberciak</A>
* @version Version 1.0, Nov. 24, 2002
*/
// imports are listed above IDBox
/*
* CONTROLLER
*/
public class PacmanEngine implements ActionListener, KeyListener
{
/** Debug value for toggling System.out.* output */
public static boolean DEBUG = false;
public static boolean DEBUG_CODE = false;
public static boolean DEBUG_MAIN = false;
/*
// =======================================================================
// Constructors
// =======================================================================
*/
/**
* Constructor 1. Specified default-overriding constructor for PacmanEngine.
* @param void No parameters.
* @return PacmanEngine instance/object.
*
public PacmanEngine()
{
} //end of PacmanEngine()
*/
/**
* Constructor 2. Specified default-overloading constructor for PacmanEngine.
* @param void No parameters.
* @return PacmanEngine instance/object.
*/
public PacmanEngine(PacmanFrame pmf, GameBoard gb)
{
this.setPmf( pmf );
this.setBoard( gb );
this.setGhosts( gb.getPfr().getGhosts() );
this.setPacman( gb.getPfr().getPacman() );
/*
GhostTimer= new Timer(P6Constants.GHOST_INTERVAL, ); //add AL
PacmanTimer = new Timer(P6Constants.PACMAN_INTERVAL, ); //add AL
*/
} //end of PacmanEngine()
/*
// =======================================================================
// Methods which override class Object methods
// =======================================================================
*/
/**
* Equal instance comparison. Compares if two instances are equal.
* @param o object-type reference of (hopefully) an PacmanEngine.
* @return boolean whether objects are equal.
*
public boolean equals (Object o)
{
} //end of equals(Object)
*/
/**
* toString instance printer. Prints properties of PacmanEngine.
* @return System.out.println(PacmanEngine instance) instance print.
*
public String toString()
{
} //end of toString()
*/
/*
// =======================================================================
// Class specific methods local to this instance (ex: forced by interface)
// =======================================================================
*/
public void actionPerformed(ActionEvent ae)
{
int togglePG=0;
//CALL REPAINT
if( (ae.getSource() instanceof Timer) ==true )
{
//Now to determine if moves are legal
if
(
(ae.getActionCommand()=="PacmanTimer")
|| (ae.getActionCommand()=="GhostTimer")
)
{
checkMoveValid(
pacman.getDirection(),
pacman.getX(),
pacman.getY(),
this.board.getPieceArray()[pacman.getX()][pacman.getY()]
);
}
else
System.out.println(this.getClass()+" error: wrong Timer.");
if (this.legal==true)
{
if (ae.getActionCommand()=="PacmanTimer")
getPacman().move(pacman.getDirection());
if (ae.getActionCommand()=="GhostTimer")
{
int gMoves[];
for(int itr=0; itr<getGhosts().length; itr=itr+1)
gMoves= getGhosts()[itr].getMove(this.pacman.getX(),
this.pacman.getY()
);
}
}
}
}
// returns true if valid, false if not.
public void checkMoveValid( int direction, int xAt, int yAt, Object piece )
{
boolean result=false;
switch (direction)
{
case (P6Constants.NORTH):
break;
case (P6Constants.EAST):
break;
case (P6Constants.SOUTH):
break;
case (P6Constants.WEST):
break;
}
this.legal=result;
}
/**
* Invoked when a key has been pressed.
*/
public void keyPressed(KeyEvent e) {}
/**
* Invoked when a key has been released.
*/
public void keyReleased(KeyEvent e) {}
/**
* Invoked when a key has been typed.
*/
public void keyTyped(KeyEvent e) {}
/*
// =======================================================================
// Methods dealing directly with the data within this instance
// (accessors, modifiers, etc)
// =======================================================================
*/
/**
* Get the value of pmf.
* @return value of pmf.
*/
public PacmanFrame getPmf() {
return pmf;
}
/**
* Set the value of pmf.
* @param v Value to assign to pmf.
*/
public void setPmf(PacmanFrame v) {
this.pmf = v;
}
/**
* Get the value of pacman.
* @return value of pacman.
*/
public Pacman getPacman()
{
return pacman;
}
/**
* Set the value of pacman.
* @param v Value to assign to pacman.
*/
public void setPacman(Pacman v)
{
this.pacman = v;
}
/**
* Get the value of ghosts.
* @return value of ghosts.
*/
public Ghost[] getGhosts()
{
return ghosts;
}
/**
* Set the value of ghosts.
* @param v Value to assign to ghosts.
*/
public void setGhosts(Ghost[] v)
{
this.ghosts = v;
}
/**
* Get the value of board.
* @return value of board.
*/
public GameBoard getBoard() {
return board;
}
/**
* Set the value of board.
* @param v Value to assign to board.
*/
public void setBoard(GameBoard v) {
this.board = v;
}
/*
// =======================================================================
// Protected Variables local to this instance
// =======================================================================
*/
/*
// =======================================================================
// Private Variables local to this instance
// =======================================================================
*/
private Timer GhostTimer;
private Timer PacmanTimer;
/*
* board. GameBoard instance.
* The GameBoard instance used to draw the state of the board.
*/
private GameBoard board;
private PacmanFrame pmf;
private Ghost[] ghosts;
/**
* pacman. Pacman instance.
* The Pacman instance in play.
*/
private Pacman pacman;
private boolean legal;
/*
// =======================================================================
// Main method (overrides this commenting system for readibility reasons)
// =======================================================================
*/
/**
* Debugging main for class PacmanEngine.
* This method will rigorously test my code.
*
* <br><br>
* @param args a String array of command line arguments.
*/
public static void main(String[] args)
{
if ( (args.length==1) && (args[0].equals("-db") ) )
DEBUG_MAIN=true; //else leave false: ignore input.
if (DEBUG_MAIN)
{ // NOTE: This {} encapsulates most of main and is leftmost margin as a flag.
// redundant ifs left in, in case the main if(DEBUG) statement was ommitted,
// this would then print out neat output, as an example of real running.
if (DEBUG) System.out.println("end main(String[] args) call:");
} //end of DEBUG if
} //end of main(String[] args)
} //end of class PacmanEngine

View File

@@ -0,0 +1,411 @@
import java.util.*;
import java.io.*;
/**
* CS1322: Programming Assignment #6 - Fall 2002
*
* <PRE>
* IDBox for: PacmanFileReader.java
*
* Revisions: 1.0 Nov. 23, 2002
* Created the PacmanFileReader class
*
* </PRE>
*
* Collaboration statement:
* "I worked on the homework assignment alone, using only
* course materials."
*
* @author
<A HREF="mailto:gtg142g@mail.gatech.edu">Roland Krystian Alberciak</A>
* @version Version 1.0, Nov. 23, 2002
*/
// imports are listed above IDBox
public class PacmanFileReader
{
/** Debug value for toggling System.out.* output */
public static boolean DEBUG = false;
public static boolean DEBUG_CODE = false;
public static boolean DEBUG_MAIN = false;
/*
// =======================================================================
// Constructors
// =======================================================================
*/
/**
* Constructor 1. Specified default-overriding constructor for PacmanFileReader.
* @param void No parameters.
* @return PacmanFileReader instance/object.
*
public PacmanFileReader()
{
} //end of PacmanFileReader()
*/
/**
* Constructor 2. Specified default-overloading constructor for PacmanFileReader.
* @param file_name a String file name of a board file
* @return PacmanFileReader instance/object.
*/
public PacmanFileReader(String file_name)
{
ghosts = new Ghost[4]; //0->1, 1->2, 2->3, 3->4
this.FILE_NAME=file_name;
pieceArray=new GamePiece[15][15];
read_5_lines();
read_15_lines();
} //end of PacmanFileReader(String)
/*
// =======================================================================
// Methods which override class Object methods
// =======================================================================
*/
/**
* Equal instance comparison. Compares if two instances are equal.
* @param o object-type reference of (hopefully) an PacmanFileReader.
* @return boolean whether objects are equal.
*
public boolean equals (Object o)
{
} //end of equals(Object)
*/
/**
* toString instance printer. Prints properties of PacmanFileReader.
* @return System.out.println(PacmanFileReader instance) instance print.
*/
public String toString()
{
String result="";
result= result+pacman.toString()+"\n"; //gets toString of Pacman.
for (int i=0; i<ghosts.length; i=i+1)
result= result+ghosts[i].toString()+"\n"; //gets toString of ghosts.
for (int y=0; y<15; y=y+1)
{
for (int x=0; x<15; x=x+1)
result=result+pieceArray[x][y].toString();
result= result+"\n";
}
return result;
} //end of toString()
/*
// =======================================================================
// Class specific methods local to this instance (ex: forced by interface)
// =======================================================================
*/
/**
* read_5_lines. Reads the first 5 lines of the given file.
* Reads each of the first five lines of the board file,
* gets the x and y start coordinates of objects and
* instantiates Pacman or each of the four Ghosts
* (depending on input, being which line is read)
* @param void No parameters.
*/
public void read_5_lines()
{
StringTokenizer st;
String temp_token;
int startpos[];
int char_num;
String line;
Integer temp_Int;
try
{
br = new BufferedReader( new FileReader(FILE_NAME) );
startpos = new int[2];
char_num=0;
line = br.readLine();
for (int num_line=0;
( (num_line<5) && (line!=null) && (line.equals("")==false) );
num_line=num_line+1)
{
st = new StringTokenizer(line);
while ( st.hasMoreTokens() )
{
temp_token = st.nextToken();
// temp_Int = new Integer(temp_token);
startpos[char_num]=Integer.parseInt(temp_token);
char_num= char_num+1;
} //endwhile
char_num=0;
if (num_line == 0 )
pacman = new Pacman(startpos[0], startpos[1]);
else //if (num_line!=0)
ghosts[num_line-1] = new Ghost(startpos[0], startpos[1], num_line);
line = br.readLine();
} //endfor
br.close();
} //endtry
catch( IOException ioe)
{
System.out.println("Error making pacman and ghosts.");
} //endcatch
} //end read_5_lines(void)
/**
* read_15_lines. Reads the board.
* Instantiates each cell of pieceArray to the appropriate GamePiece subclass
* passing in the x and y index as the GamePiece coordinates.
* @param void No parameters.
*/
public void read_15_lines()
{
StringTokenizer st;
String temp_token;
char board_line[];
int char_num;
String line;
Integer temp_Int;
try
{
br = new BufferedReader( new FileReader(FILE_NAME) );
board_line = new char[15];
char_num=0;
//ignore first 5 lines
for (int i=0; i<5; i=i+1)
line = br.readLine();
// 5th line, the real stuff.
line = br.readLine();
for (int y_coord=0;
( (y_coord<15) && (line!=null) && (line.equals("")==false) );
y_coord=y_coord+1)
{
st = new StringTokenizer(line);
while ( st.hasMoreTokens() )
{
temp_token= st.nextToken();
// temp_Int = new Integer(temp_token);
board_line[char_num]= temp_token.charAt(0);
char_num= char_num+1;
} //endwhile
char_num=0;
for (int x_coord=0; x_coord<15; x_coord=x_coord+1)
{
if (P6Constants.WALL.charAt(0) == board_line[x_coord])
{
pieceArray[x_coord][y_coord]=
new WallPiece(x_coord, y_coord);
}
else if (P6Constants.FLOOR.charAt(0) == board_line[x_coord])
{
pieceArray[x_coord][y_coord]=
new FloorPiece(x_coord, y_coord, false, false);
}
else if (P6Constants.NIBBLE.charAt(0) == board_line[x_coord])
{
pieceArray[x_coord][y_coord]=
new FloorPiece(x_coord, y_coord, true, false);
}
else if (P6Constants.SPECIAL.charAt(0) == board_line[x_coord])
{
pieceArray[x_coord][y_coord]=
new FloorPiece(x_coord, y_coord, false, true);
}
else // error
System.out.println("Error char in file.");
//STUB - use references and dynamic binding.
/*
switch (board_line[itr_bl])
{
case P6Constants.WALL.charAt(0)://'w'
break;
case P6Constants.FLOOR.charAt(0)://'f'
break;
case P6Constants.NIBBLE.charAt(0)://'n'
break;
case P6Constants.SPECIAL.charAt(0)://'s'
break;
}
*/
} //endfor
line = br.readLine();
} //endfor
br.close();
} //endtry
catch( IOException ioe)
{
System.out.println("Error making the board to play on.");
} //endcatch
} //end read_15_lines(void)
/*
// =======================================================================
// Methods dealing directly with the data within this instance
// (accessors, modifiers, etc)
// =======================================================================
*/
/**
* Get the value of pacman.
* @return value of pacman.
*/
public Pacman getPacman()
{
return pacman;
}
/**
* Set the value of pacman.
* @param v Value to assign to pacman.
*
public void setPacman(Pacman v)
{
this.pacman = v;
}
NOT IMPLEMENTED
*/
/**
* Get the value of ghosts.
* @return value of ghosts.
*/
public Ghost[] getGhosts()
{
return ghosts;
}
/**
* Set the value of ghosts.
* @param v Value to assign to ghosts.
*/
public void setGhosts(Ghost[] v)
{
this.ghosts = v;
}
/**
* Get the value of pieceArray.
* @return value of pieceArray.
*/
public GamePiece[][] getPieceArray()
{
return pieceArray;
}
/**
* Set the value of pieceArray.
* @param v Value to assign to pieceArray.
*/
public void setPieceArray(GamePiece[][] v)
{
this.pieceArray = v;
}
/*
// =======================================================================
// Protected Variables local to this instance
// =======================================================================
*/
/*
// =======================================================================
// Private Variables local to this instance
// =======================================================================
*/
/**
* pieceArray. A 15x15 array of GamePieces.
* This array will model the board seen in the GUI.
*/
private GamePiece[][] pieceArray;
/**
* br. To read the board file.
*/
private BufferedReader br;
/**
* instance variables for pacman and four ghosts
*/
private Pacman pacman;
private Ghost[] ghosts;
// Perhaps to use in the constructor.
private String FILE_NAME;
/*
// =======================================================================
// Main method (overrides this commenting system for readibility reasons)
// =======================================================================
*/
/**
* Debugging main for class PacmanFileReader.
* This method will rigorously test my code.
*
* <br><br>
* @param args a String array of command line arguments.
*/
public static void main(String[] args)
{
if ( (args.length==1) && (args[0].equals("-db") ) )
DEBUG_MAIN=true; //else leave false: ignore input.
if (DEBUG_MAIN)
{ // NOTE: This {} encapsulates most of main and is leftmost margin as a flag.
// redundant ifs left in, in case the main if(DEBUG) statement was ommitted,
// this would then print out neat output, as an example of real running.
PacmanFileReader pfr1 = new PacmanFileReader("board_1.txt");
PacmanFileReader pfr2 = new PacmanFileReader("board_2.txt");
System.out.println(pfr1);
System.out.println(pfr2);
if (DEBUG) System.out.println("end main(String[] args) call:");
} //end of DEBUG if
} //end of main(String[] args)
} //end of class PacmanFileReader

View File

@@ -0,0 +1,226 @@
/**
* CS1322: Programming Assignment #6 - Fall 2002
*
* <PRE>
* IDBox for: PacmanFrame.java
*
* Revisions: 1.0 Nov. 24, 2002
* Created the PacmanFrame class
*
* </PRE>
*
* Collaboration statement:
* "I worked on the homework assignment alone, using only
* course materials."
*
* @author
<A HREF="mailto:gtg142g@mail.gatech.edu">Roland Krystian Alberciak</A>
* @version Version 1.0, Nov. 24, 2002
*/
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
/*
*o an instance of GameBoard
o a JMenu with two JMenuItems:
- one that activates a new game: This should restart the
game no matter what the state of the current game.
- one that exits the program. This should stop the JVM just
as if we clicked on the X in the top right corner of the
frame.
o a default constructor which sets up the frame with a
BorderLayout, instantiates a new GameBoard and adds it to the
center. There is a constant in P6Constants called BOARD_FILE
containing the name of the file to tokenize into a GamePiece
array.
o We recommend you set the size of the frame to be about 520x520
o helper methods that set up the menus.
o We recommend you have this class be a listener for its own
JMenuItems. You will need to then have this class implement
ActionListener.
o The program should exit gracefully if either the quit menu is
chosen or the X in the top right is clicked.
*/
public class PacmanFrame extends JFrame implements ActionListener{
GameBoard cGameBoard;
JMenu cGameMenu;
JMenuItem jNewGame;
JMenuItem jExitGame; //why the heck would you want to do that!!
/**
*PacmanFrame Default Constructor
*Basically sets up the game
*/
public PacmanFrame(){
public class PacmanFrame extends JFrame implements ActionListener
{
/** Debug value for toggling System.out.* output */
public static boolean DEBUG = false;
public static boolean DEBUG_CODE = false;
public static boolean DEBUG_MAIN = false;
/**
* Constructor 2. Specified default-overloading constructor for PacmanFrame.
* @param void No parameters.
* @return PacmanFrame instance/object.
*/
public PacmanFrame()
{
super("Pacman: Pac-a-delic, yo");
super.getContentPane().setLayout( new BorderLayout() );
// also, remember "board2.txt"
// this.setGb(new GameBoard("board_2.txt") );
this.setGb(new GameBoard(P6Constants.BOARD_FILE) );
super.getContentPane().add(getGb(), BorderLayout.CENTER);
makeGUI();
addToGUI();
super.setSize(520, 520);
super.setResizable(false); //processWindowEvent();
super.setDefaultCloseOperation(EXIT_ON_CLOSE);
super.setVisible(true); //super.show();
} //end of PacmanFrame()
public void makeGUI()
{
newGame = new JMenuItem("Restart Pacman");
exitGame = new JMenuItem("Exit Pacman");
mainMenu = new JMenu("Pacman Menu");
menuBar = new JMenuBar();
}
public void addToGUI()
{
mainMenu.add(newGame);
mainMenu.add(exitGame);
menuBar.add(mainMenu); // mainMenu is placed into menuBar.
super.setJMenuBar(menuBar);
}
public void actionPerformed(ActionEvent ae)
{
if( (ae.getSource() instanceof JMenuItem) ==true )
{
//Restart Pacman
if( ae.getActionCommand().equals("Restart Pacman") ==true )
{
System.out.println("Restarted Pacman");
} //endif
else if( ae.getActionCommand().equals("Exit Pacman") ==true )
{
System.exit(1); //Exits gracefully. Compassionate Conservative.
System.out.println("Exiting Pacman");
} //endif
}
}
/*
// =======================================================================
// Methods dealing directly with the data within this instance
// (accessors, modifiers, etc)
// =======================================================================
*/
/**
* Get the value of gb.
* @return value of gb.
*/
public GameBoard getGb()
{
return gb;
}
/**
* Set the value of gb.
* @param v Value to assign to gb.
*/
public void setGb(GameBoard v)
{
this.gb = v;
}
/*
// =======================================================================
// Protected Variables local to this instance
// =======================================================================
*/
/*
// =======================================================================
// Private Variables local to this instance
// =======================================================================
*/
/**
* gb. An instance of GameBoard.
* To be used in accessing GameBoard's elements, and displaying in Frame.
*/
private GameBoard gb;
private JMenu mainMenu;
private JMenuBar menuBar;
private JMenuItem newGame;
private JMenuItem exitGame;
/*
// =======================================================================
// Main method (overrides this commenting system for readibility reasons)
// =======================================================================
*/
/**
* Debugging main for class PacmanFrame.
* This method will rigorously test my code.
*
* <br><br>
* @param args a String array of command line arguments.
*/
public static void main(String[] args)
{
if ( (args.length==1) && (args[0].equals("-db") ) )
DEBUG_MAIN=true; //else leave false: ignore input.
if (DEBUG_MAIN)
{ // NOTE: This {} encapsulates most of main and is leftmost margin as a flag.
// redundant ifs left in, in case the main if(DEBUG) statement was ommitted,
// this would then print out neat output, as an example of real running.
PacmanFrame pf = new PacmanFrame();
if (DEBUG) System.out.println("end main(String[] args) call:");
} //end of DEBUG if
} //end of main(String[] args)
} //end of class PacmanFrame

View File

@@ -0,0 +1,155 @@
/**
* CS1322: Programming Assignment #6 - Fall 2002
*
* <PRE>
* IDBox for: WallPiece.java
*
* Revisions: 1.0 Nov. 21, 2002
* Created the WallPiece class
*
* </PRE>
*
* Collaboration statement:
* "I worked on the homework assignment alone, using only
* course materials."
*
* @author
<A HREF="mailto:gtg142g@mail.gatech.edu">Roland Krystian Alberciak</A>
* @version Version 1.0, Nov. 21, 2002
*/
// imports are listed above IDBox
/**
* MODEL.
* Gamepiece. Wallpiece extends GamePiece.
* Adds the functionality of a wall on the game board.
* Neither ghosts nor Pacman can travel on or through walls.
* They can only travel on FloorPieces.
*/
public class WallPiece extends GamePiece
{
/** Debug value for toggling System.out.* output */
public static boolean DEBUG = false;
public static boolean DEBUG_MAIN = false;
/*
// =======================================================================
// Constructors
// =======================================================================
*/
/**
* Constructor 1. Specified default-overriding constructor for WallPiece.
* @param void No parameters.
* @return WallPiece instance/object.
*
public WallPiece()
{
} //end of WallPiece()
*/
/**
* Constructor 1. Specified default-overriding constructor for WallPiece.
* @param x the location along the x-axis.
* @param y the location along the y-axis.
* @return WallPiece instance/object.
*/
public WallPiece(int x, int y)
{
super(x,y); //Chains to the super constructor (GamePiece)
} //end of WallPiece(int, int)
/*
// =======================================================================
// Methods which override class Object methods
// =======================================================================
*/
/**
* Equal instance comparison. Compares if two instances are equal.
* @param o object-type reference of (hopefully) an WallPiece.
* @return boolean whether objects are equal.
*
public boolean equals (Object o)
{
} //end of equals(Object)
*/
/**
* toString instance printer. Prints properties of WallPiece.
* @return System.out.println(WallPiece instance) instance print.
*/
public String toString()
{
String result="";
result= P6Constants.WALL;
result= result+" "; //cleanup, autoprepare for output
return result;
} //end of toString()
/*
// =======================================================================
// Class specific methods local to this instance
// =======================================================================
*/
/*
// =======================================================================
// Methods dealing directly with the data within this instance
// (accessors, modifiers, etc)
// =======================================================================
*/
/*
// =======================================================================
// Private Variables local to this instance
// =======================================================================
*/
/*
// =======================================================================
// Main method (overrides this commenting system for readibility reasons)
// =======================================================================
*/
/**
* Debugging main for class WallPiece.
* This method will rigorously test my code.
*
* <br><br>
* @param args a String array of command line arguments.
*/
public static void main(String[] args)
{
if ( (args.length==1) && (args[0].equals("-db") ) )
DEBUG_MAIN=true; //else leave false: ignore input.
if (DEBUG_MAIN)
{ // NOTE: This {} encapsulates most of main and is leftmost margin as a flag.
// redundant ifs left in, in case the main if(DEBUG) statement was ommitted,
// this would then print out neat output, as an example of real running.
WallPiece w1 = new WallPiece(1,5);
System.out.println(w1);
if (DEBUG) System.out.println("end main(String[] args) call:");
} //end of DEBUG if
} //end of main(String[] args)
} //end of class WallPiece

View File

@@ -0,0 +1,20 @@
0 7
1 1
13 1
13 13
1 13
w w w w w w w w w w w w w w w
w s f n n n n w n n n n f s w
w f w w w w n w n w w w w f w
w n w n n n n w n n n n w n w
w n w n w w w w w w w n w n w
w n w n n n n n n n n n w n w
w n w n n n w w w n n n w n w
f n n n n n w f w n n n n n w
w n w n n n w w w n n n w n w
w n w n n n n n n n n n w n w
w n w n w w w w w w w n w n w
w n w n n n n w n n n n w n w
w f w w w w n w n w w w w f w
w s f n n n n w n n n n f s w
w w w w w w w w w w w w w w w

View File

@@ -0,0 +1,20 @@
0 7
1 1
13 1
13 13
1 13
w w w w w w w w w w w w w w w
w s f n n n n n n n n n f s w
w f w w w w w n w w w w w f w
w n w f f f w n w f f f w n w
w n w w w w w n w w w w w n w
w n w n n n n n n n n n w n w
w n w n w n w w w n w n w n w
f n n n n n w f w n n n n n f
w n w n w n w w w n w n w n w
w n w n n n n n n n n n w n w
w n w w w w w n w w w w w n w
w n w f f f w n w f f f w n w
w f w w w w w n w w w w w f w
w s f n n n n n n n n n f s w
w w w w w w w w w w w w w w w

BIN
CS1322/p6/Krystian/gh1.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 B

BIN
CS1322/p6/Krystian/gh2.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 B

BIN
CS1322/p6/Krystian/gh3.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 224 B

BIN
CS1322/p6/Krystian/gh4.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 B

BIN
CS1322/p6/Krystian/ghRA.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 357 B

BIN
CS1322/p6/Krystian/p6.zip Normal file

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 B