Skip to content

Commit aa1f8b1

Browse files
committed
Complete Commit: Classes, Driver, Images, Audio
0 parents  commit aa1f8b1

35 files changed

+1999
-0
lines changed

Blinky.java

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//*****************************************
2+
// Blinky.java Author: Austin George
3+
// The Red Ghost in Pac Man
4+
//*****************************************
5+
public class Blinky extends Ghost
6+
{
7+
//*****************************************************
8+
// Blinky(GameBoard board, int delay, String file)
9+
// Full Constructor
10+
//*****************************************************
11+
public Blinky(GameBoard board, int delay, String file)
12+
{
13+
super(board,delay,file);
14+
}
15+
16+
//*******************************
17+
// Blinky(GameBoard board)
18+
// Partial Constructor
19+
//*******************************
20+
public Blinky(GameBoard board)
21+
{
22+
this(board,2200);
23+
}
24+
25+
//****************************************
26+
// Blinky(GameBoard board, int delay)
27+
// Partial Constructor
28+
//****************************************
29+
public Blinky(GameBoard board, int delay)
30+
{
31+
super(board,delay,"blinky.png");
32+
}
33+
34+
//************************************************************
35+
// chooseDirection()
36+
// Determines direction based on the following algorithm:
37+
// - Target PacMan's Location
38+
// - Determine Euclidean (Straight-Line) Path to Target
39+
// - Take the proper navigation along that route
40+
// Personality: Chaser
41+
//************************************************************
42+
public void chooseDirection()
43+
{
44+
int targetX, targetY;
45+
//Scatter Mode: Scurry to Top Right Corner
46+
if(board.getIndex() < delay+scatter)
47+
{
48+
targetX = 470;
49+
targetY = 160;
50+
}
51+
//Pursuit Mode
52+
else
53+
{
54+
targetX = board.getPacman().getX();
55+
targetY = board.getPacman().getY();
56+
}
57+
pursueTarget(targetX,targetY);
58+
}
59+
}

Clyde.java

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//*****************************************
2+
// Blinky.java Author: Austin George
3+
// The Red Ghost in Pac Man
4+
//*****************************************
5+
public class Clyde extends Ghost
6+
{
7+
//****************************************************
8+
// Clyde(GameBoard board, int delay, String file)
9+
// Full Constructor
10+
//****************************************************
11+
public Clyde(GameBoard board, int delay, String file)
12+
{
13+
super(board,delay,file);
14+
}
15+
16+
//***********************************
17+
// Clyde(GameBoard board)
18+
// Partial Constructor
19+
//***********************************
20+
public Clyde(GameBoard board)
21+
{
22+
this(board,4600);
23+
}
24+
25+
//***************************************
26+
// Clyde(GameBoard board, int delay)
27+
// Partial Constructor
28+
//***************************************
29+
public Clyde(GameBoard board, int delay)
30+
{
31+
super(board,delay,"clyde.png");
32+
}
33+
//************************************************************
34+
// chooseDirection()
35+
// Determines direction based on the following algorithm:
36+
// - Target PacMan's Location
37+
// - Determine Euclidean (Straight-Line) Path to Target
38+
// - Take the proper navigation along that route
39+
// Personality: Ignorant
40+
//************************************************************
41+
public void chooseDirection()
42+
{
43+
//Scatter Mode
44+
if(board.getIndex() < delay+scatter)
45+
{
46+
int targetX = 150;//510
47+
int targetY = 650;//60;
48+
pursueTarget(targetX,targetY);
49+
}
50+
//Pursuit Mode -- or lack thereof
51+
else randomizeDirection();
52+
}
53+
}

Dot.java

+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
//***************************************
2+
// Dot.java Author: Austin George
3+
// Exists as a dot for PacMan to eat
4+
//***************************************
5+
import javax.swing.*;
6+
import java.awt.*;
7+
8+
public class Dot extends JPanel
9+
{
10+
private int x,y,width,height,header;
11+
private ImageIcon wholeIcon;
12+
private ImageIcon wholeIconX;
13+
private JLabel label;
14+
private boolean eaten;
15+
private GameBoard board;
16+
17+
//*************************
18+
// Dot()
19+
// Default Constructor
20+
//*************************
21+
public Dot()
22+
{
23+
x = 0;
24+
y = 0;
25+
width = 0;
26+
height = 0;
27+
header = 100;
28+
setGUI();
29+
}
30+
31+
//****************************************
32+
// Dot(int x, int y, GameBoard board)
33+
// Complete Constructor
34+
//****************************************
35+
public Dot(int x, int y, GameBoard board)
36+
{
37+
header = 100;
38+
this.x = x;
39+
this.y = y + header; //header will offset the coordinates so the board shifts down
40+
width = 20;
41+
height = 20;
42+
eaten = false;
43+
this.board = board;
44+
45+
wholeIcon = new ImageIcon("dot.png");
46+
wholeIconX = new ImageIcon(wholeIcon.getImage().getScaledInstance(6,6,Image.SCALE_SMOOTH));
47+
label = new JLabel(wholeIconX, JLabel.CENTER);
48+
49+
setLayout(null);
50+
label.setForeground(Color.yellow);
51+
label.setIconTextGap(0);
52+
label.setBounds(7,7,6,6);//10,10
53+
add(label);
54+
55+
setBackground(Color.black);
56+
}
57+
58+
//***********************
59+
// setGUI()
60+
// Set GUI
61+
//***********************
62+
public void setGUI()
63+
{ setPreferredSize(new Dimension(width,height)); }
64+
65+
//***********************
66+
// getX()
67+
// Gets x
68+
//***********************
69+
public int getX()
70+
{ return x; }
71+
72+
//***********************
73+
// getY()
74+
// Gets y
75+
//***********************
76+
public int getY()
77+
{ return y; }
78+
79+
//***********************
80+
// getWidth()
81+
// Gets width
82+
//***********************
83+
public int getWidth()
84+
{ return width; }
85+
86+
//***********************
87+
// getHeight()
88+
// Gets height
89+
//***********************
90+
public int getHeight()
91+
{ return height; }
92+
93+
//**************************
94+
// setEaten(boolean eat)
95+
// Sets eat
96+
//**************************
97+
public void setEaten(boolean eat)
98+
{
99+
eaten = eat;
100+
if (eaten)label.setIcon(null);
101+
else label.setIcon(wholeIconX);
102+
}
103+
104+
//**************************
105+
// isEaten()
106+
// Gets eaten
107+
//**************************
108+
public boolean isEaten()
109+
{ return eaten; }
110+
111+
//*************************************************
112+
// overlap(int xQ. int yQ)
113+
// Determines if a coordinate overlaps the dot
114+
//*************************************************
115+
public boolean overlap(int xQ, int yQ)
116+
{
117+
//Whole PacMan is Above Wall
118+
if (yQ + 20 <= y) return false; //20
119+
120+
//Whole PacMan is Below Wall
121+
if (yQ + 20 >= y+height) return false; //-20
122+
123+
//Whole PacMan is Left of Wall
124+
if (xQ + 20 <= x) return false; //40
125+
126+
//Whole PacMan is Right of Wall
127+
if (xQ + 20 >= x+width) return false; //-20
128+
129+
if (eaten == false)
130+
{
131+
eaten = true;
132+
label.setIcon(null);
133+
setOpaque(true);
134+
return true;
135+
}
136+
return false;
137+
}
138+
}

Entry.java

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//****************************************
2+
// Entry.java Author: Austin George
3+
// Acts as an entry in Leaderboards
4+
//****************************************
5+
public class Entry implements Comparable
6+
{
7+
private String name;
8+
private int score;
9+
public Entry()
10+
{
11+
name="";
12+
score=0;
13+
}
14+
15+
public Entry(String name, int score)
16+
{
17+
this.name = name;
18+
this.score = score;
19+
}
20+
21+
public String getName()
22+
{ return name; }
23+
24+
public int getScore()
25+
{ return score; }
26+
27+
public int compareTo(Object obj)
28+
{
29+
Entry entry = (Entry)obj;
30+
if(score == entry.getScore()) return 0;
31+
else if (score > entry.getScore()) return 1;
32+
else return -1;
33+
}
34+
}

0 commit comments

Comments
 (0)