Commit cec50d4b by Joe Student

pacman added

parent 515c7379
Showing with 1955 additions and 0 deletions
,2Ah5si3BMr .3HA
r:: ,H@G: .;&M; s@#@@. .3As
.:rS22r. ;@@@B .#@, ... @i s#. @@: .3@#@@ :A&r
:sXB#@@#Hh22XX#@: h# :@@ X@ ..... .S@@2 S5XX2A: iB #@r .2@#: @9 i@MM@: ,:
i@A;:, 2@r:#s .@@: @2 ..,,,.,iB@@S. @@SS52@2 SH G@2s@@; .@r ,A@i @M h@@A 2i:.
@S ri ,sX@XA A@i #2 ..,,,.r@@2 s@..,.A@i5G s@@r ;@, r@M, 2@. .#h3@S ;@##@@#
X# ....@@. ;Xr@@: . r@5.M ......:ii29Xi; .@@@@#Ai92 .. . .. i@ .9@5 @G r@, M@: A# .;2@
;@r .,. ,:s5:M@A ..@@. rs#A5S .... s#;@; :Bs ... .. G,X@ ,##: ,s. h@ &A @@;#; ;@:
#A ... 2hS23h@9M . sS 3;9@AS: ;5S@@. i@, .... @.HB;@X . &@2 ..@S ;#r .@@M .. @@
5@. .. 9X;@2::Xi .. .:,#:;@Xr22srrriM##i #3irr;:,.:XSsG @#9, .. . 3;3@ SM . ,@r .. ;@S
,@i . #.@ iA .,:sAG3hS@@5 .:sX9S; X@@@@@@@@@@#hX@@: .. ,..A.@93i ... ;. ., M@
M# :;;;& #9 M@SH@@@@@@BXir;, .,;riS&M@@@@@AXsXXr& 2@H ... rH,@i
r@i9HHBAH@@ 2hi;, .:s3B@@@#HXh@A ,. @:9@
sMH2r:. :r5G@@@@AS;2Xsi& @S
:SH@@@@#H:9@
,;s5hr
___________________________________________________________________________________________________________________
LINK TO DEMO VIDEO- https://www.youtube.com/watch?v=WXvOjMfTUmk
CONTROLS- Use the arrow keys to control pac man, he will automatically move in whatever direction he is
facing, provided there is not a wall in front of him. Do not hold them down, as the arrow keys do not respond as well to
being held down versus letter keys.
Press 'S' to start the game
KEY FEATURES- The game plays very true to the original Pac-Man, most notably in the ghost logic. The board consists of a
28 x 36 grid, which contains the playable space as well as life and score display. All 4 ghosts use the same logic to determine
their directions as they do in the original game, all code for ghost logic is original, based on several publications and websites
discussing the way they decide to move.
Ghosts have 3 modes: Scatter, Chase, and Frightened. They start the game in scatter mode for 7 seconds, then chase mode for 20, then
back to scatter for 7. This pattern continues for 3 cycles until they stay in perpetual chase mode.
When a PacMan eats an Energizer, one of the big dots, the ghosts enter Frightened mode and turn blue. As the levels progress,
the time that the ghosts stay frightened. When the ghosts are in frightened mode, they turn randomly.
When the ghosts are in Scatter mode, they each try to move as close to a pre-determined square as possible. When they are in chase mode
they each try to get as close to a certain target square as possible, more details on each ghosts logic are available on each ghost's
class file.
Ghosts make their decision one turn in advance. When they reach a square, they immediately look to the next square and decide
which way they will turn, if it all. Ghosts ONLY reverse direction when a mode change occurs, provided they have not just completed
a turn and are still in the same square.
BONUS LIFE- As in the original, the player is awarded a bonus life when their score reaches 10,000
FRUIT- After 70 dots, a cherry pops up and awards pac-man 100 bonus points if eaten.
In addition to these features, there are a couple of extra features:
Press 'O' for Ouija mode, this will summon an extra ghost for each time it's pressed. Avoid holding it down as ghosts spawned
at exactly the same time will essentially act as one ghost, more on that later.
Press 'G' for Ghostbuster mode, this will give pac-man a 3 second proton-pack which will allow him to suck up ghosts and
get him out of a jam. You only get 3 of these per game.
package lec08.pmnehls.finalproject.game.model;
import java.awt.*;
import java.util.ArrayList;
/**
* Created by pmnehls on 12/1/14.
*/
public class Cherry extends Sprite
{
public Cherry()
{
super();
ArrayList<Point> pntCs = new ArrayList<Point>();
pntCs.add(new Point(6, 6));
pntCs.add(new Point(6, 4));
pntCs.add(new Point(4, 4));
pntCs.add(new Point(4, 2));
pntCs.add(new Point(3, 2));
pntCs.add(new Point(3, 1));
pntCs.add(new Point(2, 1));
pntCs.add(new Point(2, 0));
pntCs.add(new Point(4, 0));
pntCs.add(new Point(4, -1));
pntCs.add(new Point(5, -1));
pntCs.add(new Point(5, -5));
pntCs.add(new Point(4, -5));
pntCs.add(new Point(4, -6));
pntCs.add(new Point(0, -6));
pntCs.add(new Point(0, -5));
pntCs.add(new Point(-1, -5));
pntCs.add(new Point(-1, -1));
pntCs.add(new Point(0, -1));
pntCs.add(new Point(0, 0));
pntCs.add(new Point(1, 0));
pntCs.add(new Point(1, 1));
pntCs.add(new Point(2, 1));
pntCs.add(new Point(2, 2));
pntCs.add(new Point(3, 2));
pntCs.add(new Point(3, 4));
pntCs.add(new Point(2, 4));
pntCs.add(new Point(2, 3));
pntCs.add(new Point(0, 3));
pntCs.add(new Point(0, 2));
pntCs.add(new Point(-1, 2));
pntCs.add(new Point(-1, 1));
pntCs.add(new Point(0, 1));
pntCs.add(new Point(0, 0));
pntCs.add(new Point(-1, 0));
pntCs.add(new Point(-1, -1));
pntCs.add(new Point(-2, -1));
pntCs.add(new Point(-2, -4));
pntCs.add(new Point(-5, -4));
pntCs.add(new Point(-5, -3));
pntCs.add(new Point(-6, -3));
pntCs.add(new Point(-6, 1));
pntCs.add(new Point(-5, 1));
pntCs.add(new Point(-5, 2));
pntCs.add(new Point(-1, 2));
pntCs.add(new Point(-1, 3));
pntCs.add(new Point(0, 3));
pntCs.add(new Point(0, 4));
pntCs.add(new Point(2, 4));
pntCs.add(new Point(2, 5));
pntCs.add(new Point(3, 5));
pntCs.add(new Point(3, 6));
assignPolarPoints(pntCs);
setColor(Color.RED);
//put cherry in correct location
setCenter(new Point(TargetSpace.TS_WIDTH*(14),
TargetSpace.TS_HEIGHT*(20) + TargetSpace.TS_HEIGHT/2));
setOrientation(270);
setRadius(14);
}
public void draw(Graphics g)
{
super.draw(g);
g.fillPolygon(getXcoords(), getYcoords(), dDegrees.length);
}
}
package lec08.pmnehls.finalproject.game.model;
import java.util.concurrent.CopyOnWriteArrayList;
import lec08.pmnehls.finalproject.controller.Game;
import lec08.pmnehls.finalproject.sounds.Sound;
import javax.sound.sampled.Clip;
public class CommandCenter {
private static int nNumFalcon;
private static int nLevel = 1;
private static long lScore;
private static Pacman pacman;
private static boolean bPlaying;
private static boolean bIntroDone = false;
private static boolean bPaused;
private static int nProtonTick;
private static boolean bProton;
// These ArrayLists are thread-safe
public static CopyOnWriteArrayList<Movable> movDebris = new CopyOnWriteArrayList<Movable>();
public static CopyOnWriteArrayList<Movable> movFriends = new CopyOnWriteArrayList<Movable>();
public static CopyOnWriteArrayList<Movable> movPacman = new CopyOnWriteArrayList<Movable>();
public static CopyOnWriteArrayList<Movable> movFoes = new CopyOnWriteArrayList<Movable>();
public static CopyOnWriteArrayList<Movable> movFloaters = new CopyOnWriteArrayList<Movable>();
public static CopyOnWriteArrayList<Movable> movEnergizers = new CopyOnWriteArrayList<Movable>();
public static CopyOnWriteArrayList<Movable> movDots = new CopyOnWriteArrayList<Movable>();
public static CopyOnWriteArrayList<Movable> movLives = new CopyOnWriteArrayList<Movable>();
public static CopyOnWriteArrayList<Movable> movProton = new CopyOnWriteArrayList<Movable>();
//create board as a grid of target spaces
public static TargetSpace[][] grid = new TargetSpace[28][36];
// Constructor made private - static Utility class only
private CommandCenter() {}
public static void initGame(){
setMaze();
setLevel(nLevel);
setTimers();
setScore(0);
initPacmanLives();
initProtonPacks();
}
public static void setMaze()
{
//loop over TargetSpaces and initialize contents
for (int nD = 0; nD < 36; nD++)
{
for (int nC = 0; nC < 28; nC++)
{
grid[nC][nD] = new TargetSpace(nC+1, nD+1);
if(grid[nC][nD].getIsEnergizer())
{
movEnergizers.add(new Energizer(nC+1, nD+1));
}
else if (grid[nC][nD].getIsDot())
{
movDots.add(new Dot(nC+1, nD+1));
}
else if (grid[nC][nD].getIsGhostBox())
{
movDebris.add(new GhostBox(nC+1, nD+1));
}
else if (grid[nC][nD].getIsWall())
{
movDebris.add(new Wall(nC+1, nD+1));
}
}
}
}
public static void setTimers()
{
if(nLevel == 1)
{
Game.setScaredSeconds(6);
}
else if (nLevel == 2)
{
Game.setScaredSeconds(5);
}
else if (nLevel == 3)
{
Game.setScaredSeconds(4);
}
else if (nLevel == 4)
{
Game.setScaredSeconds(3);
}
else if (nLevel == 5)
{
Game.setScaredSeconds(2);
}
else if (nLevel == 6)
{
Game.setScaredSeconds(5);
}
else if (nLevel >= 7 && nLevel < 10)
{
Game.setScaredSeconds(2);
}
else
{
Game.setScaredSeconds(1);
}
}
public static void playIntro()
{
Game.setnTick(0);
Sound.playSound("pacman_beginning.wav");
bIntroDone = true;
}
public static void initPacmanLives()
{
for (int nC = 0; nC < Game.getLives() - 1; nC++)
{
movLives.add(new Life(TargetSpace.TS_WIDTH * (1 + (2 * nC)), TargetSpace.TS_HEIGHT*35));
}
}
public static void initProtonPacks()
{
for (int nC = 0; nC < Game.getProtonsLeft(); nC++)
{
movLives.add(new ProtonPackDisplay(TargetSpace.TS_WIDTH * (14 + (2 * nC)), TargetSpace.TS_HEIGHT*35));
}
}
public static void spawnPacman(boolean bFirst)
{
if (bFirst)
{
pacman = new Pacman();
movPacman.add(pacman);
}
else
{
pacman = new Pacman();
movPacman.add(pacman);
}
}
public static void spawnCherry()
{
Cherry cherry = new Cherry();
movDots.add(cherry);
}
public static void spawnBlinky(boolean bFirstBlinky)
{
if (bFirstBlinky)
{
Blinky blinky = new Blinky(true);
//Eyes eyes = new Eyes(blinky);
movFoes.add(blinky);
//movDebris.add(eyes);
}
else
{
Blinky blinky = new Blinky(false);
blinky.setRespawn(true);
movFoes.add(blinky);
}
}
public static void spawnPinky(boolean bFirstPinky)
{
if (bFirstPinky)
{
Pinky pinky = new Pinky();
movFoes.add(pinky);
}
else
{
Pinky pinky = new Pinky();
pinky.setRespawn(true);
movFoes.add(pinky);
}
}
public static void spawnInky(boolean bFirstInky)
{
if (bFirstInky)
{
Inky inky = new Inky();
movFoes.add(inky);
}
else
{
Inky inky = new Inky();
inky.setRespawn(true);
movFoes.add(inky);
}
}
public static void spawnClyde(boolean bFirstClyde)
{
if (bFirstClyde)
{
Clyde clyde = new Clyde();
movFoes.add(clyde);
}
else
{
Clyde clyde = new Clyde();
clyde.setRespawn(true);
movFoes.add(clyde);
}
}
public static void clearAll(){
movDebris.clear();
movFriends.clear();
movFoes.clear();
movDots.clear();
movEnergizers.clear();
movFloaters.clear();
movPacman.clear();
movProton.clear();
}
public static void startNextLevel(int nLevel)
{
initPacmanLives();
initProtonPacks();
setMaze();
setLevel(nLevel);
Game.setnTick(0);
Game.setDotCounter(0);
Game.setEnergizerCounter(0);
Game.setIsInvincible(false);
Game.setFruitBool(false);
}
public static void spawnAllAfterPause()
{
Game.setnTick(0);
setTimers();
spawnPacman(true);
spawnBlinky(true);
spawnPinky(true);
spawnInky(true);
spawnClyde(true);
Game.setIsInvincible(false);
Game.getSiren().loop(Clip.LOOP_CONTINUOUSLY);
}
public static void initialSpawn()
{
setTimers();
spawnPacman(true);
spawnBlinky(true);
spawnPinky(true);
spawnInky(true);
spawnClyde(true);
}
public static void resetLevel()
{
movLives.clear();
movProton.clear();
Game.setnTick(0);
initPacmanLives();
initProtonPacks();
setTimers();
}
public static void ouija(int nTick)
{
spawnBlinky(false);
}
public static void protonPack()
{
Sound.playSound("export.wav");
if (movPacman.size() != 0)
{
pacman = (Pacman)movPacman.get(0);
Proton proton = new Proton(pacman);
proton.setOrientation(pacman.getOrientation());
movProton.add(proton);
CommandCenter.nProtonTick = Game.getnTick();
bProton = true;
movLives.clear();
initPacmanLives();
initProtonPacks();
}
}
public static boolean isPlaying() {
return bPlaying;
}
public static void setPlaying(boolean bPlaying) {
CommandCenter.bPlaying = bPlaying;
}
public static boolean isPaused() {
return bPaused;
}
public static void setPaused(boolean bPaused) {
CommandCenter.bPaused = bPaused;
}
public static boolean isGameOver() { //if pacman's lives = 0, then game over
if (Game.getLives() == 0) {
Game.setStarted(false);
Game.setLives(4);
Game.setProtonsLeft(3);
Game.setRespawnAfterDeath(false);
Game.setInitial(true);
Game.setFruitBool(false);
Game.setDotCounter(0);
return true;
}
return false;
}
public static int getLevel() {
return nLevel;
}
public static long getScore() {
return lScore;
}
public static void setScore(long lParam) {
lScore = lParam;
}
public static void setLevel(int n) {
nLevel = n;
}
//public static int getNumFalcons() {
// return nNumFalcon;
//}
//public static Falcon getFalcon(){
// return falShip;
//}
public static Pacman getPacman() { return pacman;}
public static boolean getProton()
{
return CommandCenter.bProton;
}
public static void setProton(boolean bProton)
{
CommandCenter.bProton = bProton;
}
public static int getProtonTick()
{
return CommandCenter.nProtonTick;
}
}
package lec08.pmnehls.finalproject.game.model;
import java.awt.*;
import java.util.ArrayList;
/**
* Created by pmnehls on 11/19/14.
*/
public class Dot extends Sprite
{
private int nDotX;
private int nDotY;
public Dot(int x, int y)
{
super();
nDotX = x;
nDotY = y;
ArrayList<Point> pntCs = new ArrayList<Point>();
pntCs.add(new Point(2, 4));
pntCs.add(new Point(4, 2));
pntCs.add(new Point(4, -2));
pntCs.add(new Point(2, -4));
pntCs.add(new Point(-2, -4));
pntCs.add(new Point(-4, -2));
pntCs.add(new Point(-4, 2));
pntCs.add(new Point(-2, 4));
assignPolarPoints(pntCs);
int nHeight = TargetSpace.TS_HEIGHT;
int nWidth = TargetSpace.TS_WIDTH;
setCenter(new Point(nHeight * (x - 1) + nHeight/2, nWidth * (y - 1) + nWidth/2));
setRadius(2);
}
@Override
public void draw(Graphics g) {
super.draw(g);
g.fillPolygon(getXcoords(), getYcoords(), dDegrees.length);
}
}
package lec08.pmnehls.finalproject.game.model;
import lec08.pmnehls.finalproject.controller.Game;
import java.awt.*;
import java.util.ArrayList;
/**
* Created by pmnehls on 11/19/14.
*/
public class Energizer extends Sprite
{
private int nEnergizerX;
private int nEnergizerY;
public Energizer(int x, int y)
{
super();
nEnergizerX = x;
nEnergizerY = y;
ArrayList<Point> pntCs = new ArrayList<Point>();
pntCs.add(new Point(2, 4));
pntCs.add(new Point(4, 2));
pntCs.add(new Point(4, -2));
pntCs.add(new Point(2, -4));
pntCs.add(new Point(-2, -4));
pntCs.add(new Point(-4, -2));
pntCs.add(new Point(-4, 2));
pntCs.add(new Point(-2, 4));
assignPolarPoints(pntCs);
setColor(new Color(200,200,200));
int nHeight = TargetSpace.TS_HEIGHT;
int nWidth = TargetSpace.TS_WIDTH;
setCenter(new Point(nHeight * (x - 1) + nHeight/2, nWidth * (y - 1) + nWidth/2));
setRadius(8);
}
public void draw(Graphics g) {
super.draw(g);
g.fillPolygon(getXcoords(), getYcoords(), dDegrees.length);
}
}
package lec08.pmnehls.finalproject.game.model;
import lec08.pmnehls.finalproject.sounds.Sound;
import java.awt.*;
import java.util.ArrayList;
/**
* Created by pmnehls on 12/3/14.
*/
public class Eyes extends Sprite
{
private Movable ghost;
public Eyes(Movable ghost) {
super();
ArrayList<Point> pntCs = new ArrayList<Point>();
pntCs.add(new Point(-5, -1));
pntCs.add(new Point(-5, 2));
pntCs.add(new Point(-4, 2));
pntCs.add(new Point(-4, 3));
pntCs.add(new Point(-2, 3));
pntCs.add(new Point(-2, 2));
pntCs.add(new Point(-1, 2));
pntCs.add(new Point(-1, 0));
pntCs.add(new Point(1, 0));
pntCs.add(new Point(1, 2));
pntCs.add(new Point(2, 2));
pntCs.add(new Point(2, 3));
pntCs.add(new Point(4, 3));
pntCs.add(new Point(4, 2));
pntCs.add(new Point(5, 2));
pntCs.add(new Point(5, -1));
pntCs.add(new Point(4, -1));
pntCs.add(new Point(4, -2));
pntCs.add(new Point(2, -2));
pntCs.add(new Point(2, -1));
pntCs.add(new Point(1, -1));
pntCs.add(new Point(1, 0));
pntCs.add(new Point(-1, 0));
pntCs.add(new Point(-1, -1));
pntCs.add(new Point(-2, -1));
pntCs.add(new Point(-2, -2));
pntCs.add(new Point(-4, -2));
pntCs.add(new Point(-4, -1));
assignPolarPoints(pntCs);
setColor(Color.WHITE);
this.ghost = ghost;
setCenter(ghost.getCenter());
//facing left
setOrientation(270);
//this is the size of Eyes
setRadius(6);
}
public void draw(Graphics g)
{
super.draw(g);
g.fillPolygon(getXcoords(), getYcoords(), dDegrees.length);
}
public void move()
{
super.move();
setCenter(ghost.getCenter());
}
public Movable getGhost()
{
return ghost;
}
}
package lec08.pmnehls.finalproject.game.model;
import java.awt.*;
import java.util.ArrayList;
/**
* Created by pmnehls on 11/20/14.
*/
public class GhostBox extends Sprite
{
private boolean isLid;
public GhostBox(int x, int y)
{
super();
if (y == 16 && (x == 14 || x == 15))
{
isLid = true;
}
ArrayList<Point> pntCs = new ArrayList<Point>();
if (isLid)
{
pntCs.add(new Point(1, 5));
pntCs.add(new Point(1, -5));
pntCs.add(new Point(-1, -5));
pntCs.add(new Point(-1, 5));
assignPolarPoints(pntCs);
setColor(Color.WHITE);
setRadius(8);
}
else
{
pntCs.add(new Point(1, 1));
pntCs.add(new Point(1, -1));
pntCs.add(new Point(-1, -1));
pntCs.add(new Point(-1, 1));
assignPolarPoints(pntCs);
setColor(new Color(0,0,180));
setRadius(6);
}
int nHeight = TargetSpace.TS_HEIGHT;
int nWidth = TargetSpace.TS_WIDTH;
setCenter(new Point(nWidth * (x - 1) + nWidth/2, nHeight * (y - 1) + nHeight/2));
}
@Override
public void draw(Graphics g) {
super.draw(g);
g.fillPolygon(getXcoords(), getYcoords(), dDegrees.length);
}
}
package lec08.pmnehls.finalproject.game.model;
import java.awt.*;
import java.util.ArrayList;
/**
* Created by pmnehls on 11/23/14.
*/
public class Life extends Sprite
{
public Life(int x, int y)
{
super();
ArrayList<Point> pntCs = new ArrayList<Point>();
pntCs.add(new Point(3, 7));
pntCs.add(new Point(3, 6));
pntCs.add(new Point(5, 6));
pntCs.add(new Point(5, 5));
pntCs.add(new Point(6, 5));
pntCs.add(new Point(6, 3));
pntCs.add(new Point(4, 3));
pntCs.add(new Point(4, 2));
pntCs.add(new Point(1, 2));
pntCs.add(new Point(1, 1));
pntCs.add(new Point(-2, 1));
pntCs.add(new Point(-2, 0));
pntCs.add(new Point(1, 0));
pntCs.add(new Point(1, -1));
pntCs.add(new Point(4, -1));
pntCs.add(new Point(4, -2));
pntCs.add(new Point(6, -2));
pntCs.add(new Point(6, -4));
pntCs.add(new Point(5, -4));
pntCs.add(new Point(5, -5));
pntCs.add(new Point(3, -5));
pntCs.add(new Point(3, -6));
pntCs.add(new Point(-2, -6));
pntCs.add(new Point(-2, -5));
pntCs.add(new Point(-4, -5));
pntCs.add(new Point(-4, -4));
pntCs.add(new Point(-5, -4));
pntCs.add(new Point(-5, -2));
pntCs.add(new Point(-6, -2));
pntCs.add(new Point(-6, 3));
pntCs.add(new Point(-5, 3));
pntCs.add(new Point(-5, 5));
pntCs.add(new Point(-4, 5));
pntCs.add(new Point(-4, 6));
pntCs.add(new Point(-2, 6));
pntCs.add(new Point(-2, 7));
assignPolarPoints(pntCs);
setColor(Color.yellow);
//put life in correct location
setCenter(new Point(x, y - TargetSpace.TS_HEIGHT/4));
setOrientation(270);
setRadius(12);
}
public void draw(Graphics g)
{
super.draw(g);
g.fillPolygon(getXcoords(), getYcoords(), dDegrees.length);
}
}
package lec08.pmnehls.finalproject.game.model;
import java.awt.*;
public interface Movable {
//for the game to draw
public void move();
public void draw(Graphics g);
//for collisions
//if two objects are both friends or both foes, then nothing happens, otherwise exlode both
//the friend type may be DEBRIS, in which case it is inert
//public byte getFriend();
//when a foe explodes, your points increase
public int points();
public Point getCenter();
public int getRadius();
//for short-lasting objects only like powerUps, bullets, special weapons and UFOs
//controls nExpiry that clicks down to expire, then the object should remove itself
//see Bullet class for how this works.
public void expire();
//for fading objects
public void fadeInOut();
public int getOrientation();
public void setRespawn(boolean bRespawn);
public boolean getRespawn();
} //end Movable
package lec08.pmnehls.finalproject.game.model;
import java.awt.*;
import java.util.ArrayList;
import java.util.Random;
/**
* Created by pmnehls on 12/3/14.
*/
public class Proton extends Sprite
{
private Pacman pacman;
public Proton(Pacman pacman)
{
super();
ArrayList<Point> pntCs = new ArrayList<Point>();
pntCs.add(new Point(0, 0));
pntCs.add(new Point(0, 1));
pntCs.add(new Point(6, 1));
pntCs.add(new Point(6, 2));
pntCs.add(new Point(13, 2));
pntCs.add(new Point(13, 3));
pntCs.add(new Point(17, 3));
pntCs.add(new Point(17, -3));
pntCs.add(new Point(13, -3));
pntCs.add(new Point(13, -2));
pntCs.add(new Point(6, -2));
pntCs.add(new Point(6, -1));
pntCs.add(new Point(0, -1));
assignPolarPoints(pntCs);
setColor(Color.WHITE);
setCenter(pacman.getCenter());
//facing left
setOrientation(270);
//this is the size of Eyes
setRadius(30);
this.pacman = pacman;
}
public void draw(Graphics g)
{
super.draw(g);
g.fillPolygon(getXcoords(), getYcoords(), dDegrees.length);
}
public void move()
{
super.move();
if (pacman.getOrientation() == 0)
{
setCenter(new Point(pacman.getCenter().x, pacman.getCenter().y - 12));
}
else if (pacman.getOrientation() == 90)
{
setCenter(new Point(pacman.getCenter().x + 12, pacman.getCenter().y));
}
else if (pacman.getOrientation() == 180)
{
setCenter(new Point(pacman.getCenter().x, pacman.getCenter().y + 12));
}
else if (pacman.getOrientation() == 270)
{
setCenter(new Point(pacman.getCenter().x - 12, pacman.getCenter().y));
}
Random ran = new Random();
setColor(new Color(ran.nextInt(255), ran.nextInt(255), ran.nextInt(255)));
setOrientation(pacman.getOrientation());
}
}
package lec08.pmnehls.finalproject.game.model;
import java.awt.*;
import java.util.ArrayList;
/**
* Created by pmnehls on 12/4/14.
*/
public class ProtonPackDisplay extends Sprite
{
public ProtonPackDisplay(int x, int y)
{
super();
ArrayList<Point> pntCs = new ArrayList<Point>();
pntCs.add(new Point(-1, -6));
pntCs.add(new Point(0, -6));
pntCs.add(new Point(2, -4));
pntCs.add(new Point(2, -2));
pntCs.add(new Point(1, -1));
pntCs.add(new Point(1, 3));
pntCs.add(new Point(2, 3));
pntCs.add(new Point(2, 1));
pntCs.add(new Point(3, 0));
pntCs.add(new Point(3, 7));
pntCs.add(new Point(4, 7));
pntCs.add(new Point(4, -4));
pntCs.add(new Point(0, -7));
pntCs.add(new Point(-1, -7));
pntCs.add(new Point(-1, -6));
pntCs.add(new Point(-2, -6));
pntCs.add(new Point(-2, -8));
pntCs.add(new Point(0, -8));
pntCs.add(new Point(5, -4));
pntCs.add(new Point(5, 7));
pntCs.add(new Point(4, 8));
pntCs.add(new Point(3, 8));
pntCs.add(new Point(2, 7));
pntCs.add(new Point(2, 4));
pntCs.add(new Point(-5, 4));
pntCs.add(new Point(-5, 5));
pntCs.add(new Point(-6, 5));
pntCs.add(new Point(-6, 1));
pntCs.add(new Point(-5, 1));
pntCs.add(new Point(-5, -4));
pntCs.add(new Point(-3, -6));
assignPolarPoints(pntCs);
setColor(Color.GRAY);
//put pack display in correct location
setCenter(new Point(x, y - TargetSpace.TS_HEIGHT/4));
setOrientation(270);
setRadius(12);
}
public void draw(Graphics g)
{
super.draw(g);
g.fillPolygon(getXcoords(), getYcoords(), dDegrees.length);
}
}
package lec08.pmnehls.finalproject.game.model;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
import java.util.ArrayList;
import java.util.Random;
import lec08.pmnehls.finalproject.controller.Game;
public abstract class Sprite implements Movable {
//the center-point of this sprite
private Point pntCenter;
//this causes movement; change in x and change in y
private double dDeltaX, dDeltaY;
//every sprite needs to know about the size of the gaming environ
private Dimension dim; //dim of the gaming environment
//the radius of circumscibing circle
private int nRadius;
//is this DEBRIS, FRIEND, FOE, OR FLOATER
//private byte yFriend;
//degrees (where the sprite is pointing out of 360)
private int nOrientation;
private int nExpiry; //natural mortality (short-living objects)
//the color of this sprite
private Color col;
//radial coordinates
//this game uses radial coordinates to render sprites
public double[] dLengths;
public double[] dDegrees;
//for drawing alternative
//public double[] dLengthAlts;
//public double[] dDegreeAlts;
//fade value for fading in and out
private int nFade;
//these are used to draw the polygon. You don't usually need to interface with these
private Point[] pntCoords; //an array of points used to draw polygon
private int[] nXCoords;
private int[] nYCoords;
public void move() {
Point pnt = getCenter();
double dX = pnt.x + getDeltaX();
double dY = pnt.y + getDeltaY();
//this just keeps the sprite inside the bounds of the frame
if (pnt.x > getDim().width) {
setCenter(new Point(1, pnt.y));
} else if (pnt.x < 0) {
setCenter(new Point(getDim().width - 1, pnt.y));
} else if (pnt.y > getDim().height) {
setCenter(new Point(pnt.x, 1));
} else if (pnt.y < 0) {
setCenter(new Point(pnt.x, getDim().height - 1));
} else {
setCenter(new Point((int) dX, (int) dY));
}
}
public Sprite() {
//you can override this and many more in the subclasses
setDim(Game.DIM);
setColor(Color.WHITE);
setCenter(new Point(Game.R.nextInt(Game.DIM.width),
Game.R.nextInt(Game.DIM.height)));
}
public void setExpire(int n) {
nExpiry = n;
}
public double[] getLengths() {
return this.dLengths;
}
public void setLengths(double[] dLengths) {
this.dLengths = dLengths;
}
public double[] getDegrees() {
return this.dDegrees;
}
public void setDegrees(double[] dDegrees) {
this.dDegrees = dDegrees;
}
public Color getColor() {
return col;
}
public void setColor(Color col) {
this.col = col;
}
public int points() {
//default is zero
return 0;
}
public int getExpire() {
return nExpiry;
}
public boolean isExploding() {
return false;
}
public void fadeInOut() {
};
@Override
public int getOrientation() {
return nOrientation;
}
public void setOrientation(int n) {
nOrientation = n;
}
public void setDeltaX(double dSet) {
dDeltaX = dSet;
}
public void setDeltaY(double dSet) {
dDeltaY = dSet;
}
public double getDeltaY() {
return dDeltaY;
}
public double getDeltaX() {
return dDeltaX;
}
public int getRadius() {
return nRadius;
}
public void setRadius(int n) {
nRadius = n;
}
public Dimension getDim() {
return dim;
}
public void setDim(Dimension dim) {
this.dim = dim;
}
public Point getCenter() {
return pntCenter;
}
public void setCenter(Point pntParam) {
pntCenter = pntParam;
}
public void setYcoord(int nValue, int nIndex) {
nYCoords[nIndex] = nValue;
}
public void setXcoord(int nValue, int nIndex) {
nXCoords[nIndex] = nValue;
}
public int getYcoord( int nIndex) {
return nYCoords[nIndex];// = nValue;
}
public int getXcoord( int nIndex) {
return nXCoords[nIndex];// = nValue;
}
public int[] getXcoords() {
return nXCoords;
}
public int[] getYcoords() {
return nYCoords;
}
public void setXcoords( int[] nCoords) {
nXCoords = nCoords;
}
public void setYcoords(int[] nCoords) {
nYCoords =nCoords;
}
protected double hypot(double dX, double dY) {
return Math.sqrt(Math.pow(dX, 2) + Math.pow(dY, 2));
}
//utility function to convert from cartesian to polar
//since it's much easier to describe a sprite as a list of cartesean points
//sprites (except Asteroid) should use the cartesean technique to describe the coordinates
//see Falcon or Bullet constructor for examples
protected double[] convertToPolarDegs(ArrayList<Point> pntPoints) {
//ArrayList<Tuple<Double,Double>> dblCoords = new ArrayList<Tuple<Double,Double>>();
double[] dDegs = new double[pntPoints.size()];
int nC = 0;
for (Point pnt : pntPoints) {
dDegs[nC++]=(Math.toDegrees(Math.atan2(pnt.y, pnt.x))) * Math.PI / 180 ;
}
return dDegs;
}
//utility function to convert to polar
protected double[] convertToPolarLens(ArrayList<Point> pntPoints) {
double[] dLens = new double[pntPoints.size()];
//determine the largest hypotenuse
double dL = 0;
for (Point pnt : pntPoints)
if (hypot(pnt.x, pnt.y) > dL)
dL = hypot(pnt.x, pnt.y);
int nC = 0;
for (Point pnt : pntPoints) {
if (pnt.x == 0 && pnt.y > 0) {
dLens[nC] = hypot(pnt.x, pnt.y) / dL;
} else if (pnt.x < 0 && pnt.y > 0) {
dLens[nC] = hypot(pnt.x, pnt.y) / dL;
} else {
dLens[nC] = hypot(pnt.x, pnt.y) / dL;
}
nC++;
}
// holds <thetas, lens>
return dLens;
}
protected void assignPolarPoints(ArrayList<Point> pntCs) {
setDegrees(convertToPolarDegs(pntCs));
setLengths(convertToPolarLens(pntCs));
}
public void draw(Graphics g) {
nXCoords = new int[dDegrees.length];
nYCoords = new int[dDegrees.length];
//need this as well
pntCoords = new Point[dDegrees.length];
for (int nC = 0; nC < dDegrees.length; nC++) {
nXCoords[nC] = (int) (getCenter().x + getRadius()
* dLengths[nC]
* Math.sin(Math.toRadians(getOrientation()) + dDegrees[nC]));
nYCoords[nC] = (int) (getCenter().y - getRadius()
* dLengths[nC]
* Math.cos(Math.toRadians(getOrientation()) + dDegrees[nC]));
//need this line of code to create the points which we will need for debris
pntCoords[nC] = new Point(nXCoords[nC], nYCoords[nC]);
}
g.setColor(getColor());
g.drawPolygon(getXcoords(), getYcoords(), dDegrees.length);
}
public Point[] getObjectPoints() {
return pntCoords;
}
public void setObjectPoints(Point[] pntPs) {
pntCoords = pntPs;
}
public void setObjectPoint(Point pnt, int nIndex) {
pntCoords[nIndex] = pnt;
}
public void expire() {
}
public int getFadeValue() {
return nFade;
}
public void setFadeValue(int n) {
nFade = n;
}
@Override
public void setRespawn(boolean bRespawn)
{
}
@Override
public boolean getRespawn()
{
return false;
}
}
package lec08.pmnehls.finalproject.game.model;
import java.awt.*;
/**
* Created by pmnehls on 11/19/14.
*
* Target Spaces play a key role in this game. The grid is composed of 28x36 target spaces. The long equations below determine
* which square is a wall, which is a dot, and which is empty. passing in an x,y value can tell a ghost or pacman what is in any
* given square, telling them if they need to stop, turn, or if they are eating a dot
*/
public class TargetSpace extends Sprite
{
private boolean isWall;
private boolean isDot;
private boolean isEmpty;
private boolean isEnergizer;
private boolean isGhostBox;
private boolean isReachable;
public static final int TS_HEIGHT= 16;
public static final int TS_WIDTH = 16;
private Sprite inside;
private Point pCenter;
private int nX;
private int nY;
public TargetSpace(int x, int y)
{
nX = x;
nY = y;
if((x == 2 && y == 7) || (x == 2 && y == 27) || (x == 27 && y == 7) || (x == 27 && y == 27))
{
isEnergizer = true;
isReachable = true;
this.inside = new Energizer(x, y);
}
else if (((y == 5 || y == 24) && (x != 1 && x != 14 && x!= 15 && x != 28)) || ((y == 9 || y == 33) && (x != 1 && x != 28))
|| ((y == 12 || y == 30) && ((x != 1 && x != 8 && x != 9 && x != 14 && x != 15 && x != 20 && x != 21 && x != 28)))
|| (y == 27 && ((x != 1 && x != 5 && x != 6 && x != 14 && x != 15 && x != 23 && x != 24 && x != 28)))
|| ((y == 6 || y == 8 || y == 25 || y == 26) && (x == 2 || x == 7 || x == 13 || x == 16 || x == 22 || x == 27 ))
|| (y == 7 && (x == 7 || x == 13 || x == 16 || x == 22))
|| ((y == 10 || y == 11) && (x == 2 || x == 7 || x == 10 || x == 19 || x == 22 || x == 27 ))
|| (y > 12 && y < 24) && (x == 7 || x == 22)
|| (y == 28 || y == 29) && (x == 4 || x == 7 || x == 10 || x == 19 || x == 22 || x == 25)
|| (y == 31 || y == 32) && (x == 2 || x == 13 || x == 16 || x == 27))
{
this.isDot = true;
this.isReachable = true;
this.inside = new Dot(x, y);
}
else if (((y == 13 || y == 14) && (x == 13 || x == 16)) || ((y == 15 || y == 21) && ( x > 9 && x < 20))
|| ((y == 16 || y == 17 || y == 18 || y == 19 || y == 20 || y == 21 || y == 23 || y == 24) && (x == 10 || x == 19))
|| (y == 18 && (x != 7 && x != 22 && (x < 11 || x > 18))) || (y == 27 && (x == 14 || x == 15))
|| (y == 22 && (x == 10 || x == 19)))
{
isEmpty = true;
isReachable = true;
}
else if(y == 1 || y == 2 || y == 3 || y == 35 || y == 36 || (y == 7 && ( x == 4 || x == 5 || x == 9 || x == 10 || x == 11
|| x == 18 || x == 19 || x == 20 || x == 24 || x == 25 )) || ((y == 14 || y == 15 || y == 16 || y == 20
|| y == 21 || y == 22) && ( x < 6 || x > 23)))
{
isEmpty = true;
}
else if ((y > 15 && y < 21 ) && (x > 10 && x < 19 ))
{
if (y == 16 || y == 20)
{
isGhostBox = true;
isWall = true;
}
else if (x == 11 || x == 18)
{
isGhostBox = true;
isWall = true;
}
}
else
{
isWall = true;
this.inside = new Wall(x ,y );
}
pCenter = new Point(TS_HEIGHT * (x-1) + TS_HEIGHT/2, TS_WIDTH * (y-1) + TS_WIDTH/2);
setCenter(new Point(pCenter));
}
public boolean getIsWall()
{
return isWall;
}
public boolean getIsDot()
{
return isDot;
}
public void setIsDot(boolean isDot)
{
this.isDot = isDot;
}
public boolean getIsEmpty()
{
return isEmpty;
}
public boolean getIsEnergizer()
{
return isEnergizer;
}
public void setIsEnergizer(boolean isEnergizer)
{
this.isEnergizer = isEnergizer;
}
public boolean getIsGhostBox()
{
return isGhostBox;
}
public boolean getIsReachable()
{
return isReachable;
}
public Movable getInside()
{
return inside;
}
public Point getTargetCenter()
{
return pCenter;
}
public int getSpaceX()
{
return nX;
}
public void setSpaceX(int x)
{
this.nX = x;
}
public int getSpaceY()
{
return nY;
}
public void setSpaceY(int y)
{
this.nY = y;
}
public Point getSpacePoint()
{
return new Point(nX, nY);
}
public Point getSpaceCenterCoord()
{
return pCenter;
}
@Override
public void setRespawn(boolean bRespawn)
{
}
}
package lec08.pmnehls.finalproject.game.model;
import java.awt.*;
import java.util.ArrayList;
/**
* Created by pmnehls on 11/19/14.
*/
public class Wall extends Sprite
{
public Wall(int x, int y)
{
super();
ArrayList<Point> pntCs = new ArrayList<Point>();
//simple square wall
pntCs.add(new Point(1, 1));
pntCs.add(new Point(1, -1));
pntCs.add(new Point(-1, -1));
pntCs.add(new Point(-1, 1));
assignPolarPoints(pntCs);
setColor(new Color(0,0,180));
setCenter(new Point(TargetSpace.TS_WIDTH * x - TargetSpace.TS_WIDTH/2,
TargetSpace.TS_HEIGHT* y - TargetSpace.TS_HEIGHT/2));
setRadius(6);
}
@Override
public void draw(Graphics g) {
super.draw(g);
g.fillPolygon(getXcoords(), getYcoords(), dDegrees.length);
}
}
package lec08.pmnehls.finalproject.game.view;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class GameFrame extends JFrame {
private JPanel contentPane;
private BorderLayout borderLayout1 = new BorderLayout();
public GameFrame() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
initialize();
} catch (Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void initialize() throws Exception {
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(borderLayout1);
}
@Override
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
}
package lec08.pmnehls.finalproject.game.view;
import java.awt.*;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.swing.JFrame;
import lec08.pmnehls.finalproject.controller.Game;
import lec08.pmnehls.finalproject.game.model.CommandCenter;
import lec08.pmnehls.finalproject.game.model.Movable;
import lec08.pmnehls.finalproject.game.model.TargetSpace;
import lec08.pmnehls.finalproject.sounds.Sound;
public class GamePanel extends Panel {
// ==============================================================
// FIELDS
// ==============================================================
// The following "off" vars are used for the off-screen double-bufferred image.
private Dimension dimOff;
private Image imgOff;
private Graphics grpOff;
private GameFrame gmf;
private Font fnt = new Font("Joystix", Font.PLAIN, 18);
private Font fntBig = new Font("Joystix", Font.BOLD, 64);
private Font fntlogo = new Font("SansSerif", Font.PLAIN, 4);
private FontMetrics fmt;
private int nFontWidth;
private int nFontHeight;
private String strDisplay = "";
private static final String strFile = System.getProperty("user.dir") + "/src/lec08/pmnehls/finalproject/game/model/Joystix.TTF";
public Font joystix = initJoystixFont();
// ==============================================================
// CONSTRUCTOR
// ==============================================================
public GamePanel(Dimension dim){
initJoystixFont();
gmf = new GameFrame();
gmf.getContentPane().add(this);
gmf.pack();
initView();
gmf.setSize(dim);
gmf.setTitle("PAC-MAN");
gmf.setResizable(false);
gmf.setVisible(true);
this.setFocusable(true);
}
// ==============================================================
// METHODS
// ==============================================================
private void drawScore(Graphics g) {
g.setColor(Color.white);
g.setFont(fnt);
if (CommandCenter.getScore() != 0) {
g.drawString("" + CommandCenter.getScore(), nFontWidth, nFontHeight);
} else {
g.drawString("00", nFontWidth, nFontHeight);
}
}
private void drawLevel(Graphics g)
{
g.setColor(Color.WHITE);
g.setFont(fnt);
if(CommandCenter.getLevel() != 0)
{
g.drawString("Level " + CommandCenter.getLevel(), TargetSpace.TS_WIDTH * 22, TargetSpace.TS_HEIGHT * 35);
}
}
public void drawLogo(Graphics g)
{
g.setColor(Color.YELLOW);
g.setFont(fntBig);
if(!CommandCenter.isPlaying())
{
g.drawString("PAC-MAN", 62, 180);
}
}
@SuppressWarnings("unchecked")
public void update(Graphics g) {
if (grpOff == null || Game.DIM.width != dimOff.width
|| Game.DIM.height != dimOff.height) {
dimOff = Game.DIM;
imgOff = createImage(Game.DIM.width, Game.DIM.height);
grpOff = imgOff.getGraphics();
}
// Fill in background with black.
grpOff.setColor(Color.black);
grpOff.fillRect(0, 0, Game.DIM.width, Game.DIM.height);
drawLogo(grpOff);
drawScore(grpOff);
drawLevel(grpOff);
if (!CommandCenter.isPlaying()) {
displayTextOnScreen();
} else if (CommandCenter.isPaused()) {
strDisplay = "Game Paused";
grpOff.drawString(strDisplay,
(Game.DIM.width - fmt.stringWidth(strDisplay)) / 2, Game.DIM.height / 4);
}
//playing and not paused!
else {
//draw them in decreasing level of importance
//friends will be on top layer and debris on the bottom
iterateMovables(grpOff,
CommandCenter.movLives,
CommandCenter.movDots,
CommandCenter.movEnergizers,
CommandCenter.movFoes,
CommandCenter.movDebris,
CommandCenter.movProton,
CommandCenter.movPacman,
CommandCenter.movFriends);
//drawNumberShipsLeft(grpOff);
if (CommandCenter.isGameOver()) {
CommandCenter.setPlaying(false);
//bPlaying = false;
}
}
//draw the double-Buffered Image to the graphics context of the panel
g.drawImage(imgOff, 0, 0, this);
}
//for each movable array, process it.
private void iterateMovables(Graphics g, CopyOnWriteArrayList<Movable>...movMovz)
{
for (CopyOnWriteArrayList<Movable> movMovs : movMovz)
{
for (Movable mov : movMovs)
{
mov.move();
mov.draw(g);
mov.fadeInOut();
mov.expire();
}
}
}
private void initView() {
Graphics g = getGraphics(); // get the graphics context for the panel
g.setFont(fnt); // take care of some simple font stuff
fmt = g.getFontMetrics();
nFontWidth = fmt.getMaxAdvance();
nFontHeight = fmt.getHeight();
g.setFont(fntBig); // set font info
}
// This method draws some text to the middle of the screen before/after a game
private void displayTextOnScreen() {
strDisplay = "use the arrow keys to turn Pac-Man";
grpOff.drawString(strDisplay,
(Game.DIM.width - fmt.stringWidth(strDisplay)) / 2, Game.DIM.height / 4
+ nFontHeight + 100);
strDisplay = "'S' to Start";
grpOff.drawString(strDisplay,
(Game.DIM.width - fmt.stringWidth(strDisplay)) / 2, Game.DIM.height / 4
+ nFontHeight + 160);
strDisplay = "'P' to Pause";
grpOff.drawString(strDisplay,
(Game.DIM.width - fmt.stringWidth(strDisplay)) / 2, Game.DIM.height / 4
+ nFontHeight + 200);
strDisplay = "'Q' to Quit";
grpOff.drawString(strDisplay,
(Game.DIM.width - fmt.stringWidth(strDisplay)) / 2, Game.DIM.height / 4
+ nFontHeight + 240);
strDisplay = "------BONUS FEATURES------";
grpOff.drawString(strDisplay,
(Game.DIM.width - fmt.stringWidth(strDisplay)) / 2, Game.DIM.height / 4
+ nFontHeight + 280);
strDisplay = "Add more ghosts: 'O' for Ouija";
grpOff.drawString(strDisplay,
(Game.DIM.width - fmt.stringWidth(strDisplay)) / 2, Game.DIM.height / 4
+ nFontHeight + 320);
strDisplay = "GhostBuster Mode: press 'G'";
grpOff.drawString(strDisplay,
(Game.DIM.width - fmt.stringWidth(strDisplay)) / 2, Game.DIM.height / 4
+ nFontHeight + 360);
}
public GameFrame getFrm() {return this.gmf;}
public void setFrm(GameFrame frm) {this.gmf = frm;}
public Font initJoystixFont()
{
try
{
Font fntTemp = Font.createFont(Font.TRUETYPE_FONT,new File(strFile));
return fntTemp.deriveFont(18f);
} catch (FontFormatException e)
{
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
}
return null;
}
}
\ No newline at end of file
package lec08.pmnehls.finalproject.sounds;
import java.io.IOException;
import java.net.URL;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
public class Sound {
//for individual wav sounds (not looped)
//http://stackoverflow.com/questions/26305/how-can-i-play-sound-in-java
public static synchronized void playSound(final String strPath) {
new Thread(new Runnable() {
public void run() {
try {
Clip clp = AudioSystem.getClip();
AudioInputStream aisStream =
AudioSystem.getAudioInputStream(Sound.class.getResourceAsStream(strPath));
clp.open(aisStream);
clp.start();
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
}).start();
}
//for looping wav clips
//http://stackoverflow.com/questions/4875080/music-loop-in-java
public static Clip clipForLoopFactory(String strPath){
Clip clp = null;
// this line caused the original exceptions
try {
AudioInputStream aisStream =
AudioSystem.getAudioInputStream(Sound.class.getResourceAsStream(strPath));
clp = AudioSystem.getClip();
clp.open( aisStream );
} catch (UnsupportedAudioFileException exp) {
exp.printStackTrace();
} catch (IOException exp) {
exp.printStackTrace();
} catch (LineUnavailableException exp) {
exp.printStackTrace();
//the next three lines were added to catch all exceptions generated
}catch(Exception exp){
System.out.println("error");
}
return clp;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment