198 lines
5.4 KiB
Java
198 lines
5.4 KiB
Java
/**
|
|
* 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
|