first commit
This commit is contained in:
147
CS1322/p6/Ghost.java
Normal file
147
CS1322/p6/Ghost.java
Normal file
@@ -0,0 +1,147 @@
|
||||
/**
|
||||
* <PRE>
|
||||
* Ghost.java
|
||||
*
|
||||
* Revisions: 1.0 Nov. 12, 2002
|
||||
* Created the Ghost class
|
||||
*
|
||||
* </PRE>
|
||||
*
|
||||
* Collaboration Statement:
|
||||
* I worked on the homework assignment alone, using only
|
||||
* course materials.
|
||||
*
|
||||
* Created with JCreatorLE, some indents are off when viewed through notepad
|
||||
* or EMACS
|
||||
*
|
||||
* @author <A HREF="mailto:gtg184g@mail.gatech.edu">Jose Manuel Caban</A>
|
||||
* @version Version 1.0, Nov. 12, 2002
|
||||
*/
|
||||
|
||||
public class Ghost extends MoveablePiece{
|
||||
|
||||
/**
|
||||
*number of the ghost
|
||||
*/
|
||||
private int ghostNum;
|
||||
|
||||
/**
|
||||
*true if the ghost is running away from pacman
|
||||
*/
|
||||
private boolean runAwayFlag;
|
||||
|
||||
/**
|
||||
*Times ghost will run from Pacman
|
||||
*/
|
||||
private int runAwayCount;
|
||||
|
||||
/**
|
||||
*Starting coordinates of the ghost
|
||||
*/
|
||||
private int startX;
|
||||
private int startY;
|
||||
|
||||
public Ghost(int x, int y, int ghostNum){
|
||||
super(x,y);
|
||||
startX = x;
|
||||
startY = y;
|
||||
this.ghostNum = ghostNum;
|
||||
runAwayCount=0;
|
||||
}
|
||||
|
||||
/////////////
|
||||
//Accessors//
|
||||
/////////////
|
||||
|
||||
/**
|
||||
*@return ghostNumber
|
||||
*/
|
||||
public int getGhostNum(){
|
||||
return ghostNum;
|
||||
}
|
||||
|
||||
/**
|
||||
*@return runaway y/n
|
||||
*/
|
||||
public boolean getRunAwayFlag(){
|
||||
return runAwayFlag;
|
||||
}
|
||||
|
||||
/**
|
||||
*@return the XstartPos
|
||||
*/
|
||||
public int getStartX(){
|
||||
return startX;
|
||||
}
|
||||
|
||||
/**
|
||||
*@return the YstartPos
|
||||
*/
|
||||
public int getStartY(){
|
||||
return startY;
|
||||
}
|
||||
|
||||
///////////
|
||||
//Methods//
|
||||
///////////
|
||||
|
||||
/**
|
||||
*Make the ghost run like hell
|
||||
*/
|
||||
public void runAway(){
|
||||
runAwayFlag = true;
|
||||
runAwayCount = RUN_AWAY_DURATION;
|
||||
}
|
||||
|
||||
/**
|
||||
*reset the stupid ghost
|
||||
*/
|
||||
public void resetGhost(){
|
||||
runAwayFlag = false;
|
||||
setPosition(startX,startY);
|
||||
}
|
||||
|
||||
/**
|
||||
*@param x, the x coord of Pacman
|
||||
*@param y, the y coord of Pacman
|
||||
*@return an array of moves for the ghost
|
||||
*/
|
||||
public int[] getMove(int x, int y){
|
||||
runAwayCount--;
|
||||
if(runAwayCount<1){
|
||||
runAwayFlag = false;
|
||||
}
|
||||
if(!runAwayFlag){
|
||||
return GhostAI.getGhostMove(this.x,this.y,x,y);
|
||||
}
|
||||
else{
|
||||
int[] array = GhostAI.getGhostMove(this.x,this.y,x,y);
|
||||
int[] tmpArray = new int[array.length];
|
||||
for(int i=0; i<array.length; i++){
|
||||
tmpArray[i] = array[array.length-i-1];
|
||||
}
|
||||
return tmpArray;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*@return String
|
||||
*/
|
||||
public String toString(){
|
||||
return (super.toString() + "Ghost]");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
|
||||
|
||||
}// end of main(String[] args)
|
||||
|
||||
}// end of class Ghost
|
||||
Reference in New Issue
Block a user