first commit
This commit is contained in:
47
CS1322/p6/MyWay2/CBgLayer.java
Normal file
47
CS1322/p6/MyWay2/CBgLayer.java
Normal file
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* <PRE>
|
||||
* CBgLayer.java
|
||||
*
|
||||
* Revisions: 1.0 Nov. 24, 2002
|
||||
* Created the CBgLayer class
|
||||
*
|
||||
* </PRE>
|
||||
*
|
||||
* @author <A HREF="mailto:gtg184g@mail.gatech.edu">Jose Manuel Caban</A>
|
||||
* @version Version 1.0, Nov. 24, 2002
|
||||
*/
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class CBgLayer extends JPanel{
|
||||
CEngine cEngine;
|
||||
|
||||
public CBgLayer(String fileName){
|
||||
cEngine = new CEngine(fileName);
|
||||
}
|
||||
|
||||
protected void paintComponent(Graphics g){
|
||||
super.paintComponent(g);
|
||||
int w = WIDTH / cEngine.cBgLayer.length;
|
||||
int h = HEIGHT / cEngine.cBgLayer[0].length;
|
||||
|
||||
for(int x=0; x<cEngine.cBgLayer.length; x++){
|
||||
for(int y=0; y<cEngine.cBgLayer[x].length; y++){
|
||||
if(cEngine.cBgLayer[x][y].getZ() == 2){
|
||||
fillrect(
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Debugging main for class CBgLayer.
|
||||
* 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 CBgLayer
|
||||
105
CS1322/p6/MyWay2/CCoord.java
Normal file
105
CS1322/p6/MyWay2/CCoord.java
Normal file
@@ -0,0 +1,105 @@
|
||||
/**
|
||||
* <PRE>
|
||||
* CCoord.java
|
||||
*
|
||||
* Revisions: 1.0 Nov. 23, 2002
|
||||
* Created the CCoord class, scratched old code
|
||||
* 1.1 Nov. 23, 2002
|
||||
* Compiled, FInished, Commented
|
||||
*
|
||||
*
|
||||
* </PRE>
|
||||
*
|
||||
* @author <A HREF="mailto:gtg184g@mail.gatech.edu">Jose Manuel Caban</A>
|
||||
* @version Version 1.1, Nov. 23, 2002
|
||||
*/
|
||||
|
||||
/**
|
||||
*This class will be used to store Coordinate values relative to the grid
|
||||
*not the x,y coord relative to the resolution
|
||||
*/
|
||||
public class CCoord{
|
||||
|
||||
/**
|
||||
*Stores the x coord
|
||||
*/
|
||||
protected int iX;
|
||||
|
||||
/**
|
||||
*Stores the y coord
|
||||
*/
|
||||
protected int iY;
|
||||
|
||||
/**
|
||||
*Stores the Height of the ground, ground level = 0
|
||||
*/
|
||||
protected int iZ;
|
||||
|
||||
////////////////
|
||||
//Constructors//
|
||||
////////////////
|
||||
|
||||
/**
|
||||
*Default Constructor, sets values to 1,1,0
|
||||
*/
|
||||
public CCoord(){
|
||||
this(1,1,0);
|
||||
}
|
||||
|
||||
/**
|
||||
*@param x, the x coord
|
||||
*@param y, the y coord
|
||||
*@param z, the z coord
|
||||
*/
|
||||
public CCoord(int iX, int iY, int iZ){
|
||||
this.iX = iX;
|
||||
this.iY = iY;
|
||||
this.iZ = iZ;
|
||||
}
|
||||
|
||||
///////////////////////////
|
||||
//Accessors and Modifiers//
|
||||
///////////////////////////
|
||||
|
||||
/**
|
||||
*@return, the value of X
|
||||
*/
|
||||
public int getX(){
|
||||
return iX;
|
||||
}
|
||||
|
||||
/**
|
||||
*@return, the value of Y
|
||||
*/
|
||||
public int getY(){
|
||||
return iY;
|
||||
}
|
||||
|
||||
/**
|
||||
*@return, the value of Z
|
||||
*/
|
||||
public int getZ(){
|
||||
return iZ;
|
||||
}
|
||||
|
||||
/**
|
||||
*@param x, the x coord
|
||||
*@param y, the y coord
|
||||
*@param z, the z coord
|
||||
*/
|
||||
public void setParams(int iX, int iY, int iZ){
|
||||
this.iX = iX;
|
||||
this.iY = iY;
|
||||
this.iZ = iZ;
|
||||
}
|
||||
|
||||
public void setParams(CCoord c){
|
||||
this.iX = c.iX;
|
||||
this.iY = c.iY;
|
||||
this.iZ = c.iZ;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return ("[X: "+iX+" Y: "+iY+" Z: "+iZ+"]");
|
||||
}
|
||||
}//end class::CCoord
|
||||
58
CS1322/p6/MyWay2/CEngine.java
Normal file
58
CS1322/p6/MyWay2/CEngine.java
Normal file
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* <PRE>
|
||||
* CEngine.java
|
||||
*
|
||||
* Revisions: 1.0 Nov. 17, 2002
|
||||
* Created the CEngine class
|
||||
*
|
||||
* </PRE>
|
||||
*
|
||||
* @author <A HREF="mailto:gtg184g@mail.gatech.edu">Jose Manuel Caban</A>
|
||||
* @version Version 1.0, Nov. 17, 2002
|
||||
*/
|
||||
|
||||
public class CEngine {
|
||||
|
||||
public CGhost[] cGhost;
|
||||
public CPacman[] cPacman;
|
||||
public CTile[][] cBgGrid;
|
||||
public CMonster[][] cSpriteLayer;
|
||||
public CNode[][] cNodeLayer;
|
||||
|
||||
public CEngine(String fileName){
|
||||
CFileReader cTemp= new CFileReader();
|
||||
Object[] array = cTemp.readMap(fileName);
|
||||
|
||||
cBgGrid = (CTile[][])array[5];
|
||||
CPacman Pacman = new CPacman((CCoord)array[0]);
|
||||
CGhost Ghost1 = new CGhost((CCoord)array[1]);
|
||||
CGhost Ghost2 = new CGhost((CCoord)array[2]);
|
||||
CGhost Ghost3 = new CGhost((CCoord)array[3]);
|
||||
CGhost Ghost4 = new CGhost((CCoord)array[4]);
|
||||
|
||||
cNodeLayer = (CNode[][])array[6];
|
||||
|
||||
cSpriteLayer = new CMonster[cBgGrid.length][cBgGrid[0].length];
|
||||
cSpriteLayer[Pacman.getX()][Pacman.getY()] = Pacman;
|
||||
cSpriteLayer[Ghost1.getX()][Ghost1.getY()] = Ghost1;
|
||||
cSpriteLayer[Ghost2.getX()][Ghost2.getY()] = Ghost2;
|
||||
cSpriteLayer[Ghost3.getX()][Ghost3.getY()] = Ghost3;
|
||||
cSpriteLayer[Ghost4.getX()][Ghost4.getY()] = Ghost4;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Debugging main for class CEngine.
|
||||
* 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 CEngine
|
||||
247
CS1322/p6/MyWay2/CFileReader.java
Normal file
247
CS1322/p6/MyWay2/CFileReader.java
Normal file
@@ -0,0 +1,247 @@
|
||||
/**
|
||||
* <PRE>
|
||||
* CFileReader.java
|
||||
*
|
||||
* Revisions: 1.0 Nov. 24, 2002
|
||||
* Created the CFileReader class
|
||||
*
|
||||
* </PRE>
|
||||
*
|
||||
* @author <A HREF="mailto:gtg184g@mail.gatech.edu">Jose Manuel Caban</A>
|
||||
* @version Version 1.0, Nov. 24, 2002
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
public class CFileReader implements Constants{
|
||||
|
||||
BufferedReader brReader;
|
||||
|
||||
/**
|
||||
*@return an array with the first 4 slots holding pacman and the ghost
|
||||
*start locations, slot 5 holding the Background grid, slot 6 holding the
|
||||
*Node Grid
|
||||
*/
|
||||
public Object[] readMap(String mapFile){
|
||||
Object[] array = new Object[6];
|
||||
StringTokenizer st;
|
||||
|
||||
/////////////////////
|
||||
//Read Start Points//
|
||||
/////////////////////
|
||||
|
||||
try{
|
||||
brReader = new BufferedReader(new FileReader(mapFile));
|
||||
}catch(FileNotFoundException fnfe){
|
||||
System.err.println("File Not Found Error - CFileReader");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
for(int i=0; i<5; i++){
|
||||
st = new StringTokenizer("b");
|
||||
try{
|
||||
st = new StringTokenizer(brReader.readLine());
|
||||
}catch(IOException ioe){
|
||||
System.err.println(ioe);
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
array[i] = new CCoord(Integer.parseInt(st.nextToken()),
|
||||
Integer.parseInt(st.nextToken()),1);
|
||||
}
|
||||
/*End Read Start Points*/
|
||||
/////////////////////////
|
||||
|
||||
String strTemp = "";
|
||||
CTile[][] cBgGrid;
|
||||
|
||||
try{
|
||||
strTemp = brReader.readLine();
|
||||
}catch(IOException ioe){
|
||||
System.err.println(ioe);
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
/*Check whether its standard file or enhanced grid*/
|
||||
|
||||
switch(strTemp.charAt(0)){
|
||||
case 'w': case 'n': case 's': case 'f':
|
||||
cBgGrid = new CTile[15][15];
|
||||
break;
|
||||
|
||||
case '1':case '2':case '3':case '4': case '5': case '6': case '7':
|
||||
case '8':case '9':case '0':
|
||||
|
||||
st = new StringTokenizer(strTemp);
|
||||
cBgGrid = new CTile[Integer.parseInt(st.nextToken())]
|
||||
[Integer.parseInt(st.nextToken())];
|
||||
|
||||
try{
|
||||
strTemp = brReader.readLine();
|
||||
}catch(IOException ioe){
|
||||
System.err.println(ioe);
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
cBgGrid = new CTile[0][0];
|
||||
break;
|
||||
}
|
||||
|
||||
/*End Check file type*/
|
||||
///////////////////////
|
||||
|
||||
///////////////
|
||||
/*Read in map*/
|
||||
st = new StringTokenizer("");
|
||||
|
||||
for(int i=0; i<cBgGrid.length; i++){
|
||||
|
||||
try{
|
||||
if(i==0){
|
||||
st = new StringTokenizer(strTemp);
|
||||
}else{
|
||||
st = new StringTokenizer(brReader.readLine());
|
||||
}
|
||||
}catch(IOException ioe){
|
||||
System.err.println(ioe);
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
for(int z=0; z<cBgGrid[i].length; z++){
|
||||
|
||||
switch(st.nextToken().charAt(0))
|
||||
{
|
||||
case 'f':
|
||||
cBgGrid[i][z] = new CTile(i,z,1);
|
||||
break;
|
||||
case 'n':
|
||||
cBgGrid[i][z] = new CTile(i,z,1);
|
||||
cBgGrid[i][z].setItems(true,false);
|
||||
break;
|
||||
case 's':
|
||||
cBgGrid[i][z] = new CTile(i,z,1);
|
||||
cBgGrid[i][z].setItems(false,true);
|
||||
break;
|
||||
default:
|
||||
case 'w':
|
||||
cBgGrid[i][z] = new CTile(i,z,2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*End map read*/
|
||||
////////////////
|
||||
array[5] = cBgGrid;
|
||||
|
||||
//////////////
|
||||
//Init Nodes//
|
||||
//////////////
|
||||
|
||||
CNode[][] cNode= new CNode[cBgGrid.length][cBgGrid[0].length];
|
||||
|
||||
for(int i=0; i<cNode.length; i++){
|
||||
for(int z=0; z<cNode[i].length; z++){
|
||||
boolean up=false, down=false, left=false, right=false;
|
||||
|
||||
//check up
|
||||
try{
|
||||
up = cBgGrid[i-1][z].getZ()==1?true:false;
|
||||
}
|
||||
catch(IndexOutOfBoundsException iobe){
|
||||
up = true;
|
||||
}
|
||||
catch(Exception e){
|
||||
up = false;
|
||||
}
|
||||
|
||||
//check down
|
||||
try{
|
||||
down = cBgGrid[i+1][z].getZ()==1?true:false;
|
||||
}
|
||||
catch(IndexOutOfBoundsException iobe){
|
||||
down = true;
|
||||
}
|
||||
catch(Exception e){
|
||||
down = false;
|
||||
}
|
||||
|
||||
//check left
|
||||
try{
|
||||
left = cBgGrid[i][z-1].getZ()==1?true:false;
|
||||
}
|
||||
catch(IndexOutOfBoundsException iobe){
|
||||
left = true;
|
||||
}
|
||||
catch(Exception e){
|
||||
left = false;
|
||||
}
|
||||
|
||||
//check right
|
||||
try{
|
||||
right = cBgGrid[i][z+1].getZ()==1?true:false;
|
||||
}
|
||||
catch(IndexOutOfBoundsException iobe){
|
||||
right = true;
|
||||
}
|
||||
catch(Exception e){
|
||||
right = false;
|
||||
}
|
||||
|
||||
if(cBgGrid[i][z] != null && cBgGrid[i][z].getZ()==1){
|
||||
cNode[i][z] = new CNode(up,down,left,right,i,z,1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
array[6] = cNode;
|
||||
try{
|
||||
brReader.close();
|
||||
}catch(IOException ioe){
|
||||
System.err.println(ioe);
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
public static void main(String args[]){
|
||||
CFileReader bob = new CFileReader();
|
||||
Object[] steve = bob.readMap("board_1.txt");
|
||||
for(int i=0; i<5; i++){
|
||||
System.out.println(steve[i]);
|
||||
}
|
||||
|
||||
System.out.println();
|
||||
|
||||
CTile[][] crystal = (CTile[][])steve[5];
|
||||
for(int i=0; i<crystal.length; i++){
|
||||
for(int z=0; z<crystal.length; z++){
|
||||
System.out.println(crystal[i][z]);
|
||||
}
|
||||
}
|
||||
|
||||
CNode[][] julia = (CNode[][])steve[6];
|
||||
for(int i=0; i<julia.length; i++){
|
||||
for(int z=0; z<julia.length; z++){
|
||||
try{
|
||||
if(julia[i][z] == null){}
|
||||
else{
|
||||
System.out.println(julia[i][z]);}
|
||||
}
|
||||
catch(Exception e){
|
||||
//System.out.print("null");
|
||||
}
|
||||
}
|
||||
System.out.println("/*NextLine*/");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}// end of class CFileReader
|
||||
68
CS1322/p6/MyWay2/CGhost.java
Normal file
68
CS1322/p6/MyWay2/CGhost.java
Normal file
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* <PRE>
|
||||
* CGhost.java
|
||||
*
|
||||
* Revisions: 1.0 Nov. 23, 2002
|
||||
* Created the CGhost class
|
||||
*
|
||||
* </PRE>
|
||||
*
|
||||
* @author <A HREF="mailto:gtg184g@mail.gatech.edu">Jose Manuel Caban</A>
|
||||
* @version Version 1.0, Nov. 23, 2002
|
||||
*/
|
||||
|
||||
public class CGhost extends CMonster implements Constants{
|
||||
|
||||
private CCoord startLoc;
|
||||
private CNode cLastNode;
|
||||
private int iCurrDir;
|
||||
private boolean bDazed;
|
||||
|
||||
public CGhost(CSprite image, CCoord startLoc){
|
||||
oIntel = new CGhostAI();
|
||||
imgSprite = image;
|
||||
this.setParams(startLoc);
|
||||
this.startLoc = startLoc;
|
||||
}
|
||||
|
||||
public CGhost(CCoord startLoc){
|
||||
this(new CSprite("Error",".gif",1),startLoc);
|
||||
}
|
||||
|
||||
public int doMove(CCoord cPacPos){
|
||||
return ((CGhostAI)oIntel).doMove(cLastNode,this,cPacPos);
|
||||
}
|
||||
|
||||
public void setLastNode(CNode cLastNode){
|
||||
this.cLastNode = cLastNode;
|
||||
}
|
||||
|
||||
public void setDir(int dir){
|
||||
iCurrDir = dir;
|
||||
}
|
||||
|
||||
public int getDir(){
|
||||
return iCurrDir;
|
||||
}
|
||||
|
||||
public void setDaze(boolean b){
|
||||
bDazed = b;
|
||||
}
|
||||
|
||||
public boolean getDaze(){
|
||||
return bDazed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Debugging main for class CGhost.
|
||||
* 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 CGhost
|
||||
66
CS1322/p6/MyWay2/CGhostAI.java
Normal file
66
CS1322/p6/MyWay2/CGhostAI.java
Normal file
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* <PRE>
|
||||
* CGhostAI.java
|
||||
*
|
||||
* Revisions: 1.0 Nov. 23, 2002
|
||||
* Created the CGhostAI class
|
||||
*
|
||||
* </PRE>
|
||||
*
|
||||
* @author <A HREF="mailto:gtg184g@mail.gatech.edu">Jose Manuel Caban</A>
|
||||
* @version Version 1.0, Nov. 23, 2002
|
||||
*/
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class CGhostAI extends CIntelligence implements Constants{
|
||||
|
||||
/**
|
||||
*This GhostAI uses a more classicPacman-like AI system
|
||||
*Considering the fact that pacman isn't Half-Life, we don't need
|
||||
*to do any searches to find Pacman, Pacman will eventually run into
|
||||
*the ghosts.
|
||||
*
|
||||
*Basically, if the Ghost "sees" Pacman, that is, Pacman is within the
|
||||
*Ghost's Line of Sight, the ghost will increase his speed to equal Pacman's
|
||||
*(in this case I'm setting the speeds to be 3,2,1: 3 = Pacman speed,
|
||||
*2 = Ghost regular speed, 1 = Ghost zombied speed)
|
||||
*and the Ghost will head in Pacman's direction at full speed until pacman
|
||||
*hits a new node (a Pacman hit Node event occurs) where the new direction
|
||||
*Pacman chooses will be sent back to the Ghost and the Ghost will return to
|
||||
*moving at normal speed (which is slightly slower than pacman but much faster
|
||||
*than the speed at which they move when zombied out.
|
||||
*
|
||||
*@param CNode, the Ghost's current node
|
||||
*@param CGhost, the Ghost to be analyzed
|
||||
*@param CCoord, pacmans coordinate
|
||||
*/
|
||||
public int doMove(CNode cLastNode, CGhost cGhost, CCoord cPacPos){
|
||||
int wayToGo;
|
||||
|
||||
if(cGhost.getX() == cPacPos.getX()){
|
||||
if(cGhost.getY() < cPacPos.getY()){
|
||||
wayToGo = cLastNode.canMV_DN()?MV_DN:MV_SAMEDIR;
|
||||
}
|
||||
else{
|
||||
wayToGo = cLastNode.canMV_UP()?MV_UP:MV_SAMEDIR;
|
||||
}
|
||||
}
|
||||
|
||||
else if(cGhost.getY() == cPacPos.getY()){
|
||||
if(cGhost.getX() < cPacPos.getX()){
|
||||
wayToGo = cLastNode.canMV_RIGHT()?MV_RIGHT:MV_SAMEDIR;
|
||||
}
|
||||
else{
|
||||
wayToGo = cLastNode.canMV_LEFT()?MV_LEFT:MV_SAMEDIR;
|
||||
}
|
||||
}
|
||||
else {
|
||||
//if the ghost can't see pacman then
|
||||
Random rando = new Random();
|
||||
wayToGo = rando.nextInt(MV_SAMEDIR);
|
||||
}
|
||||
return wayToGo;
|
||||
}//end doMove()
|
||||
|
||||
}// end of class CGhostAI
|
||||
55
CS1322/p6/MyWay2/CGrid.java
Normal file
55
CS1322/p6/MyWay2/CGrid.java
Normal file
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* <PRE>
|
||||
* CGrid.java
|
||||
*
|
||||
* Revisions: 1.0 Nov. 17, 2002
|
||||
* Created the CGrid class
|
||||
*
|
||||
* </PRE>
|
||||
*
|
||||
* @author <A HREF="mailto:gtg184g@mail.gatech.edu">Jose Manuel Caban</A>
|
||||
* @version Version 1.0, Nov. 17, 2002
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class CGrid {
|
||||
|
||||
/**
|
||||
*2D array to store the game data
|
||||
*/
|
||||
private CCoord[][] grid;
|
||||
|
||||
////////////////
|
||||
//Constructors//
|
||||
////////////////
|
||||
|
||||
public CGrid(int iLength, int iHeight){
|
||||
grid = new CCoord[iLength][iHeight];
|
||||
}
|
||||
|
||||
///////////
|
||||
//Methods//
|
||||
///////////
|
||||
|
||||
public CCoord get(int x, int y){
|
||||
return grid[x][y];
|
||||
}
|
||||
|
||||
public void set(int x, int y, CCoord c){
|
||||
grid[x][y] = c;
|
||||
}
|
||||
|
||||
/**
|
||||
* Debugging main for class CGrid.
|
||||
* 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 CGrid
|
||||
36
CS1322/p6/MyWay2/CIntelligence.java
Normal file
36
CS1322/p6/MyWay2/CIntelligence.java
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* <PRE>
|
||||
* CIntelligence.java
|
||||
*
|
||||
* Revisions: 1.0 Nov. 13, 2002
|
||||
* Created the CIntelligence class
|
||||
* 1.1 Nov. 23, 3003
|
||||
* Created, Compiled, Finished
|
||||
*
|
||||
* </PRE>
|
||||
*
|
||||
* @author <A HREF="mailto:gtg184g@mail.gatech.edu">Jose Manuel Caban</A>
|
||||
* @version Version 1.1, Nov. 23, 2002
|
||||
*/
|
||||
|
||||
public abstract class CIntelligence implements Constants{
|
||||
/**
|
||||
*Holds who controls the Intelligence
|
||||
*/
|
||||
String type;
|
||||
|
||||
/**
|
||||
*Default Constructor, set type to CPU
|
||||
*/
|
||||
public CIntelligence(){
|
||||
type = "CPU";
|
||||
}
|
||||
|
||||
/**
|
||||
*@param, set type to this
|
||||
*/
|
||||
public CIntelligence(String type){
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
}// end of class CIntelligence
|
||||
27
CS1322/p6/MyWay2/CMonster.java
Normal file
27
CS1322/p6/MyWay2/CMonster.java
Normal file
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* <PRE>
|
||||
* Monster.java
|
||||
*
|
||||
* Revisions: 1.0 Nov. 13, 2002
|
||||
* Created the Monster class
|
||||
*
|
||||
* </PRE>
|
||||
*
|
||||
* @author <A HREF="mailto:gtg184g@mail.gatech.edu">Jose Manuel Caban</A>
|
||||
* @version Version 1.0, Nov. 13, 2002
|
||||
*/
|
||||
|
||||
public abstract class CMonster extends CCoord implements Constants{
|
||||
|
||||
/**
|
||||
*Defines the Intelligence of the monster
|
||||
*whether player controlled or CPU controlled
|
||||
*/
|
||||
protected CIntelligence oIntel;
|
||||
|
||||
/**
|
||||
*Define image for monster
|
||||
*/
|
||||
protected CSprite imgSprite;
|
||||
|
||||
}// end of class Monster
|
||||
105
CS1322/p6/MyWay2/CNode.java
Normal file
105
CS1322/p6/MyWay2/CNode.java
Normal file
@@ -0,0 +1,105 @@
|
||||
/**
|
||||
* <PRE>
|
||||
* CNode.java
|
||||
*
|
||||
* Revisions: 1.0 Nov. 17, 2002
|
||||
* Created the CNode class
|
||||
* 1.1 Nov. 17, 2002
|
||||
* Added Primary code, Commented, Finished
|
||||
*
|
||||
* </PRE>
|
||||
*
|
||||
* @author <A HREF="mailto:gtg184g@mail.gatech.edu">Jose Manuel Caban</A>
|
||||
* @version Version 1.1, Nov. 17, 2002
|
||||
*/
|
||||
|
||||
/**
|
||||
*The Engine class (CEngine) can take in a board and turn it into a game map.
|
||||
*The Engine class then creates another grid which will below the game map
|
||||
* that holds the nodes for the Intelligence class (CIntelligence).
|
||||
*The Node classes hold the data for where a ghost can move and are used to
|
||||
* send ghosts after the player. If pacman is between Node A and Node B and
|
||||
* a ghost finds itself in Node A, it will turn and head in the direction of
|
||||
* Node B. These Intelligence specifics are handled in the
|
||||
* CIntelligence->CIntelGhost class
|
||||
*/
|
||||
public class CNode extends CCoord{
|
||||
|
||||
/**
|
||||
*Define where the ghost can move when at this node
|
||||
*/
|
||||
private boolean MV_LEFT;
|
||||
private boolean MV_RIGHT;
|
||||
private boolean MV_UP;
|
||||
private boolean MV_DN;
|
||||
//originally meant to genarilize code to allow increase height nodes
|
||||
//but removed due to deadline constraints
|
||||
//mmm, deadlines....mmmm
|
||||
//private boolean INC_HEIGHT;
|
||||
|
||||
///////////////
|
||||
//Constructor//
|
||||
///////////////
|
||||
|
||||
/**
|
||||
*@param up, can move up?
|
||||
*@param down, can move down?
|
||||
*@param left, can move left?
|
||||
*@param right, can move right?
|
||||
*@param x, x-coord
|
||||
*@param y, y-coord
|
||||
*@param h, h-coord
|
||||
*/
|
||||
public CNode(boolean up, boolean down, boolean left, boolean right,
|
||||
/*boolean incH,*/ int x, int y, int h){
|
||||
super(x,y,h);
|
||||
MV_UP = up;
|
||||
MV_DN = down;
|
||||
MV_LEFT = left;
|
||||
MV_RIGHT = right;
|
||||
//INC_HEIGHT = incH;
|
||||
}
|
||||
|
||||
///////////
|
||||
//Methods//
|
||||
///////////
|
||||
|
||||
/**
|
||||
*@return true if can go up from node
|
||||
*/
|
||||
public boolean canMV_UP(){
|
||||
return MV_UP;
|
||||
}
|
||||
|
||||
/**
|
||||
*@return true if can go down from node
|
||||
*/
|
||||
public boolean canMV_DN(){
|
||||
return MV_DN;
|
||||
}
|
||||
|
||||
/**
|
||||
*@return true if can move left from node
|
||||
*/
|
||||
public boolean canMV_LEFT(){
|
||||
return MV_LEFT;
|
||||
}
|
||||
|
||||
/**
|
||||
*@return true if can move right
|
||||
*/
|
||||
public boolean canMV_RIGHT(){
|
||||
return MV_RIGHT;
|
||||
}
|
||||
|
||||
/**
|
||||
*@return Coordinates of the Node
|
||||
*/
|
||||
public CCoord getNodeCoord(){
|
||||
return (new CCoord(this.getX(), this.getY(), this.getZ()));
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return (super.toString() + MV_UP+MV_DN+MV_LEFT+MV_RIGHT+"*/");
|
||||
}
|
||||
}// end of class CNode
|
||||
35
CS1322/p6/MyWay2/CPacman.java
Normal file
35
CS1322/p6/MyWay2/CPacman.java
Normal file
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* <PRE>
|
||||
* CPacman.java
|
||||
*
|
||||
* Revisions: 1.0 Nov. 24, 2002
|
||||
* Created the CPacman class
|
||||
*
|
||||
* </PRE>
|
||||
*
|
||||
* @author <A HREF="mailto:gtg184g@mail.gatech.edu">Jose Manuel Caban</A>
|
||||
* @version Version 1.0, Nov. 24, 2002
|
||||
*/
|
||||
|
||||
public class CPacman extends CMonster implements Constants{
|
||||
private CCoord currLocation;
|
||||
|
||||
public CPacman(CCoord startLoc){
|
||||
this.iX = startLoc.getX();
|
||||
this.iY = startLoc.getY();
|
||||
this.iZ = startLoc.getZ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Debugging main for class CPacman.
|
||||
* 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 CPacman
|
||||
93
CS1322/p6/MyWay2/CSprite.java
Normal file
93
CS1322/p6/MyWay2/CSprite.java
Normal file
@@ -0,0 +1,93 @@
|
||||
/**
|
||||
* <PRE>
|
||||
* CSprite.java
|
||||
*
|
||||
* Revisions: 1.0 Nov. 23, 2002
|
||||
* Created the CSprite class
|
||||
*
|
||||
* </PRE>
|
||||
*
|
||||
* @author <A HREF="mailto:gtg184g@mail.gatech.edu">Jose Manuel Caban</A>
|
||||
* @version Version 1.0, Nov. 23, 2002
|
||||
*/
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class CSprite {
|
||||
|
||||
/**
|
||||
*Holds image value(s)
|
||||
*/
|
||||
private ImageIcon[] imgSprite;
|
||||
|
||||
/**
|
||||
*Holds the baseName for the Image Sprite
|
||||
*(i.e. Imagename000.jpg, where 000 = animation number
|
||||
*/
|
||||
private String strImgName;
|
||||
|
||||
/**
|
||||
*Holds value for time (in fps) for animation delay
|
||||
*/
|
||||
private int iAnimDelay;
|
||||
|
||||
////////////////
|
||||
//Constructors//
|
||||
////////////////
|
||||
|
||||
/**
|
||||
*@param imgName, the base name for the image file
|
||||
* ex:Street.jpg and Street000.jpg would both have imgName of Street
|
||||
* use / to represent a different folder
|
||||
*@param strExt, the extension for the file
|
||||
* Acceptable types: .jpg, .gif, .bmp
|
||||
*@param animCount, the number of animations
|
||||
* Acceptable values: 1 or higher
|
||||
*/
|
||||
public CSprite(String imgName, String strExt, int animCount){
|
||||
imgSprite = new ImageIcon[animCount];
|
||||
this.strImgName = imgName+strExt;
|
||||
|
||||
for(int i=0; i<animCount; i++){
|
||||
String strName;
|
||||
if(i<10){
|
||||
strName = imgName + "00" + i + strExt;
|
||||
}
|
||||
else if(i<100){//no need to recheck if i<10, already done that and
|
||||
//skipped else{}
|
||||
strName = imgName + "0" + i + strExt;
|
||||
}
|
||||
else{
|
||||
strName = imgName + strExt;
|
||||
}
|
||||
|
||||
try{
|
||||
imgSprite[i] = new ImageIcon(imgName);
|
||||
}
|
||||
catch(Exception e){
|
||||
imgSprite[i] = new ImageIcon("Error.gif");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setAnimDelay(int c){
|
||||
iAnimDelay = c;
|
||||
}
|
||||
|
||||
public int getAnimDelay(){
|
||||
return iAnimDelay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Debugging main for class CSprite.
|
||||
* 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 CSprite
|
||||
125
CS1322/p6/MyWay2/CTile.java
Normal file
125
CS1322/p6/MyWay2/CTile.java
Normal file
@@ -0,0 +1,125 @@
|
||||
/**
|
||||
* <PRE>
|
||||
* Tile.java
|
||||
*
|
||||
* Revisions: 1.0 Nov. 12, 2002
|
||||
* Created the Tile class
|
||||
*
|
||||
* </PRE>
|
||||
*
|
||||
* @author <A HREF="mailto:gtg184g@mail.gatech.edu">Jose Manuel Caban</A>
|
||||
* @version Version 1.0, Nov. 12, 2002
|
||||
*/
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
*CTile "is-a" Coordinate, however, it is used for both walls and floor
|
||||
*using the height. The AI will be built specificaly for say level 1, which is
|
||||
*the ground height of the floor and level 2, the walls, will be left out
|
||||
*
|
||||
*Addendum: CTile is pacman specific is not fully generalized, it also removes
|
||||
* support for animated tiles such as water
|
||||
*/
|
||||
public class CTile extends CCoord{
|
||||
|
||||
/**
|
||||
*Defines whether the object is coming from the ground up to a given level
|
||||
*or whether it is a floating object (i.e. a bridge)
|
||||
*NOT IMPLEMENTED IN PACMAN
|
||||
*/
|
||||
private boolean bIsFloating; //special note, this will NOT be implemented
|
||||
//in standard Pacman, it is meant for future
|
||||
//manipulation
|
||||
|
||||
/**
|
||||
*Define whether block has a special nibble
|
||||
*/
|
||||
private boolean bHasSpecial;
|
||||
|
||||
/**
|
||||
*Define whether block has a nibble
|
||||
*/
|
||||
private boolean bHasNibble;
|
||||
|
||||
/**
|
||||
*Holds the tile picture data
|
||||
*/
|
||||
ImageIcon imgTile;
|
||||
|
||||
////////////////
|
||||
//Constructors//
|
||||
////////////////
|
||||
|
||||
/**
|
||||
*@param x, the x-coord
|
||||
*@param y, the y-coord
|
||||
*@param z, the z-coord
|
||||
*/
|
||||
public CTile(int x, int y, int z){
|
||||
this(x,y,z,false);
|
||||
//imgTile = new ImageIcon(icon);
|
||||
}
|
||||
|
||||
/**
|
||||
*Same as other constructor but adds
|
||||
*@param bIsFloating, defines whether the object is floating or not
|
||||
*/
|
||||
public CTile(int x, int y, int z, boolean bFloating){
|
||||
super(x,y,z);
|
||||
bIsFloating = bFloating;
|
||||
bHasSpecial = false;
|
||||
bHasNibble = false;
|
||||
}
|
||||
|
||||
///////////////////////
|
||||
//Accessors/Modifiers//
|
||||
///////////////////////
|
||||
|
||||
/**
|
||||
*@return true if object can be passed over
|
||||
*/
|
||||
public boolean isPassable(CCoord op){
|
||||
if(op.getZ() == this.iZ){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isSpecial(){
|
||||
return bHasSpecial;
|
||||
}
|
||||
|
||||
public boolean isNibble(){
|
||||
return bHasNibble;
|
||||
}
|
||||
|
||||
public void setImage(String filename){
|
||||
imgTile = new ImageIcon(filename);
|
||||
}
|
||||
|
||||
/**
|
||||
*@param nibble, whether or not it has a nibble
|
||||
*@param special, whether or not it has a special
|
||||
*/
|
||||
public void setItems(boolean nibble, boolean special){
|
||||
bHasNibble = nibble;
|
||||
bHasSpecial = special;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Debugging main for class Tile.
|
||||
* 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 Tile
|
||||
28
CS1322/p6/MyWay2/Constants.java
Normal file
28
CS1322/p6/MyWay2/Constants.java
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* <PRE>
|
||||
* Constants.java
|
||||
*
|
||||
* Revisions: 1.0 Nov. 13, 2002
|
||||
* Created the Constants class
|
||||
*
|
||||
* </PRE>
|
||||
*
|
||||
* @author <A HREF="mailto:gtg184g@mail.gatech.edu">Jose Manuel Caban</A>
|
||||
* @version Version 1.0, Nov. 13, 2002
|
||||
*/
|
||||
|
||||
public interface Constants {
|
||||
|
||||
/*Directions*/
|
||||
/**
|
||||
*Define 4 movement constants: MV_UP, MV_DN, MV_LFT, MV_RGHT
|
||||
*/
|
||||
public static final int MV_UP = 0;
|
||||
public static final int MV_DN = 1;
|
||||
public static final int MV_LEFT = 2;
|
||||
public static final int MV_RIGHT = 3;
|
||||
public static final int MV_SAMEDIR= 4;
|
||||
|
||||
|
||||
|
||||
}// end of class Constants
|
||||
BIN
CS1322/p6/MyWay2/PacmanDown001.gif
Normal file
BIN
CS1322/p6/MyWay2/PacmanDown001.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 158 B |
BIN
CS1322/p6/MyWay2/PacmanLeft001.gif
Normal file
BIN
CS1322/p6/MyWay2/PacmanLeft001.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 146 B |
BIN
CS1322/p6/MyWay2/PacmanRight001.gif
Normal file
BIN
CS1322/p6/MyWay2/PacmanRight001.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 147 B |
BIN
CS1322/p6/MyWay2/PacmanUp001.gif
Normal file
BIN
CS1322/p6/MyWay2/PacmanUp001.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 158 B |
20
CS1322/p6/MyWay2/board_1.txt
Normal file
20
CS1322/p6/MyWay2/board_1.txt
Normal 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
|
||||
Reference in New Issue
Block a user