actors/Actor.java
package pacman.actors;
import java.awt.Color;
import java.awt.Graphics2D;
import pacman.ai.AIManager;
import pacman.game.GameObject;
import pacman.map.Map;
import pacman.state.StateGame;
import pacman.util.Direction;
import pacman.util.RequestedDirectionBuffer;
/**
* An actor is any object that has a degree of autonomy or intelligent input
* (Human / AIManager) dictating the object's behavior ingame Subclass of
* GameObject
*
* @author Ramsey Kant
*/
public abstract class Actor extends GameObject {
/** Whether the actor is alive or not. */
protected boolean f012;
/** The x-position on the map where the actor gets spawned */
protected int f112;
/** The y-position on the map where the actor gets spawned */
protected int f212;
/** The direction in which the actor is currently oriented. */
protected Direction f312;
/** The actor's direction requested by user input. Uses a buffer to
* remember requests over some steps to simplify timing for the user.
* Computer-controlled actors (ghosts) ignore this. */
protected RequestedDirectionBuffer f412;
/** The size of the direction request buffer. */
private final static int f512 = 6;
/** The current orientation angle of the actor. Ignored by actors that do
* not have to orient (aka ghosts). */
protected int f612;
/** The x-position delta to the current map cell, caused by movement
* in pixels. */
protected float f712;
/** The y-position delta to the current map cell, caused by movement
* in pixels. */
protected float f812;
/** The movement speed of the actor */
protected float f912;
/**
* Actor Class Constructor
*
* @param v0
* Object type that is an actor
* @param v1
* Base color of the actor
* @param v2
* Reference to the global map object
* @param v3
* X coordinate to spawn the actor at
* @param v4
* Y coordinate to spawn the actor at
* @see GameObject
*/
public Actor(int v0, Color v1, Map v2, int v3, int v4) {
super(v0, v1, v2, v3, v4);
f012 = false;
// Movement
f112 = v3;
f212 = v4;
f312 = Direction.f41;
f412 = new RequestedDirectionBuffer(f512);
f612 = 0;
f712 = 0;
f812 = 0;
f912 = (float) (5d * f1916.f55);
}
// Getters and Setters
/**
* Returns the original X coordinate the Actor was given in the constructor
*
* @return the X coordinate of the spawn point
*/
public int m012() {
return f112;
}
/**
* Returns the original Y coordinate the Actor was given in the constructor
*
* @return the Y coordinate of the spawn point
*/
public int m112() {
return f212;
}
/**
* Set the death status of the actor. Used by StateGame and AIManager to
* determine if the player / ghost has died
*/
public void m212(boolean v5) {
f012 = v5;
}
/**
* Get dead status
*
* @return True if dead, false if alive
* @see Actor#m212(boolean)
*/
public boolean m312() {
return f012;
}
/**
* Speed is the number of pixels an actor moves across the screen in a given
* cycle. A full position change is the number of pixels defined in
* Map.CELL_SIZE
*
* @param v6
* New Speed
*/
public void m412(float v6) {
f912 = v6;
}
/**
* Get the current speed of the actor
*
* @return Current speed
* @see Actor#m412(float)
*/
public float m512() {
return f912;
}
/**
* Set the direction actor should travel in. Player uses this to determine
* the direction to "auto-move" to Ghosts ignore what is set by this
* function because their direction is determined within act() based on the
* path
*/
public void m612(Direction v7) {
f412.m114(v7);
}
// Public Methods
/**
* Attempt to move the actor to the given x,y location. This method will
* check if a coordinate is valid with the Map class method canMove(). It is
* not necessary to call canMove() before this function
*
* @param v8
* A x coordinate to move to
* @param v9
* A y coordinate to move to
* @return True if the move succeeded. False if otherwise
* @see Map#m195(Actor, int, int)
*/
public boolean m712(int v8, int v9) {
final boolean v10;
v10 = f1916.m195(this, v8, v9);
if (v10) {
f1716 = v8;
f1816 = v9;
}
return v10;
}
/**
* The primary logic function for actors. StateGame calls this for players
* directly in logic() and the AIManager calls this for ghosts in process()
*
* @see GameObject#m516()
* @see StateGame#m28()
* @see AIManager#m20()
*/
@Override
public abstract void m516();
/**
*
* @see GameObject#m616(java.awt.Graphics2D)
*/
@Override
public abstract void m616(Graphics2D v11);
}
actors/Ghost.java
package pacman.actors;
import java.awt.Color;
import java.awt.Graphics2D;
import pacman.ai.AIManager;
import pacman.game.GameObject;
import pacman.map.Map;
import pacman.map.Path;
import pacman.util.Direction;
/**
* The Ghost class is the primary enemy in Pacman. Intelligent decisions of
* ghosts are made by the AIManager class Ghost is a subclass of Actor
*
* @author Ramsey Kant
*/
public class Ghost extends Actor {
// Movement
private Path f018;
private int f118;
private boolean f218;
// State
private boolean f318;
private boolean f418;
private boolean f518;
/**
* Class constructor
*
* @param v0
* Color of the ghost's 'body'
* @param v1
* Reference to the map
* @param v2
* X coordinate to spawn at
* @param v3
* Y coordinate to spawn at
* @param v4
* Set trapped status
*/
public Ghost(Color v0, Map v1, int v2, int v3, boolean v4) {
super(GameObject.f416, v0, v1, v2, v3);
f218 = true;
f418 = false;
f318 = v4;
f518 = false;
}
/**
* Return the fear status of the ghost
*
* @return True if fearful
*/
public boolean m018() {
return f418;
}
/**
* Set fear status. AIManager interperates this setting for behavior
*
* @param v5
* Fear status, true if fearful
*/
public void m118(boolean v5) {
f418 = v5;
}
/**
* Get the current trapped status
*
* @return True if the ghost is currently in the spawn-jail
*/
public boolean m218() {
return f318;
}
/**
* Set the current trapped status
*
* @param v6
* Trye uf the ghost is in the spawn-jail
*/
public void m318(boolean v6) {
f318 = v6;
}
/**
* Flag that is set to true when the path reaches the last possible step
*
* @return True if the AIManager needs to assign a new path
*/
public boolean m418() {
return f218;
}
/**
* Update the Path object for the ghost to follow'
*
* @param v7
* Path object generated in process() by the AIManager
* @see AIManager#m20()
*/
public void m518(Path v7) {
f118 = 1;
f018 = v7;
f218 = false;
}
/**
* Direct's the paint() function to draw the current path of the ghost on
* the map
*
* @param v8
* If true, debug is on and the path will be drawn
* @see AIManager#setDebugEnabled
*/
public void m618(boolean v8) {
f518 = v8;
}
/**
* Run a think cycle for the AI. Major decisions are made by the AIManager
* (pathing), this just determines movement and screen draw deltas
*
* @see Actor#m516()
*/
@Override
public void m516() {
// Move to the next step
if (f018 != null && f118 < f018.m03()) {
// Figure out the direction
if ((f018.m33(f118) - f1816) < 0) {
f312 = Direction.f01;
} else if ((f018.m33(f118) - f1816) > 0) {
f312 = Direction.f21;
} else if ((f018.m23(f118) - f1716) > 0) {
f312 = Direction.f11;
} else {
f312 = Direction.f31;
}
// Based on the direction, move the screen delta's and the X,Y
// coordinates if the # of pixels for the cell have been surpassed
switch (f312) {
case f01:
f712 = 0;
f812 = f812 - f912;
// If the movement delta has surpassed the number of pixels for
// the cell, set him to the map cell he has reached by his movement.
if (Math.abs(f812) >= f1916.f25) {
f812 = 0;
m712(f1716, f1816 - 1);
f118++;
}
break;
case f11:
f712 = f712 + f912;
f812 = 0;
if (Math.abs(f712) >= f1916.f25) {
f712 = 0;
m712(f1716 + 1, f1816);
f118++;
}
break;
case f21:
f712 = 0;
f812 = f812 + f912;
if (Math.abs(f812) >= f1916.f25) {
f812 = 0;
m712(f1716, f1816 + 1);
f118++;
}
break;
case f31:
f712 = f712 - f912;
f812 = 0;
if (Math.abs(f712) >= f1916.f25) {
f712 = 0;
m712(f1716 - 1, f1816);
f118++;
}
break;
case f51:
case f41:
// do not move
}
} else {
f218 = true;
}
}
/**
* Draw the ghost
*
* @see GameObject#m616(Graphics2D)
*/
@Override
public void m616(Graphics2D v9) {
final int v10;
v10 = (int) ((f1916.f25 * f1716) + f712);
final int v11;
v11 = (int) ((f1916.f25 * f1816) + f812);
v9.setColor(f1616);
// Body
if (f418) {
v9.setColor(Color.WHITE);
}
v9.fillArc(v10, v11, f1916.f25, f1916.f25, 0, 360);
v9.fillRect((int) ((f1916.f25 * f1716) + f712), (int) ((f1916.f25 * f1816)
+ (f1916.f25 / 2) + f812), f1916.f25, f1916.f25 / 2);
// Eyes
if (f418) {
v9.setColor(Color.BLACK);
} else {
v9.setColor(Color.WHITE);
}
v9.fillOval((int) ((f1916.f25 * f1716) + 4 + f712),
(int) ((f1916.f25 * f1816) + 3 + f812), 8, 10);
v9.fillOval((int) ((f1916.f25 * f1716) + 12 + f712),
(int) ((f1916.f25 * f1816) + 3 + f812), 8, 10);
// Eyeballs
v9.setColor(Color.BLUE);
v9.fillOval((int) ((f1916.f25 * f1716) + 7 + f712),
(int) ((f1916.f25 * f1816) + 6 + f812), 4, 4);
v9.fillOval((int) ((f1916.f25 * f1716) + 13 + f712),
(int) ((f1916.f25 * f1816) + 6 + f812), 4, 4);
// Debug draw path
if (f518 && f018 != null) {
int v12;
for (v12
= 0; v12 < f018.m03(); v12++) {
final Path.Step v13;
v13 = f018.m13(v12);
v9.setColor(f1616);
v9.drawLine(f1916.f25 * v13.m03(), f1916.f25 * v13.m13(),
(f1916.f25 * v13.m03()) + f1916.f25, (f1916.f25 * v13.m13())
+ f1916.f25);
}
}
}
}
actors/Player.java
package pacman.actors;
import java.awt.Color;
import java.awt.Graphics2D;
import pacman.game.GameObject;
import pacman.game.Item;
import pacman.map.Map;
import pacman.util.Direction;
/**
* Player (pacman) is the object controlled by the human playing the game Player
* is a subclass of Actor
*
* @author Ramsey Kant
*/
public class Player extends Actor {
// State
private int f013; // Current score - Only valid for the current life /
// level. StateGame will pull this on death or on
// level change
private boolean f113; // Powered up
private long f213;
/**
* Class Constructor for Player
*
* @param v0
* Reference to the map object
* @param v1
* X coordiante to spawn the player at
* @param v2
* Y coordinate to spawn the player at
*/
public Player(Map v0, int v1, int v2) {
super(f316, Color.yellow, v0, v1, v2);
// State
f013 = 0;
f113 = false;
f213 = 0;
}
// Getters and Setters
/**
* Increment score by amount. The is the current level score, not the entire
* session score This function is typically called inside an Item's use()
* function when the player picks up an item like a dot
*
* @param v3
* Amount to increment
*/
public void m013(int v3) {
f013 += v3;
}
/**
* Get the current level score of the player
*
* @return the score
*/
public int m113() {
return f013;
}
/**
* Returns the isPowered flag which determines whether or not the player is
* powered up and invicible to ghosts
*
* @return True if the player is powered up
*/
public boolean m213() {
return f113;
}
/**
* Set powered up state and start the expirtation time for when the powerup
* wears off
*
* @param v4
* True if powered up, false if otherwise
* @see Player#m213()
*/
public void m313(boolean v4) {
f113 = v4;
// If powered up, start the timer and increase speed temporarily
if (f113) {
f213 = System.currentTimeMillis() + 10000;
}
}
/**
* Player act() method This should evaluate if there is: - a collission with
* a ghost and how to handle that interaction - a dot or cherry being eaten
* (call use() on the item) - a next movement
*/
@Override
public void m516() {
final Actor v5;
v5 = f1916.m135(f1716, f1816, true);
if (v5 != null && v5.m016() == GameObject.f416) {
// Notify the State of the loss if pacman isn't powered up
if (!f113) {
m212(true);
return;
} else {
v5.m212(true);
}
}
// Check for powerup expire
if (System.currentTimeMillis() > f213) {
m313(false);
}
boolean v6;
v6 = false;
final Item v7;
v7 = f1916.m105(f1716, f1816);
if (v7 != null) {
v6 = v7.m37(this);
}
// Update the item's state in the map (remove if itemDestroy is true)
if (v6) {
f1916.m155(f1716, f1816);
}
final Direction v8;
v8 = f412.m014();
if (v8 != Direction.f41) {
if (f1916.m205(this, v8)) {
f312 = v8;
}
}
// Based on the direction, increment the movement delta and set the
// appropriate orientation
// The delta's represent the screen position (in pixels) since the last
// official change in position on the grid
// When a delta in a certain direction passes the CELL_SIZE, the object
// can change position in the map grid. This makes for smooth
// transitions between tiles
switch (f312) {
case f01:
// Move in the direction only if the next map cell in this
// direction is reachable (not occupied by a wall)
if (f1916.m195(this, f1716, f1816 - 1)) {
f712 = 0;
f812 = f812 - f912;
// If the movement delta has surpassed the number of pixels for
// the cell, set him to the map cell he has reached by his movement
if (Math.abs(f812) >= f1916.f25) {
f812 = 0;
m712(f1716, f1816 - 1);
}
}
f612 = 90;
break;
case f11:
if (f1916.m195(this, f1716 + 1, f1816)) {
f712 = f712 + f912;
f812 = 0;
if (Math.abs(f712) >= f1916.f25) {
f712 = 0;
m712(f1716 + 1, f1816);
}
}
f612 = 0;
break;
case f21:
if (f1916.m195(this, f1716, f1816 + 1)) {
f712 = 0;
f812 = f812 + f912;
if (Math.abs(f812) >= f1916.f25) {
f812 = 0;
m712(f1716, f1816 + 1);
}
}
f612 = -90;
break;
case f31:
if (f1916.m195(this, f1716 - 1, f1816)) {
f712 = f712 - f912;
f812 = 0;
if (Math.abs(f712) >= f1916.f25) {
f712 = 0;
m712(f1716 - 1, f1816);
}
}
f612 = 180;
break;
case f51:
case f41:
// do not move
}
}
/**
* Draw & animate pacman
*
* @param v9
* The graphics context
* @see Actor#m516()
*/
@Override
public void m616(Graphics2D v9) {
final int v10;
v10 = (int) ((f1916.f25 * f1716) + f712);
final int v11;
v11 = (int) ((f1916.f25 * f1816) + f812);
v9.setColor(f1616);
// Animate Pacman's mouth
// When the player is half-way through a tile, close the flap. Open it
// back up when the flap clears a tile.
// This essentially creates an eating animation
if ((Math.abs(f712) >= f1916.f25 / 2) || Math.abs(f812) >= f1916.f25 / 2) {
v9.fillArc(v10, v11, f1916.f25, f1916.f25, 0 + f612, 360); // flap
// closed
} else {
v9.fillArc(v10, v11, f1916.f25, f1916.f25, 35 + f612, 270);
}
}
}
ai/AIManager.java
package pacman.ai;
import java.util.ArrayList;
import pacman.actors.Actor;
import pacman.actors.Ghost;
import pacman.actors.Player;
import pacman.game.GameObject;
import pacman.map.Map;
import pacman.map.Path;
import pacman.map.PathFinder;
/**
* Strategy management behind the AI (Ghost objects)
*
* @author Ramsey Kant
*/
public class AIManager {
// References
private Map f00;
private Player f10;
// Logic
private boolean f20;
private PathFinder f30;
private final ArrayList<Ghost> f40;
private long f50;
/**
* Class Constructor
*
* @param v0
* Reference to the map object being used by the game
* @param v1
* Reference to the player
* @param v2
* Set the debug flag allowing the AI manager to direct ghosts to
* exibit diagnostic behavior
*/
public AIManager(Map v0, Player v1, boolean v2) {
// Set vars
f40 = new ArrayList<Ghost>();
m10(v0, v1);
f50 = System.currentTimeMillis() + 10000;
f20 = v2;
}
// Getters and Setters
/**
* Direct ghosts to display diagnostic information
*
* @param v3
* If true, ghosts will enter debug mode
* @see Ghost#setDebugDrawPath
*/
public void m00(boolean v3) {
f20 = v3;
}
/**
* Set the global map and player references. Ghosts being tracked (in the
* 'ghosts' ArrayList) will be updated
*
* @param v4
* Reference to the map
* @param v5
* Reference to the player object
*/
public void m10(Map v4, Player v5) {
f40.clear();
f00 = v4;
f10 = v5;
f30 = new PathFinder(v4, 500, false);
final int v6;
v6 = f00.m25();
int v7;
for (v7
= 0; v7 < v6; v7++) {
final Actor v8;
v8 = f00.m115(v7);
if (v8.m016() == GameObject.f416) {
f40.add((Ghost) v8);
}
}
}
/**
* Run all logic required for AI operation; fear, ghost release, path
* updates. Ghost act() functions are called here
*/
public void m20() {
// Make sure the game is still running and there is a map
if (f00 == null) {
return;
}
boolean v9;
v9 = false;
if (f00.m125().m213()) {
v9 = true;
}
// Release the next ghost
if (System.currentTimeMillis() > f50) {
for (final Ghost v10 : f40) {
if (v10.m218()) {
v10.m318(false);
v10.m712(13, 11);
f50 = System.currentTimeMillis() + 8000;
break;
}
}
}
// Go through a list of all AI on the map
for (final Ghost v11 : f40) {
// If a ghost just died, send them to jail
if (v11.m312()) {
final int v12;
v12 = 11;
final int v13;
v13 = 13;
int v14;
v14 = 0;
while (!f00.m185(v12 + v14, v13)) {
v14++;
if (v14 > 4) {
break;
}
}
// Clear path and move to jail
v11.m518(null);
v11.m712(v12, v13);
v11.m318(true);
v11.m212(false);
}
// Any ghost not trapped is given the current fear status
if (!v11.m218()) {
// If fear switches from false to true for this ghost, abandon
// their current (and likely) chase path
if (!v11.m018() && v9) {
v11.m518(null);
}
v11.m118(v9);
} else {
v11.m118(false);
}
// Develop path for ghost
if (!v11.m218() && v11.m418()) {
int v15;
v15 = f10.m316();
int v16;
v16 = f10.m416();
// 45% chance of randomizing a destination, or if they are
// fearful
if (v9 || Math.random() < 0.45) {
v15 = (int) (Math.random() * f00.m05());
v16 = (int) (Math.random() * f00.m15());
}
final Path v17;
v17 = f30.m04(v11, v11.m316(), v11.m416(), v15, v16);
v11.m518(v17);
}
// Run an act()
v11.m516();
// If debug is enabled, force ghost to draw it's path
v11.m618(f20);
}
}
}
ai/AStarHeuristic.java
package pacman.ai;
import pacman.actors.Actor;
import pacman.map.Map;
/**
* A heuristic that uses the tile that is closest to the target as the next best
* tile.
*
* @author Kevin Glass
*/
public class AStarHeuristic {
/**
* Get the additional heuristic cost of the given tile. This controls the
* order in which tiles are searched while attempting to find a path to the
* target location. The lower the cost the more likely the tile will be
* searched.
*
* @param v0
* The map on which the path is being found
* @param v1
* The entity that is moving along the path
* @param v2
* The x coordinate of the tile being evaluated
* @param v3
* The y coordinate of the tile being evaluated
* @param v4
* The x coordinate of the target location
* @param v5
* Teh y coordinate of the target location
* @return The cost associated with the given tile
*/
public float m06(Map v0, Actor v1, int v2, int v3, int v4, int v5) {
final float v6;
v6 = v4 - v2;
final float v7;
v7 = v5 - v3;
final float v8;
v8 = (float) (Math.sqrt((v6 * v6) + (v7 * v7)));
return v8;
}
}
editor/EditorFrame.java
package pacman.editor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JSeparator;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import pacman.game.GameObject;
import pacman.state.State;
import pacman.state.StateEditor;
/**
* This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
* Builder, which is free for non-commercial use. If Jigloo is being used
* commercially (ie, by a corporation, company or business for any purpose
* whatever) then you should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details. Use of Jigloo implies
* acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
* PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
* ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class EditorFrame extends javax.swing.JFrame {
private static final long f011 = 1L;
private final StateEditor f111;
private JMenuItem f211;
private JTextArea f311;
private JTextField f411;
private JLabel f511;
private JLabel f611;
private JLabel f711;
private JButton f811;
private JButton f911;
private JTextField f1011;
private JButton f1111;
private JButton f1211;
private JComboBox f1311;
private JButton f1411;
private JComboBox f1511;
private JCheckBox f1611;
private JLabel f1711;
private JButton f1811;
private JLabel f1911;
private JMenuItem f2011;
private JSeparator f2111;
private JMenuItem f2211;
private JMenuItem f2311;
private JMenu f2411;
private JMenuBar f2511;
private JLabel f2611;
private JSeparator f2711;
private JButton f2811;
private JButton f2911;
private JButton f3011;
public EditorFrame(StateEditor v0) {
super();
f111 = v0;
m011();
}
private void m011() {
try {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
getContentPane().setLayout(null);
this.setTitle("Pacman Map Editor - Ramsey Kant");
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent v1) {
f111.m08().m720(State.f58);
}
});
{
f2511 = new JMenuBar();
setJMenuBar(f2511);
{
f2411 = new JMenu();
f2511.add(f2411);
f2411.setText("File");
{
f2311 = new JMenuItem();
f2411.add(f2311);
f2311.setText("Load");
}
{
f2211 = new JMenuItem();
f2411.add(f2211);
f2211.setText("Save");
}
{
f211 = new JMenuItem();
f2411.add(f211);
f211.setText("Save As..");
}
{
f2111 = new JSeparator();
f2411.add(f2111);
}
{
f2011 = new JMenuItem();
f2411.add(f2011);
f2011.setText("Exit");
}
}
}
{
f3011 = new JButton();
getContentPane().add(f3011);
f3011.setText("Wall");
f3011.setBounds(12, 218, 59, 23);
f3011.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent v2) {
f111.m02(GameObject.f616);
}
});
}
{
f2911 = new JButton();
getContentPane().add(f2911);
f2911.setText("Dot");
f2911.setBounds(12, 36, 59, 23);
f2911.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent v3) {
f111.m02(GameObject.f016);
}
});
}
{
f2811 = new JButton();
getContentPane().add(f2811);
f2811.setText("Pacman");
f2811.setBounds(136, 36, 110, 23);
f2811.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent v4) {
f111.m02(GameObject.f316);
}
});
}
{
f2711 = new JSeparator();
getContentPane().add(f2711);
f2711.setBounds(12, 301, 360, 10);
}
{
f2611 = new JLabel();
getContentPane().add(f2611);
f2611.setText("Placeable Objects");
f2611.setBounds(12, 12, 129, 16);
}
{
f1911 = new JLabel();
getContentPane().add(f1911);
f1911.setText("Wall Type");
f1911.setBounds(12, 196, 82, 16);
}
{
final ComboBoxModel v5;
v5 = new DefaultComboBoxModel(new String[] {
"Vertical", "Horizontal", "Top Left", "Top Right",
"Bottom Left", "Bottom Right", "Ghost Barrier" });
f1311 = new JComboBox();
getContentPane().add(f1311);
f1311.setModel(v5);
f1311.setBounds(12, 246, 153, 23);
f1311.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent v6) {
final String v7;
v7 = (String) f1311.getSelectedItem();
if (v7.equals("Vertical")) {
f111.m12(GameObject.f816);
} else if (v7.equals("Horizontal")) {
f111.m12(GameObject.f916);
} else if (v7.equals("Top Left")) {
f111.m12(GameObject.f1016);
} else if (v7.equals("Top Right")) {
f111.m12(GameObject.f1116);
} else if (v7.equals("Bottom Left")) {
f111.m12(GameObject.f1216);
} else if (v7.equals("Bottom Right")) {
f111.m12(GameObject.f1316);
} else if (v7.equals("Ghost Barrier")) {
f111.m12(GameObject.f1416);
} else {
f111.m12(GameObject.f916);
}
}
});
}
{
f1211 = new JButton();
getContentPane().add(f1211);
f1211.setText("Save");
f1211.setBounds(12, 317, 70, 23);
f1211.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent v8) {
f111.m72(f1011.getText());
}
});
}
{
f1111 = new JButton();
getContentPane().add(f1111);
f1111.setText("Load");
f1111.setBounds(87, 317, 68, 23);
f1111.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent v9) {
f111.m82(f1011.getText());
}
});
}
{
f1011 = new JTextField();
getContentPane().add(f1011);
f1011.setBounds(12, 345, 225, 23);
f1011.setText("test.map");
}
{
f911 = new JButton();
getContentPane().add(f911);
f911.setText("New");
f911.setBounds(160, 317, 71, 23);
f911.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent v10) {
f111.m62(28, 31);
}
});
}
{
f811 = new JButton();
getContentPane().add(f811);
f811.setText("Teleport");
f811.setBounds(237, 218, 110, 23);
f811.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent v11) {
f111.m02(GameObject.f716);
f111.m52(Integer.parseInt(f411.getText()),
Integer.parseInt(f311.getText()));
}
});
}
{
f711 = new JLabel();
getContentPane().add(f711);
f711.setText("Teleport Settings");
f711.setBounds(237, 196, 123, 16);
}
{
f611 = new JLabel();
getContentPane().add(f611);
f611.setText("Dest X:");
f611.setBounds(237, 249, 60, 16);
}
{
f511 = new JLabel();
getContentPane().add(f511);
f511.setText("Dest Y: ");
f511.setBounds(235, 279, 52, 16);
}
{
f411 = new JTextField();
getContentPane().add(f411);
f411.setText("13");
f411.setBounds(280, 246, 85, 23);
}
{
f311 = new JTextArea();
getContentPane().add(f311);
f311.setText("17");
f311.setBounds(280, 275, 82, 20);
}
{
f1811 = new JButton();
getContentPane().add(f1811);
f1811.setText("Powerup");
f1811.setBounds(12, 65, 102, 23);
f1811.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent v12) {
f111.m02(GameObject.f116);
}
});
}
{
f1711 = new JLabel();
getContentPane().add(f1711);
f1711.setText("Ghost Settings");
f1711.setBounds(272, 12, 76, 16);
}
{
f1611 = new JCheckBox();
getContentPane().add(f1611);
f1611.setText("Trapped");
f1611.setBounds(360, 10, 100, 20);
f1611.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent v13) {
f111.m32(!f111.m42());
System.out.println(f111.m42());
}
});
}
{
final ComboBoxModel v14;
v14 = new DefaultComboBoxModel(new String[] {
"Blinky", "Pinky", "Inky", "Clyde" });
f1511 = new JComboBox();
getContentPane().add(f1511);
f1511.setModel(v14);
f1511.setBounds(272, 65, 146, 23);
f1511.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent v15) {
final String v16;
v16 = (String) f1511.getSelectedItem();
f111.m22(v16);
}
});
}
{
f1411 = new JButton();
getContentPane().add(f1411);
f1411.setText("Add Ghost");
f1411.setBounds(272, 36, 146, 23);
f1411.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent v17) {
f111.m02(GameObject.f416);
}
});
}
pack();
this.setSize(451, 547);
} catch (final Exception v18) {
// add your error handling code here
v18.printStackTrace();
}
}
}
editor/EditorMarker.java
package pacman.editor;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import pacman.game.GameObject;
import pacman.map.Map;
import pacman.state.StateEditor;
/**
* The EditorMarker is used by the StateEditor for navigation and selecting
* tiles on the map EditorMarker is NOT tracked inside the Map EditorMarker is a
* subclass of GameObject
*
* @author Ramsey Kant
*/
public class EditorMarker extends GameObject {
/**
* Class constructor for EditorMarker
*
* @param v0
* Color of the marker
* @param v1
* Reference to the map object
* @param v2
* X coordinate to initially place the marker
* @param v3
* Y coordinate to initially place the marker
*/
public EditorMarker(Color v0, Map v1, int v2, int v3) {
super(GameObject.f516, v0, v1, v2, v3);
}
// Public Methods
/**
* Change tile is the EditorMarker's version of Actor's move() method.
* Called by keyPressed in StateEditor Moves the Marker on the screen
*
* @param v4
* Amount to change the current X coordinate by
* @param v5
* Amount to change the current Y coordinate by
* @see StateEditor#keyPressed(KeyEvent)
*/
public void m09(int v4, int v5) {
// Check bounds
if (f1716 + v4 < 0 || f1816 + v5 < 0 || f1716 + v4 >= f1916.m05()
|| f1816 + v5 >= f1916.m15()) {
return;
}
f1716 += v4;
f1816 += v5;
}
/**
* EditorMarker has a blank act() method
*
* @see GameObject#m516()
*/
@Override
public void m516() {
// do nothing
}
/**
* EditorMarker appears as a circle around the tile being edited. The color
* is set in the constructor
*
* @see GameObject#m616(Graphics2D)
*/
@Override
public void m616(Graphics2D v6) {
final int v7;
v7 = (f1916.f25 * f1716);
final int v8;
v8 = (f1916.f25 * f1816);
v6.setColor(f1616);
v6.drawOval(v7, v8, f1916.f25, f1916.f25);
}
}
game/Game.java
package pacman.game;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics2D;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferStrategy;
import pacman.state.State;
import pacman.state.StateEditor;
import pacman.state.StateGame;
import pacman.state.StateMenu;
import pacman.state.StateScoreboard;
/**
* The Game Supervisor. This class implements that core program logic, state
* management, and graphics.
*
* @author Ramsey Kant
*/
public class Game extends Canvas {
private static final long f020 = 1L;
// Debug vars
private boolean f120;
// Threading
private boolean f220;
// Graphics variables
private Frame f320;
public final int f420;
public final int f520;
private BufferStrategy f620;
// State
private int f720;
private State f820;
private boolean f920;
private int f1020;
private String f1120;
/**
* Class Constructor Set's up graphics and put's game logic into a startup
* state by calling init()
*
* @param v0
* Resolution X
* @param v1
* Resolution Y
* @see Game#m020()
*/
public Game(int v0, int v1) {
// Set resolution settings
f420 = v0;
f520 = v1;
// Init game
m020();
}
/**
* Startup functionality for the program called by the constructor
*/
private void m020() {
// Debug vars
f120 = false;
f1120 = "test.map";
f920 = false;
// Setup the game frame
f320 = new Frame("Pacman");
f320.setLayout(null);
setBounds(0, 0, f420, f520);
f320.add(this);
f320.setSize(f420, f520);
f320.setResizable(false);
f320.setVisible(true);
// Set the exit handler with an anonymous class
f320.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent v2) {
// Exit main thread
f220 = false;
}
});
// Setup double buffering
setIgnoreRepaint(true); // We'll handle repainting
createBufferStrategy(2);
f620 = getBufferStrategy();
f220 = true;
}
// Getter and Setter methods
/**
* Get the Frame object encapsulating the program
*
* @return The frame
*/
public Frame m120() {
return f320;
}
/**
* Get a 'handle' of the current graphics buffer for drawing
*
* @return The Graphics2D buffer
*/
public Graphics2D m220() {
return (Graphics2D) f620.getDrawGraphics();
}
/**
* Get the name of the map to be loaded in StateGame
*
* @return Map name (with .map extension)
*/
public String m320() {
return f1120;
}
/**
* Set the default starting map (set by menu)
*
* @param v3
* The name of the map to load (with the .map extension)
*/
public void m420(String v3) {
f1120 = v3;
}
/**
* Return the current debug setting
*
* @return True if debug setting is on
* @see Game#m620()
*/
public boolean m520() {
return f120;
}
/**
* Toggle debugging. Facilities like AIManager use this flag to display
* diagnostic information like AI paths
*/
public void m620() {
f120 = !f120;
}
// Public Methods
/**
* Called by other states to safely change currentState. This is done so the
* currentState's logic can finish
*
* @see Game#m820()
*/
public void m720(int v4) {
f1020 = v4;
f920 = true;
}
/**
* The main game loop that handles graphics and game state determination
*/
public void m820() {
final long v5;
v5 = 20;
long v6;
v6 = 0;
while (f220) {
if ((v6 + v5) > System.currentTimeMillis()){
continue;
}
v6 = System.currentTimeMillis();
// If a state change was requested, execute it now
if (f920) {
f920 = false;
m920(f1020);
continue;
}
final Graphics2D v7;
v7 = m220();
// Wipe the screen
v7.setColor(Color.black);
v7.fillRect(0, 0, f420, f520);
// Run the logic of the current game state here
f820.m28();
// Show the new buffer
v7.dispose();
f620.show();
try {
Thread.sleep(10);
} catch (InterruptedException v8) {
// TODO Auto-generated catch block
v8.printStackTrace();
}
}
}
// Private Methods
/**
* Change the state of the game. Called in mainThreadLogic()
*
* @param v9
* The state to set. Must match the static vars above
* @see Game#m720(int)
* @see Game#m820()
*/
private void m920(int v9) {
// Cleanup for the outgoing state
if (f820 != null) {
f320.removeKeyListener(f820);
removeKeyListener(f820);
f820.m38();
}
// Set the new state type
f720 = v9;
// Instance the new state (reset() is called in the construtor)
switch (f720) {
case State.f28:
f820 = new StateGame(this);
break;
case State.f18:
f820 = new StateScoreboard(this);
/*
* StateGame sb = new StateScoreboard(); int newScore = 0;
*
* // If the previous state was STATE_GAME, pull the session
* score and pass it to the scoreboard if(currentState
* instanceof StateGame)
* sb.addScore((int)((StateGame)currentState
* ).getSessionScore()));
*
* currentState = sb;
*/
break;
case State.f48:
f820 = new StateEditor(this);
break;
case State.f08:
f820 = new StateMenu(this);
break;
case State.f58:
f820 = null;
f220 = false;
break;
default:
break;
}
// Setup input handler and reset()
if (f820 != null) {
f320.addKeyListener(f820);
addKeyListener(f820);
}
}
}
game/GameObject.java
package pacman.game;
import java.awt.Color;
import java.awt.Graphics2D;
import pacman.actors.Actor;
import pacman.map.Map;
import pacman.state.StateGame;
/**
* A game object is anything on the pacman grid (wall, cherry, ghost, player).
* GameObject is the base class of almost everything within the Map
*
* @author Ramsey Kant
*/
public abstract class GameObject {
// Static type vars
public static final int f016 = 1;
public static final int f116 = 2;
public static final int f216 = 4;
public static final int f316 = 8;
public static final int f416 = 16;
public static final int f516 = 32; // Virtual
public static final int f616 = 64; // Virtual
public static final int f716 = 128;
// Wall types (Walls aren't instanced GameObject's)
public static final byte f816 = 1;
public static final byte f916 = 2;
public static final byte f1016 = 3;
public static final byte f1116 = 4;
public static final byte f1216 = 5;
public static final byte f1316 = 6;
public static final byte f1416 = 7;
// Generic object attributes
protected int f1516;
protected Color f1616;
protected int f1716;
protected int f1816;
// Outside refereneces
protected final Map f1916; // Can only be set once. Object only exists within
// the map. If the map changes, new objects are
// created
// Getters and Setters
/**
* Return the type of the object set in the constructor. See static types
* defined in GameObject
*
* @return type of object
*/
public int m016() {
return f1516;
}
/**
* Grab the current java.awt.Color (base color) the object is being rendered
* in
*
* @return Base Color of the object
*/
public Color m116() {
return f1616;
}
/**
* Set the current base color used when rendering the object
*
* @param v0
* java.awt.Color Color of object
*/
public void m216(Color v0) {
f1616 = v0;
}
/**
* Grab the current X coordinate of the object on the map. This property is
* frequently modified by the Map class and move() method
*
* @see Actor#m712(int, int)
*/
public int m316() {
return f1716;
}
/**
* Grab the current Y coordinate of the object on the map. This property is
* frequently modified by the Map class and move() method
*
* @see Actor#m712(int, int)
*/
public int m416() {
return f1816;
}
// Public & Protected Abstract methods
/**
* Class Constructor for a game object
*
* @param v1
* Type of game object (see static types above)
* @param v2
* Standard java Color
* @param v3
* Reference to the global Map
* @param v4
* Initial x coordinate
* @param v5
* Initial y coordinate
*/
public GameObject(int v1, Color v2, Map v3, int v4, int v5) {
f1516 = v1;
f1616 = v2;
f1916 = v3;
f1716 = v4;
f1816 = v5;
}
/**
* Perform a "Think" cycle for the Object This includes things like self
* maintenance and movement
*/
public abstract void m516();
/**
* Draw the object. Subclasses should define how they are to be drawn. This
* is called in StateGame's logic()
*
* @param v6
* The graphics context
* @see StateGame#m28()
*/
public abstract void m616(Graphics2D v6);
}
game/Item.java
package pacman.game;
import java.awt.Color;
import java.awt.Graphics2D;
import pacman.actors.Player;
import pacman.map.Map;
/**
* Item objects are GameObject's that can be manipulated by the Player on the
* map (teleports, dots, powerups, fruit) Item is a subclass of GameObject
*
* @author Ramsey Kant
*/
public class Item extends GameObject {
// Teleportation vars
private int f07;
private int f17;
/**
* Class constructor for Item
*
* @param v0
* Object type
* @param v1
* Base color of the item
* @param v2
* Reference to the map object
* @param v3
* X coordinate the item will occupy on the map
* @param v4
* Y coordinate the item with occupy on the map
* @see GameObject
*/
public Item(int v0, Color v1, Map v2, int v3, int v4) {
super(v0, v1, v2, v3, v4);
f07 = 13;
f17 = 17;
}
/**
* Set the destination coordinates for teleportation. This isn't useful to
* any item other than a teleport
*
* @param v5
* X destination coordinate
* @param v6
* Y destination coordinate
*/
public void m07(int v5, int v6) {
f07 = v5;
f17 = v6;
}
/**
* Retrieve the teleport destination X coordinate
*
* @return X destination coordinate
* @see Item#m07(int, int)
*/
public int m17() {
return f07;
}
/**
* Retrieve the teleport destination Y coordinate
*
* @return Y destination coordinate
* @see Item#m07(int, int)
*/
public int m27() {
return f17;
}
/**
* Called when the item is picked up / used by the player (in the player's
* act() function) Add point values or trigger powerup modifiers here (using
* the pl object)
*
* @param v7
* Player that uses the item
* @return True->Destroy the item. False->Keep the item on the map
* @see Player#m516()
*/
public boolean m37(Player v7) {
boolean v8;
v8 = false;
// Perform action based on type
switch (f1516) {
case f016:
v7.m013(10);
v8 = true;
break;
case f116:
v7.m013(50);
v7.m313(true);
v8 = true;
break;
case f716:
v7.m712(f07, f17);
break;
default:
break;
}
return v8;
}
/**
* Item's have no "think" process. Blank method
*
* @see GameObject#m516()
*/
@Override
public void m516() {
// do nothing
}
/**
* Draw the item based on it's type
*
* @see GameObject#m616(java.awt.Graphics2D)
*/
@Override
public void m616(Graphics2D v9) {
v9.setColor(f1616);
final int v10;
v10 = (f1716 * f1916.f25) + f1916.f25 / 2;
final int v11;
v11 = (f1816 * f1916.f25) + f1916.f25 / 2;
// Render item based on type
switch (f1516) {
case f016:
v9.fillArc(v10 - 4, v11 - 4, 8, 8, 0, 360);
break;
case f116:
v9.fillArc(v10 - 8, v11 - 8, 16, 16, 0, 360);
break;
case f716:
v9.fillOval(v10 - 6, v11 - 8, 12, 16);
break;
default:
break;
}
}
}
game/JPacmanGame.java
package pacman.game;
import pacman.state.State;
/**
* The entry point of the program
*
* @author Ramsey Kant
*/
public class JPacmanGame {
public static void main(String[] v0) {
final Game v1;
v1 = new Game(1024, 768);
v1.m720(State.f08);
v1.m820();
System.exit(0);
}
}
map/Map.java
package pacman.map;
import java.awt.Color;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import pacman.actors.Actor;
import pacman.actors.Ghost;
import pacman.actors.Player;
import pacman.game.GameObject;
import pacman.game.Item;
import pacman.util.Direction;
/**
* Map class keeps track objects on the playing grid, helper methods to make
* movement decisions, and export/import methods for the editor
*
* @author Ramsey Kant
*/
public class Map {
// Map parameters (width & height represent # of cells)
private int f05;
private int f15;
public final int f25;
public final int f35;
public final int f45;
public final double f55;
// Instance vars
private byte f65[][];
private Item f75[][];
private ArrayList<Actor> f85;
private int f95;
/**
* Class constructor, inits a blank map based on a width, height, and cell
* size Used in the editor
*
* @param v0
* Width of the map
* @param v1
* Height of the map
* @param cs
* Size of individual cells in pixels
*/
public Map(int v0, int v1, double v2) {
// Set map parameters
f05 = v0;
f15 = v1;
f55 = v2;
f25 = (int) (32 * v2);
f35 = (int) (12 * v2);
f45 = (int) (10 * v2);
f95 = 0;
// Initialize collideMap, a 2D array that contains all static collidable
// GameObjects
// We use this for fast lookup during collision detection and AI
// movement paths
f65 = new byte[f05][f15];
// Initialize itemMap, a 2D array that contains items (dots, powerups,
// cherry) on the map
f75 = new Item[f05][f15];
// Create m_objects, an arraylist with all actorList
f85 = new ArrayList<Actor>();
}
/**
* Class Constructor that reads the map data from filename
*
* @param v3
* The file name of the map to read contents from
* @param cs
* Size of individual cells in pixels. This is something that
* should be deteremined by graphics, not the mapfile
*/
public Map(String v3, double v4) {
// Set the cell size
f55 = v4;
f25 = (int) (32 * v4);
f35 = (int) (12 * v4);
f45 = (int) (10 * v4);
// Read contents of the map file
m245(v3);
}
/**
* The width of the map originally set in the constructor
*
* @return The width of the map
*/
public int m05() {
return f05;
}
/**
* The height of the map originally set in the constructor
*
* @return The height of the map
*/
public int m15() {
return f15;
}
/**
* Get the number of actorList on the map (the size of the actorList
* ArrayList)
*
* @return Number of actorList
*/
public int m25() {
return f85.size();
}
/**
* Return the collidable map (a 2d array of bytes which correspond to the
* collidable types defined in GameObject)
*
* @return collidable map (collideMap)
*/
public byte[][] m35() {
return f65;
}
/**
* Return the item map (a 2D array of Item objects)
*
* @return item map (itemMap)
*/
public Item[][] m45() {
return f75;
}
/**
* Return the number of dots remaining on the map. This is tracked by the
* dotsRemaining local var (not a loop and count in itemMap)
*
* @return dots remaining
*/
public int m55() {
return f95;
}
/**
* Add a collidable (by type) to the collideMap
*
* @param v5
* X coordinate
* @param v6
* Y coordinate
* @param v7
* Type of collidable
* @return True if successful
*/
public boolean m65(int v5, int v6, byte v7) {
// Check bounds
if (v5 < 0 || v6 < 0 || v5 >= f05 || v6 >= f15) {
return false;
}
// Check if theres already something there
if (f65[v5][v6] > 0) {
return false;
}
// Add to the collideMap
f65[v5][v6] = v7;
return true;
}
/**
* Put a new item to the item map
*
* @param v8
* Item
* @return True if successful
*/
public boolean m75(Item v8) {
if (v8 == null) {
return false;
}
final int v9;
v9 = v8.m316();
final int v10;
v10 = v8.m416();
if (v9 < 0 || v10 < 0 || v9 >= f05 || v10 >= f15) {
return false;
}
// Add to the itemMap
if (v8.m016() == GameObject.f016) {
f95++;
}
f75[v9][v10] = v8;
return true;
}
/**
* Put a new actor in the map (actorList ArrayList)
*
* @param v11
* Actor
* @return True if successful
*/
public boolean m85(Actor v11) {
if (v11 == null) {
return false;
}
final int v12;
v12 = v11.m316();
final int v13;
v13 = v11.m416();
if (v12 < 0 || v13 < 0 || v12 >= f05 || v13 >= f15) {
return false;
}
// Add to the array list
f85.add(v11);
return true;
}
/**
* Return a value at (x,y) in the collision map
*
* @param v14
* X Coordinate
* @param v15
* Y Coordinate
* @return Integer that represents the collision object
*/
public byte m95(int v14, int v15) {
// Check bounds
if (v14 < 0 || v15 < 0 || v14 >= f05 || v15 >= f15) {
return -1;
}
return f65[v14][v15];
}
/**
* Return an item at coordinate (x,y) from within the item map (itemMap)
*
* @param v16
* X Coordinate
* @param v17
* Y Coordinate
* @return Item the item that is found at (x,y)
*/
public Item m105(int v16, int v17) {
// Check bounds
if (v16 < 0 || v17 < 0 || v16 >= f05 || v17 >= f15) {
return null;
}
return f75[v16][v17];
}
/**
* Return an actor at index in the actorList ArrayList
*
* @param v18
* Index in actorList
* @return Actor (null if non-existant)
*/
public Actor m115(int v18) {
Actor v19;
v19 = null;
try {
v19 = f85.get(v18);
} catch (final IndexOutOfBoundsException v20) {
v20.printStackTrace();
}
return v19;
}
/**
* Find and return the player object within the local actorList ArrayList
*
* @return The player object. null if not found
*/
public Player m125() {
// Get from the object map
for (final Actor v21 : f85) {
if (v21.m016() == GameObject.f316) {
return (Player) v21;
}
}
return null;
}
/**
* Return an actor at coordinate (x,y)
*
* @param v22
* X Coordinate
* @param v23
* Y Coordinate
* @param v24
* If true, ignore a "Player" actor at (x,y)
* @return Actor (null if an actor doesn't exist at the position)
*/
public Actor m135(int v22, int v23, boolean v24) {
// Check bounds
if (v22 < 0 || v23 < 0 || v22 >= f05 || v23 >= f15) {
return null;
}
// Get from the object map
for (final Actor v25 : f85) {
if (v24 && v25.m016() == GameObject.f316) {
continue;
}
if (v25.m316() == v22 && v25.m416() == v23) {
return v25;
}
}
return null;
}
/**
* Remove an actor from actorList based on index. Be careful when using
* this! Just because an actor isn't in the map doesn't mean it's not
* 'alive' This is primarily for the editor
*
* @param v26
* Index of the actor
*/
public void m145(int v26) {
f85.remove(v26);
}
/**
* Remove an item from the item array by coordinate (x, y)
*
* @param v27
* X coordinate of the item
* @param v28
* Y coordinate of the item
*/
public void m155(int v27, int v28) {
// Check bounds
if (v27 < 0 || v28 < 0 || v27 >= f05 || v28 >= f15) {
return;
}
if (f75[v27][v28].m016() == GameObject.f016) {
f95--;
}
f75[v27][v28] = null;
}
/**
* Remove everything at coordiante (x,y) Used by the editor only
*
* @param v29
* X coordinate
* @param v30
* Y coordinate
* @return boolean True if something was removed, false if otherwise
*/
public boolean m165(int v29, int v30) {
boolean v31;
v31 = false;
// Check bounds
if (v29 < 0 || v30 < 0 || v29 >= f05 || v30 >= f15) {
return false;
}
// Remove any collidable
if (f65[v29][v30] != 0) {
f65[v29][v30] = 0;
v31 = true;
}
// Remove any item
if (f75[v29][v30] != null) {
f75[v29][v30] = null;
v31 = true;
}
int v32;
// Remove any actor
for (v32
= 0; v32 < f85.size(); v32++) {
Actor v33;
v33 = f85.get(v32);
if (v33.m316() == v29 && v33.m416() == v30) {
f85.remove(v32);
v33 = null;
v32--;
v31 = true;
}
}
return v31;
}
/**
* Find the distance (Manhattan) between two objects
*
* @param v34
* GameObject at the initial position
* @param v35
* GameObject at the end position
* @return Distance (integer)
*/
public int m175(GameObject v34, GameObject v35) {
return (int) Math.sqrt(Math.pow(Math.abs(v34.m316() - v35.m316()), 2)
+ Math.pow(Math.abs(v34.m416() - v35.m416()), 2));
}
/**
* Check if a coordinate is completely empty (void of actorList, items, and
* collissions) Used by the editor
*
* @param v36
* A x coordinate to move to
* @param v37
* A y coordinate to move to
* @return True if empty. False if otherwise
*/
public boolean m185(int v36, int v37) {
// Check bounds
if (v36 < 0 || v37 < 0 || v36 >= f05 || v37 >= f15) {
return false;
}
// Check if the Object is hitting something on the collideMap
if (m95(v36, v37) != 0) {
return false;
}
// Check if object is hitting something on the itemMap
if (m105(v36, v37) != null) {
return false;
}
// Actor collission
if (m135(v36, v37, false) != null) {
return false;
}
return true;
}
/**
* Move attempt method. Changes the position the map of the game object if
* there are no obstructions
*
* @param v38
* The actor object trying to move
* @param v39
* A x coordinate to move to
* @param v40
* A y coordinate to move to
* @return True if the move succeeded. False if otherwise
*/
public boolean m195(Actor v38, int v39, int v40) {
if (v38 == null) {
return false;
}
// Check bounds
if (!m215(v39, v40)) {
return false;
}
// Check if the Object is hitting something on the collideMap
if (m95(v39, v40) != 0) {
return false;
}
// Allow the Actor to move
return true;
}
public boolean m205(Actor v41, Direction v42) {
int v43;
v43 = v41.m316();
int v44;
v44 = v41.m416();
switch (v42) {
case f01:
v44--;
break;
case f11:
v43++;
break;
case f21:
v44++;
break;
case f31:
v43--;
break;
case f41:
return true;
}
return m195(v41, v43, v44);
}
private boolean m215(int v45, int v46) {
return v45 > 0 && v46 > 0 && v45 <= f05 && v46 <= f15;
}
/**
* Get the cost of moving through the given tile. This can be used to make
* certain areas more desirable. A simple and valid implementation of this
* method would be to return 1 in all cases.
*
* @param v47
* The mover that is trying to move across the tile
* @param v48
* The x coordinate of the tile we're moving from
* @param v49
* The y coordinate of the tile we're moving from
* @param v50
* The x coordinate of the tile we're moving to
* @param v51
* The y coordinate of the tile we're moving to
* @return The relative cost of moving across the given tile
*/
public float m225(Actor v47, int v48, int v49, int v50, int v51) {
return 1;
}
/**
* Write the contents of this map to a file in the correct format
*
* @param v52
* File name of the map
*/
public void m235(String v52) {
FileOutputStream v53;
DataOutputStream v54;
try {
v53 = new FileOutputStream(v52);
v54 = new DataOutputStream(v53);
// Write the map file magic
v54.writeUTF("RKPACMAP");
// Write map width & height
v54.writeInt(f05);
v54.writeInt(f15);
int v55;
// Write the collision map
for (v55 = 0; v55 < f05; v55++) {
int v56;
for (v56 = 0; v56 < f15; v56++) {
v54.write(f65[v55][v56]);
}
}
Item v57;
v57 = null;
int v58;
for (v58 = 0; v58 < f05; v58++) {
int v59;
for (v59
= 0; v59 < f15; v59++) {
v57 = f75[v58][v59];
// If an item doesnt exist at (x,y), write 'false' for
// nonexistant and continue
if (v57 == null) {
v54.writeBoolean(false);
continue;
}
v54.writeBoolean(true);
// Write properties of the item
v54.writeInt(v57.m016());
v54.writeInt(v57.m316());
v54.writeInt(v57.m416());
v54.writeInt(v57.m116().getRGB());
if (v57.m016() == GameObject.f716) {
v54.writeInt(v57.m17());
v54.writeInt(v57.m27());
}
}
}
// Write the number of actorList, then all actor data
v54.writeInt(f85.size());
for (final Actor v60 : f85) {
v54.writeInt(v60.m016());
v54.writeInt(v60.m316());
v54.writeInt(v60.m416());
v54.writeInt(v60.m116().getRGB());
if (v60.m016() == GameObject.f416) {
v54.writeBoolean(((Ghost) v60).m218());
}
}
v54.close();
v53.close();
} catch (final IOException v61) {
System.out.println("Failed to write map file: " + v61.getMessage());
}
}
/**
* Read a file with map contents and set the properties in this map Called
* by the constructor.
*
* @param v62
* File name of the map
*/
private void m245(String v62) {
FileInputStream v63;
DataInputStream v64;
try {
v63 = new FileInputStream(v62);
v64 = new DataInputStream(v63);
// Check for the magic
if (!v64.readUTF().equals("RKPACMAP")) {
System.out.println("Not a map file!");
return;
}
// Read map width & height
f05 = v64.readInt();
f15 = v64.readInt();
f95 = 0;
// Initialize collideMap, a 2D array that contains all static
// collidable GameObjects
// We use this for fast lookup during collision detection and AI
// movement paths
f65 = new byte[f05][f15];
// Initialize itemMap, a 2D array that contains items (dots,
// powerups, cherry) on the map
f75 = new Item[f05][f15];
// Create m_objects, an arraylist with all actorList
f85 = new ArrayList<Actor>();
int v65;
// Read the collision map
for (v65 = 0; v65 < f05; v65++) {
int v66;
for (v66 = 0; v66 < f15; v66++) {
m65(v65, v66, v64.readByte());
}
}
int v67;
// Read the item map
for (v67 = 0; v67 < f05; v67++) {
int v68;
for (v68
= 0; v68 < f15; v68++) {
// If an item doesnt exist at (x,y), continue
if (!v64.readBoolean()) {
continue;
}
final int v69;
v69 = v64.readInt();
final int v70;
v70 = v64.readInt();
final int v71;
v71 = v64.readInt();
final Color v72;
v72 = new Color(v64.readInt());
m75(new Item(v69, v72, this, v70, v71));
if (v69 == GameObject.f716) {
final int v73;
v73 = v64.readInt();
final int v74;
v74 = v64.readInt();
f75[v70][v71].m07(v73, v74);
}
}
}
final int v75;
v75 = v64.readInt();
int v76;
for (v76
= 0; v76 < v75; v76++) {
final int v77;
v77 = v64.readInt();
final int v78;
v78 = v64.readInt();
final int v79;
v79 = v64.readInt();
final Color v80;
v80 = new Color(v64.readInt());
if (v77 == GameObject.f316) {
m85(new Player(this, v78, v79));
} else if (v77 == GameObject.f416) {
final boolean v81;
v81 = v64.readBoolean();
m85(new Ghost(v80, this, v78, v79, v81));
} /*
* else { addActor(new Actor(t, c, this, ix, iy)); }
*/
}
v64.close();
v63.close();
} catch (final IOException v82) {
System.out.println("Failed to read map file: " + v82.getMessage());
}
}
}
map/Path.java
package pacman.map;
import java.util.ArrayList;
/**
* A path determined by some path finding algorithm. A series of steps from the
* starting location to the target location. This includes a step for the
* initial location.
*
* @author Kevin Glass
*/
public class Path {
/** The list of steps building up this path */
private final ArrayList<Step> f03;
/**
* Create an empty path
*/
public Path() {
f03 = new ArrayList<Step>();
}
/**
* Get the length of the path, i.e. the number of steps
*
* @return The number of steps in this path
*/
public int m03() {
return f03.size();
}
/**
* Get the step at a given index in the path
*
* @param v0
* The index of the step to retrieve. Note this should be >= 0
* and < getLength();
* @return The step information, the position on the map.
*/
public Step m13(int v0) {
return f03.get(v0);
}
/**
* Get the x coordinate for the step at the given index
*
* @param v1
* The index of the step whose x coordinate should be retrieved
* @return The x coordinate at the step
*/
public int m23(int v1) {
return m13(v1).f03;
}
/**
* Get the y coordinate for the step at the given index
*
* @param v2
* The index of the step whose y coordinate should be retrieved
* @return The y coordinate at the step
*/
public int m33(int v2) {
return m13(v2).f13;
}
/**
* Append a step to the path.
*
* @param v3
* The x coordinate of the new step
* @param v4
* The y coordinate of the new step
*/
public void m43(int v3, int v4) {
f03.add(new Step(v3, v4));
}
/**
* Prepend a step to the path.
*
* @param v5
* The x coordinate of the new step
* @param v6
* The y coordinate of the new step
*/
public void m53(int v5, int v6) {
f03.add(0, new Step(v5, v6));
}
/**
* Check if this path contains the given step
*
* @param v7
* The x coordinate of the step to check for
* @param v8
* The y coordinate of the step to check for
* @return True if the path contains the given step
*/
public boolean m63(int v7, int v8) {
return f03.contains(new Step(v7, v8));
}
/**
* A single step within the path
*
* @author Kevin Glass
*/
public class Step {
/** The x coordinate at the given step */
private final int f03;
/** The y coordinate at the given step */
private final int f13;
/**
* Create a new step
*
* @param v9
* The x coordinate of the new step
* @param v10
* The y coordinate of the new step
*/
public Step(int v9, int v10) {
this.f03 = v9;
this.f13 = v10;
}
/**
* Get the x coordinate of the new step
*
* @return The x coodindate of the new step
*/
public int m03() {
return f03;
}
/**
* Get the y coordinate of the new step
*
* @return The y coodindate of the new step
*/
public int m13() {
return f13;
}
/**
* @see Object#hashCode()
*/
@Override
public int hashCode() {
return f03 * f13;
}
/**
* @see Object#equals(Object)
*/
@Override
public boolean equals(Object v11) {
if (v11 instanceof Step) {
final Step v12;
v12 = (Step) v11;
return (v12.f03 == f03) && (v12.f13 == f13);
}
return false;
}
}
}
map/PathFinder.java
package pacman.map;
import java.util.ArrayList;
import java.util.Collections;
import pacman.actors.Actor;
import pacman.ai.AStarHeuristic;
/**
* A path finder implementation that uses the AStar heuristic based algorithm to
* determine a path.
*
* @author Kevin Glass
*/
public class PathFinder {
/** The set of nodes that have been searched through */
private final ArrayList<Node> f04;
/** The set of nodes that we do not yet consider fully searched */
private final SortedNodeList f14 = new SortedNodeList();
/** The map being searched */
private final Map f24;
/** The maximum depth of search we're willing to accept before giving up */
private final int f34;
/** The complete set of nodes across the map */
private final Node[][] f44;
/** True if we allow diaganol movement */
private final boolean f54;
/** The heuristic we're applying to determine which nodes to search first */
private final AStarHeuristic f64;
/**
* Create a path finder with the default heuristic - closest to target.
*
* @param v0
* The map to be searched
* @param v1
* The maximum depth we'll search before giving up
* @param v2
* True if the search should try diaganol movement
*/
public PathFinder(Map v0, int v1, boolean v2) {
this(v0, v1, v2, new AStarHeuristic());
}
/**
* Create a path finder
*
* @param v6
* The heuristic used to determine the search order of the map
* @param v3
* The map to be searched
* @param v4
* The maximum depth we'll search before giving up
* @param v5
* True if the search should try diaganol movement
*/
public PathFinder(Map v3, int v4, boolean v5,
AStarHeuristic v6) {
this.f64 = v6;
this.f24 = v3;
this.f34 = v4;
this.f54 = v5;
f04 = new ArrayList<Node>();
f44 = new Node[v3.m05()][v3.m15()];
int v7;
for (v7 = 0; v7 < v3.m05(); v7++) {
int v8;
for (v8
= 0; v8 < v3.m15(); v8++) {
f44[v7][v8] = new Node(v7, v8);
}
}
}
/**
* Find a path from the starting location provided (sx,sy) to the target
* location (tx,ty) avoiding blockages and attempting to honour costs
* provided by the tile map.
*
* @param v9
* The entity that will be moving along the path. This provides a
* place to pass context information about the game entity doing
* the moving, e.g. can it fly? can it swim etc.
*
* @param v10
* The x coordinate of the start location
* @param v11
* The y coordinate of the start location
* @param v12
* The x coordinate of the target location
* @param v13
* Teh y coordinate of the target location
* @return The path found from start to end, or null if no path can be
* found.
*/
public Path m04(Actor v9, int v10, int v11, int v12, int v13) {
// easy first check, if the destination is blocked, we can't get there
if (!f24.m195(v9, v12, v13)) {
return null;
}
// initial state for A*. The closed group is empty. Only the starting
// tile is in the open list and it'e're already there
f44[v10][v11].f24 = 0;
f44[v10][v11].f54 = 0;
f04.clear();
f14.m14();
f14.m24(f44[v10][v11]);
f44[v12][v13].f34 = null;
int v14;
v14 = 0;
while ((v14 < f34) && (f14.m44() != 0)) {
// pull out the first node in our open list, this is determined to
// be the most likely to be the next step based on our heuristic
final Node v15;
v15 = m14();
if (v15 == f44[v12][v13]) {
break;
}
m44(v15);
m54(v15);
// search through all the neighbours of the current node evaluating
// them as next steps
int v16;
for (v16 = -1; v16 < 2; v16++) {
int v17;
for (v17
= -1; v17 < 2; v17++) {
// not a neighbour, its the current tile
if ((v16 == 0) && (v17 == 0)) {
continue;
}
// if we're not allowing diaganol movement then only
// one of x or y can be set
if (!f54) {
if ((v16 != 0) && (v17 != 0)) {
continue;
}
}
// determine the location of the neighbour and evaluate it
final int v18;
v18 = v16 + v15.f04;
final int v19;
v19 = v17 + v15.f14;
if (m84(v9, v10, v11, v18, v19)) {
// the cost to get to this node is cost the current plus
// the movement
// cost to reach this node. Note that the heursitic
// value is only used
// in the sorted open list
final float v20;
v20 = v15.f24
+ m94(v9, v15.f04, v15.f14, v18, v19);
final Node v21;
v21 = f44[v18][v19];
// if the new cost we've determined for this node is
// lower than
// it has been previously makes sure the node hasn'e've
// determined that there might have been a better path
// to get to
// this node so it needs to be re-evaluated
if (v20 < v21.f24) {
if (m34(v21)) {
m44(v21);
}
if (m64(v21)) {
m74(v21);
}
}
// if the node hasn't already been processed and
// discarded then
// reset it's cost to our current cost and add it as a
// next possible
// step (i.e. to the open list)
if (!m34(v21) && !(m64(v21))) {
v21.f24 = v20;
v21.f44 = m104(v9, v18, v19, v12, v13);
v14 = Math.max(v14, v21.m04(v15));
m24(v21);
}
}
}
}
}
// since we'e've run out of search
// there was no path. Just return null
if (f44[v12][v13].f34 == null) {
return null;
}
// At this point we've definitely found a path so we can uses the parent
// references of the nodes to find out way from the target location back
// to the start recording the nodes on the way.
final Path v22;
v22 = new Path();
Node v23;
v23 = f44[v12][v13];
while (v23 != f44[v10][v11]) {
v22.m53(v23.f04, v23.f14);
v23 = v23.f34;
}
v22.m53(v10, v11);
// thats it, we have our path
return v22;
}
/**
* Get the first element from the open list. This is the next one to be
* searched.
*
* @return The first element in the open list
*/
protected Node m14() {
return (Node) f14.m04();
}
/**
* Add a node to the open list
*
* @param v24
* The node to be added to the open list
*/
protected void m24(Node v24) {
f14.m24(v24);
}
/**
* Check if a node is in the open list
*
* @param v25
* The node to check for
* @return True if the node given is in the open list
*/
protected boolean m34(Node v25) {
return f14.m54(v25);
}
/**
* Remove a node from the open list
*
* @param v26
* The node to remove from the open list
*/
protected void m44(Node v26) {
f14.m34(v26);
}
/**
* Add a node to the closed list
*
* @param v27
* The node to add to the closed list
*/
protected void m54(Node v27) {
f04.add(v27);
}
/**
* Check if the node supplied is in the closed list
*
* @param v28
* The node to search for
* @return True if the node specified is in the closed list
*/
protected boolean m64(Node v28) {
return f04.contains(v28);
}
/**
* Remove a node from the closed list
*
* @param v29
* The node to remove from the closed list
*/
protected void m74(Node v29) {
f04.remove(v29);
}
/**
* Check if a given location is valid for the supplied mover
*
* @param v30
* The mover that would hold a given location
* @param v31
* The starting x coordinate
* @param v32
* The starting y coordinate
* @param v33
* The x coordinate of the location to check
* @param v34
* The y coordinate of the location to check
* @return True if the location is valid for the given mover
*/
protected boolean m84(Actor v30, int v31, int v32, int v33, int v34) {
boolean v35;
v35 = (v33 < 0) || (v34 < 0) || (v33 >= f24.m05())
|| (v34 >= f24.m15());
if ((!v35) && ((v31 != v33) || (v32 != v34))) {
v35 = f24.m195(v30, v33, v34) == false;
}
return !v35;
}
/**
* Get the cost to move through a given location
*
* @param v36
* The entity that is being moved
* @param v37
* The x coordinate of the tile whose cost is being determined
* @param v38
* The y coordiante of the tile whose cost is being determined
* @param v39
* The x coordinate of the target location
* @param v40
* The y coordinate of the target location
* @return The cost of movement through the given tile
*/
public float m94(Actor v36, int v37, int v38, int v39, int v40) {
return f24.m225(v36, v37, v38, v39, v40);
}
/**
* Get the heuristic cost for the given location. This determines in which
* order the locations are processed.
*
* @param v41
* The entity that is being moved
* @param v42
* The x coordinate of the tile whose cost is being determined
* @param v43
* The y coordiante of the tile whose cost is being determined
* @param v44
* The x coordinate of the target location
* @param v45
* The y coordinate of the target location
* @return The heuristic cost assigned to the tile
*/
public float m104(Actor v41, int v42, int v43, int v44, int v45) {
return f64.m06(f24, v41, v42, v43, v44, v45);
}
/**
* A simple sorted list
*
* @author kevin
*/
private class SortedNodeList {
/** The list of elements */
private final ArrayList<Node> f04 = new ArrayList<Node>();
/**
* Retrieve the first element from the list
*
* @return The first element from the list
*/
public Object m04() {
return f04.get(0);
}
/**
* Empty the list
*/
public void m14() {
f04.clear();
}
/**
* Add an element to the list - causes sorting
*
* @param v46
* The element to add
*/
public void m24(Node v46) {
f04.add(v46);
Collections.sort(f04);
}
/**
* Remove an element from the list
*
* @param v47
* The element to remove
*/
public void m34(Object v47) {
f04.remove(v47);
}
/**
* Get the number of elements in the list
*
* @return The number of element in the list
*/
public int m44() {
return f04.size();
}
/**
* Check if an element is in the list
*
* @param v48
* The element to search for
* @return True if the element is in the list
*/
public boolean m54(Object v48) {
return f04.contains(v48);
}
}
/**
* A single node in the search graph
*/
private class Node implements Comparable<Object> {
/** The x coordinate of the node */
private final int f04;
/** The y coordinate of the node */
private final int f14;
/** The path cost for this node */
private float f24;
/** The parent of this node, how we reached it in the search */
private Node f34;
/** The heuristic cost of this node */
private float f44;
/** The search depth of this node */
private int f54;
/**
* Create a new node
*
* @param v49
* The x coordinate of the node
* @param v50
* The y coordinate of the node
*/
public Node(int v49, int v50) {
this.f04 = v49;
this.f14 = v50;
}
/**
* Set the parent of this node
*
* @param v51
* The parent node which lead us to this node
* @return The depth we have no reached in searching
*/
public int m04(Node v51) {
f54 = v51.f54 + 1;
this.f34 = v51;
return f54;
}
/**
* @see Comparable#compareTo(Object)
*/
@Override
public int compareTo(Object v52) {
final Node v53;
v53 = (Node) v52;
final float v54;
v54 = f44 + f24;
final float v55;
v55 = v53.f44 + v53.f24;
if (v54 < v55) {
return -1;
} else if (v54 > v55) {
return 1;
} else {
return 0;
}
}
}
}
state/State.java
package pacman.state;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import pacman.game.Game;
/**
* A State is a mode of the program where input and functionality are radically
* different from others portions of the program. We can then effectively
* separate different logical facilities into their own State subclasses
*
* @author Ramsey Kant
*/
public abstract class State implements KeyListener {
// Game States
public static final int f08 = 1;
public static final int f18 = 2;
public static final int f28 = 4;
public static final int f38 = 8;
// public static final int STATE_GAMEOVER = 16;
public static final int f48 = 32;
public static final int f58 = 64;
protected Game f68;
/**
* Class Constructor
*
* @param v0
* Reference to the game
*/
public State(Game v0) {
f68 = v0;
m18();
}
/**
* Return the reference to the game object
*
* @return Reference to the game object
*/
public Game m08() {
return f68;
}
/**
* Start or reset the state
*
* Can be called either by the Supervisor or the state itself
*/
public abstract void m18();
/**
* Primary logic function called in the mainThreadLoop
*
* Called only by the Supervisor
*/
public abstract void m28();
/**
* Signals the state to terminate. Any final updates should be performed
* here THIS IS ONLY CALLED INSIDE CHANGESTATE() - DO NOT CALL THIS ANYWHERE
* ELSE
*/
public abstract void m38();
/*
* Human Input default
*/
@Override
public void keyReleased(KeyEvent v1) {
// do nothing
}
@Override
public void keyTyped(KeyEvent v2) {
// Esc
switch (v2.getKeyChar()) {
case 27:
f68.m720(f58);
break;
default:
break;
}
}
}
state/StateEditor.java
package pacman.state;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import pacman.actors.Actor;
import pacman.actors.Ghost;
import pacman.actors.Player;
import pacman.editor.EditorFrame;
import pacman.editor.EditorMarker;
import pacman.game.Game;
import pacman.game.GameObject;
import pacman.game.Item;
import pacman.map.Map;
/**
* The StateEditor is a mode of the program that allows the user to create and
* modify map files that can be played in StateGame. StateEditor is a subclass
* of State
*
* @author Ramsey Kant
*/
public class StateEditor extends State {
// Logic object references
private final EditorFrame f02;
private EditorMarker f12;
private boolean f22;
private Map f32;
// Placement variables
private int f42;
private byte f52;
private String f62;
private boolean f72;
private int f82;
private int f92;
// Map vars. Store them as class member vars to eliminate function call
// overhead for getHeight/getWidth
private int f102;
private int f112;
public StateEditor(Game v0) {
super(v0);
// If true, remove all editor helpers like grid lines
f22 = false;
// Create the editor toolpane
f68.m120().setSize(1024, f68.f520);
f02 = new EditorFrame(this);
f02.setVisible(true);
// Defaults
f42 = GameObject.f616;
f52 = GameObject.f816;
f62 = "Blinky";
f72 = false;
f82 = 13;
f92 = 17;
}
// Getters and Setters
/**
* Set the type of object to be placed by the marker Called by the
* EditorFrame (Dot, Powerup, Teleport buttons)
*
* @param v1
* Type of object (from GameObject statics)
*/
public void m02(int v1) {
f42 = v1;
}
/**
* Set the type of wall to be placed by the marker Called by the EditorFrame
* Wall button
*
* @param v2
* Type of wall (from GameObject statics)
*/
public void m12(byte v2) {
f52 = v2;
}
/**
* Set the type of wall to be placed by the marker Called by the EditorFrame
* Add Ghost button
*
* @param v3
* Type of wall (from GameObject statics)
*/
public void m22(String v3) {
f62 = v3;
}
/**
* Toggle the trapped status of the next ghost to be added
*
* @param v4
* True if trapped in the spawn-jail
*/
public void m32(boolean v4) {
f72 = v4;
}
/**
* Get the current trapped status
*
* @return True if new ghosts will be created as trapped
*/
public boolean m42() {
return f72;
}
/**
* Set the teleport destination, used to aid a teleport drop Called in
* EditorFrame by the Teleport add button
*
* @param v5
* destination coordinate X of the next teleport
* @param v6
* destination coordinate Y of the next teleport
*/
public void m52(int v5, int v6) {
f82 = v5;
f92 = v6;
}
/**
* Reset the StateEditor objects like the Marker
*
* @see State#m18()
*/
@Override
public void m18() {
// Force previous references out of scope
f12 = null;
f32 = null;
f42 = GameObject.f016;
}
/**
* Setup and render a new blank map
*
* @param v7
* The width of the map to be created
* @param v8
* The height of the map to be created
*/
public void m62(int v7, int v8) {
// Setup the game map
f68.m220().setBackground(Color.BLACK);
f102 = v7;
f112 = v8;
f32 = new Map(28, 31, 32);
// Create the marker (but don't put it "in" the map)
f12 = new EditorMarker(Color.GREEN, f32, 0, 0);
}
/**
* Save the map
*
* @param v9
*/
public void m72(String v9) {
f32.m235(System.getProperty("user.dir") + "\\" + v9);
}
/**
* Setup and render a map loaded from the file system
*
* @param v10
*/
public void m82(String v10) {
// Setup the game map
f68.m220().setBackground(Color.BLACK);
f32 = new Map(System.getProperty("user.dir") + "\\" + v10, 32);
f102 = f32.m05();
f112 = f32.m15();
// Create the marker (but don't put it "in" the map)
f12 = new EditorMarker(Color.GREEN, f32, 0, 0);
}
/**
* Logic of the editor processed here: Rendering, input, and object
* placement. Called in the mainThreadLoop
*
* @see State#m28()
*/
@Override
public void m28() {
if (f32 == null) {
return;
}
final Graphics2D v11;
v11 = f68.m220();
// Offset the buffer so object's arent clipped by the window borders
v11.translate(10, 30);
Item v12;
v12 = null;
int v13;
for (v13 = 0; v13 < f102; v13++) {
int v14;
for (v14
= 0; v14 < f112; v14++) {
final byte v15;
v15 = f32.m95(v13, v14);
// Switch based on wall type and paint
v11.setColor(Color.BLUE);
switch (v15) {
case 0:
// Nothing
break;
case GameObject.f816:
// Vertical wall, no edges
v11.fillRoundRect(v13 * f32.f25 + 10, v14 * f32.f25, 12,
f32.f25, 0, 0); // 2x+12 = map.CELL_SIZE.
// x = 10
break;
case GameObject.f916:
// Horizontal wall, no edges
v11.fillRoundRect(v13 * f32.f25, v14 * f32.f25 + 10, f32.f25,
12, 0, 0);
break;
case GameObject.f1016:
// g.fillArc(x*map.CELL_SIZE+10, y*map.CELL_SIZE,
// map.CELL_SIZE, map.CELL_SIZE, 90, 90);
v11.fillRoundRect(v13 * f32.f25 + (f32.f25 / 2), v14 * f32.f25
+ 10, f32.f25 / 2, 12, 0, 0);
v11.fillRoundRect(v13 * f32.f25 + 10, v14 * f32.f25
+ (f32.f25 / 2), 12, f32.f25 / 2, 0, 0);
break;
case GameObject.f1116:
v11.fillRoundRect(v13 * f32.f25, v14 * f32.f25 + 10,
f32.f25 / 2, 12, 0, 0);
v11.fillRoundRect(v13 * f32.f25 + 10, v14 * f32.f25
+ (f32.f25 / 2), 12, f32.f25 / 2, 0, 0);
break;
case GameObject.f1216:
v11.fillRoundRect(v13 * f32.f25 + (f32.f25 / 2), v14 * f32.f25
+ 10, f32.f25 / 2, 12, 0, 0); // hori
v11.fillRoundRect(v13 * f32.f25 + 10, v14 * f32.f25, 12,
f32.f25 / 2, 0, 0); // vert
break;
case GameObject.f1316:
v11.fillRoundRect(v13 * f32.f25, v14 * f32.f25 + 10,
f32.f25 / 2, 12, 0, 0); // hori
v11.fillRoundRect(v13 * f32.f25 + 10, v14 * f32.f25, 12,
f32.f25 / 2, 0, 0); // vert
break;
case GameObject.f1416:
v11.setColor(Color.PINK);
v11.fillRoundRect(v13 * f32.f25, v14 * f32.f25 + 10, f32.f25,
6, 0, 0);
break;
default:
break;
}
// Paint any of the items here
v12 = f32.m105(v13, v14);
if (v12 != null) {
v12.m616(v11);
}
}
}
final int v16;
v16 = f32.m25();
int v17;
for (v17
= 0; v17 < v16; v17++) {
final Actor v18;
v18 = f32.m115(v17);
if (v18 != null) {
v18.m616(v11);
}
}
// Paint the marker
f12.m616(v11);
// Paint gridline overlay if in editor view
if (!f22) {
v11.setColor(Color.RED);
int v19;
for (v19 = 0; v19 < f102; v19++) {
v11.drawLine(v19 * f32.f25, 0, v19 * f32.f25, f112 * f32.f25);
}
int v20;
for (v20
= 0; v20 < f112; v20++) {
v11.drawLine(0, v20 * f32.f25, f102 * f32.f25, v20 * f32.f25);
}
// Player X,Y coordinates bottom right
v11.drawString("X: " + f12.m316() + ", Y: " + f12.m416(), 900, 700);
}
}
/**
* Termination of the StateEdtior. Set references stored by the StateEditor
* as null
*
* @see State#m38()
*/
@Override
public void m38() {
// Cleanup
f12 = null;
f32 = null;
}
/**
* Input processing for the Editor
*
* @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
*/
@Override
public void keyPressed(KeyEvent v21) {
switch (v21.getKeyCode()) {
case KeyEvent.VK_UP:
f12.m09(0, -1);
break;
case KeyEvent.VK_RIGHT:
f12.m09(1, 0);
break;
case KeyEvent.VK_DOWN:
f12.m09(0, +1);
break;
case KeyEvent.VK_LEFT:
f12.m09(-1, 0);
break;
case KeyEvent.VK_ENTER:
if (f12 == null) {
return;
}
// If not empty, bail
if (!f32.m185(f12.m316(), f12.m416())) {
return;
}
switch (f42) {
case GameObject.f616:
f32.m65(f12.m316(), f12.m416(), f52);
break;
case GameObject.f016:
f32.m75(new Item(GameObject.f016, Color.WHITE, f32,
f12.m316(), f12.m416()));
break;
case GameObject.f116:
f32.m75(new Item(GameObject.f116, Color.WHITE, f32, f12
.m316(), f12.m416()));
break;
case GameObject.f416:
if (f62.equals("Blinky")) {
f32.m85(new Ghost(Color.RED, f32, f12.m316(), f12.m416(),
f72));
} else if (f62.equals("Pinky")) {
f32.m85(new Ghost(Color.PINK, f32, f12.m316(), f12.m416(),
f72));
} else if (f62.equals("Inky")) {
f32.m85(new Ghost(Color.CYAN, f32, f12.m316(), f12.m416(),
f72));
} else {
f32.m85(new Ghost(Color.ORANGE, f32, f12.m316(), f12.m416(),
f72));
}
break;
case GameObject.f316:
int v22;
// If there is already a player in the actors list,
// remove it
for (v22
= 0; v22 < f32.m25(); v22++) {
if (f32.m115(v22).m016() == GameObject.f316) {
f32.m145(v22);
v22--;
}
}
// Add the new player
f32.m85(new Player(f32, f12.m316(), f12.m416()));
break;
case GameObject.f716:
final Item v23;
v23 = new Item(GameObject.f716,
Color.LIGHT_GRAY, f32, f12.m316(), f12.m416());
v23.m07(f82, f92);
f32.m75(v23);
break;
default:
break;
}
break;
case KeyEvent.VK_DELETE:
// Delete a placed object. Will reduce excessive memory
// consumption if the user cant just replace a tile with a new
// object
// If empty, bail
if (f32.m185(f12.m316(), f12.m416())) {
return;
}
// Remove anything (collidable, actor, or item) at (x,y)
f32.m165(f12.m316(), f12.m416());
break;
case KeyEvent.VK_V:
f22 = !f22;
break;
case KeyEvent.VK_0:
// editorFrame.setEnabled(false);
// game.changeState(STATE_MENU);
break;
default:
break;
}
}
}
state/StateGame.java
package pacman.state;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import pacman.actors.Actor;
import pacman.actors.Ghost;
import pacman.actors.Player;
import pacman.ai.AIManager;
import pacman.game.Game;
import pacman.game.GameObject;
import pacman.game.Item;
import pacman.map.Map;
import pacman.util.Direction;
/**
* StateGame is a mode of the program where the user can play the game of Pacman
* various maps StateGame is a subclass of State
*
* @author Ramsey Kant
*/
public class StateGame extends State {
// Logic object references
private Player f015;
private Map f115;
private AIManager f215;
// Game vars
private String f315;
private int f415;
private int f515; // Overall score for the game session. The player
// object score is only the score for that life /
// level
private int f615;
private boolean f715;
private long f815;
// Map vars. Store them as class member vars to eliminate function call
// overhead for getHeight/getWidth
private int f915;
private int f1015;
/**
* StateGame Constructor
*
* @param v0
* Reference to the game supervisor
*/
public StateGame(Game v0) {
super(v0);
}
/**
* Get the current session score. A session score is the total score of the
* entire 'game' contained by the limited number of lives This is compounded
* at game over and in win()
*
* @see StateGame#m215()
* @see StateGame#m315()
*/
public int m015() {
return f515;
}
// Public Methods
/**
* Reset the state of the game entirely (level 1)
*
* @see State#m18()
*/
@Override
public void m18() {
// Set game vars
f315 = f68.m320();
f415 = 0;
f515 = 0;
f615 = 99;
f815 = 0;
// Respawn (start level 1)
m115(true);
}
/**
* Respawns the player after a death or win. Similar to reset() except
* running vars are saved
*
* @param v1
* Moves to the next level and corresponding map
*/
public void m115(boolean v1) {
f715 = true;
f815 = System.currentTimeMillis() + 3000;
// If we're jumping to the next level, reset everything
if (v1) {
f415++;
// Force previous references out of scope
f015 = null;
f115 = null;
f215 = null;
// Setup the game map
f68.m220().setBackground(Color.BLACK);
f115 = new Map(f315, 0.75);
f915 = f115.m05();
f1015 = f115.m15();
// Spawn the player
f015 = f115.m125();
// Setup AI
f215 = new AIManager(f115, f015, f68.m520());
// Slighly increase the game speed
} else { // Player died, reset the map
final int v2;
v2 = f115.m25();
int v3;
for (v3
= 0; v3 < v2; v3++) {
final Actor v4;
v4 = f115.m115(v3);
if (v4 != null) {
v4.m712(v4.m012(), v4.m112());
v4.m212(false);
if (v4.m016() == GameObject.f416) {
((Ghost) v4).m518(null);
}
}
}
}
}
/**
* Main game logic for rendering and processing. Called by mainThreadLoop
*
* @see Game#m820()
* @see State#m28()
*/
@Override
public void m28() {
if (f115 == null) {
return;
}
final Graphics2D v5;
v5 = f68.m220();
// Offset the buffer so object's arent clipped by the window borders
v5.translate(10, 30);
// Paint right UI with lives remaining, score, highscore etc
v5.setColor(Color.WHITE);
v5.setFont(new Font("Comic Sans MS", Font.BOLD, 24));
v5.drawString("PACMAN by Ramsey Kant", 680, 50);
v5.drawString("Score: " + f015.m113(), 750, 100);
v5.drawString("Total: " + f515, 750, 150);
v5.drawString("Lives: " + f615, 750, 200);
v5.drawString("Level: " + f415, 750, 250);
// Execute game logic for all entites on the map
if (!f715) {
f215.m20();
f015.m516();
}
// Check for player death. End the round if the player is dead
if (f015.m312()) {
m315();
return;
}
// Check for a win (all dots collected)
if (f115.m55() <= 0) {
m215();
return;
}
Item v6;
v6 = null;
int v7;
for (v7 = 0; v7 < f915; v7++) {
int v8;
for (v8
= 0; v8 < f1015; v8++) {
final byte v9;
v9 = f115.m95(v7, v8);
// Switch based on wall type and paint
v5.setColor(Color.BLUE);
switch (v9) {
case 0:
// Nothing
break;
case GameObject.f816:
// Vertical wall, no edges
v5.fillRoundRect(v7 * f115.f25 + f115.f45,
v8 * f115.f25,
f115.f35,
f115.f25, 0, 0); // 2x+12 = map.CELL_SIZE.
// x = 10
break;
case GameObject.f916:
// Horizontal wall, no edges
v5.fillRoundRect(v7 * f115.f25,
v8 * f115.f25 + f115.f45,
f115.f25,
f115.f35, 0, 0);
break;
case GameObject.f1016:
v5.fillRoundRect(v7 * f115.f25 + (f115.f25 / 2),
v8 * f115.f25 + f115.f45,
f115.f25 / 2,
f115.f35, 0, 0);
v5.fillRoundRect(v7 * f115.f25 + f115.f45,
v8 * f115.f25 + (f115.f25 / 2),
f115.f35,
f115.f25 / 2, 0, 0);
break;
case GameObject.f1116:
v5.fillRoundRect(v7 * f115.f25,
v8 * f115.f25 + f115.f45,
f115.f25 / 2,
f115.f35, 0, 0);
v5.fillRoundRect(v7 * f115.f25 + f115.f45,
v8 * f115.f25
+ (f115.f25 / 2),
f115.f35, f115.f25 / 2, 0, 0);
break;
case GameObject.f1216:
v5.fillRoundRect(v7 * f115.f25 + (f115.f25 / 2), v8 * f115.f25
+ f115.f45, f115.f25 / 2, f115.f35, 0, 0); // hori
v5.fillRoundRect(v7 * f115.f25 + f115.f45, v8 * f115.f25, 12,
f115.f25 / 2, 0, 0); // vert
break;
case GameObject.f1316:
v5.fillRoundRect(v7 * f115.f25, v8 * f115.f25 + f115.f45,
f115.f25 / 2, f115.f35, 0, 0); // hori
v5.fillRoundRect(v7 * f115.f25 + f115.f45, v8 * f115.f25, f115.f35,
f115.f25 / 2, 0, 0); // vert
break;
case GameObject.f1416:
v5.setColor(Color.PINK);
v5.fillRoundRect(v7 * f115.f25, v8 * f115.f25 + f115.f45, f115.f25,
f115.f35 / 2, 0, 0);
break;
default:
break;
}
// Paint any of the items here
v6 = f115.m105(v7, v8);
if (v6 != null) {
v6.m616(v5);
}
}
}
final int v10;
v10 = f115.m25();
int v11;
for (v11
= 0; v11 < v10; v11++) {
final Actor v12;
v12 = f115.m115(v11);
if (v12 != null) {
v12.m616(v5);
}
}
// Debug
if (f68.m520()) {
v5.setColor(Color.RED);
v5.drawString("DEBUG ON", 750, 650);
/*
* // Paint gridline overlay for(int i = 0; i < mapWidth; i++)
* g.drawLine(i*map.CELL_SIZE, 0, i*map.CELL_SIZE,
* mapHeight*map.CELL_SIZE); for(int i = 0; i < mapHeight; i++)
* g.drawLine(0, i*map.CELL_SIZE, mapWidth*map.CELL_SIZE,
* i*map.CELL_SIZE);
*/
// Player X,Y coordinates bottom right
v5.drawString("positionX: " + f015.m316(), 750, 675);
v5.drawString("positionY: " + f015.m416(), 750, 700);
}
// Check for game pause and print pause status
if (f715) {
v5.setColor(Color.RED);
v5.setFont(new Font("Comic Sans MS", Font.BOLD, 24));
v5.drawString("PAUSED", 750, 500);
if (f815 > System.currentTimeMillis()) {
v5.drawString(
"Pause ends in..." + ((f815 - System.currentTimeMillis()) / 1000),
750, 550);
}
if (f815 != 0 && System.currentTimeMillis() > f815) {
f815 = 0;
f715 = false;
}
return;
}
}
/**
* Player has died or the Supervisor has decided to change the state
* abruptly
*
* @see State#m38()
*/
@Override
public void m38() {
// Cleanup
f015 = null;
f115 = null;
}
/**
* Player has won, move to the next level Called by logic()
*
* @see StateGame#m28()
*/
public void m215() {
f515 += f015.m113();
m115(true);
}
/**
* Player has died, reset() if lives remain. Otherwise, request a state
* change thereby end()ing this state Called by logic()
*
* @see StateGame#m28()
*/
public void m315() {
f615--;
if (f615 > 0) {
m115(false);
} else {
if (f415 == 1) {
f515 = f015.m113(); // win() never called, so
// score is the 1st level
// score
}
f68.m720(State.f18);
}
}
/**
* Start automove in certain direction
*
* @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
*/
@Override
public void keyPressed(KeyEvent v13) {
if (f015 == null) {
return;
}
switch (v13.getKeyCode()) {
case KeyEvent.VK_UP:
f015.m612(Direction.f01);
break;
case KeyEvent.VK_RIGHT:
f015.m612(Direction.f11);
break;
case KeyEvent.VK_DOWN:
f015.m612(Direction.f21);
break;
case KeyEvent.VK_LEFT:
f015.m612(Direction.f31);
break;
case KeyEvent.VK_SPACE:
f015.m612(Direction.f51);
break;
case KeyEvent.VK_P:
// Don't interupt system pauses
if (f815 < System.currentTimeMillis()) {
f715 = !f715;
}
break;
case KeyEvent.VK_V:
f68.m620();
// AI debug
f215.m00(f68.m520());
break;
case KeyEvent.VK_0:
// game.changeState(STATE_MENU);
break;
default:
break;
}
}
}
state/StateMenu.java
package pacman.state;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.io.File;
import java.io.FilenameFilter;
import pacman.game.Game;
/**
* StateMenu is a graphical representation that allows users to switch into
* other States of the program like the Game and editor
*
* @author Ramsey Kant
*/
public class StateMenu extends State {
// Private instance
private int f019;
private int f119;
private byte f219;
private byte f319; // Corresponds to the index in mapList
private String[] f419;
public StateMenu(Game v0) {
super(v0);
}
@Override
public void m18() {
// Set cursor & menu position
f019 = 380;
f119 = 310;
f219 = 0;
f319 = 0;
final File v1;
v1 = new File(System.getProperty("user.dir"));
final FilenameFilter v2;
v2 = new FilenameFilter() {
@Override
public boolean accept(File v3, String v4) {
return v4.endsWith(".map");
}
};
// Apply the filter
f419 = v1.list(v2);
if (f419 == null) {
System.out.println("No maps exist!");
f68.m720(f58);
return;
}
}
/**
* Cleanup Menu objects
*
* @see State#m38()
*/
@Override
public void m38() {
// do nothing
}
/**
* Logic processing for the Menu. Rendering, Input, screen pointer
* manipulation
*
* @see State#m28()
*/
@Override
public void m28() {
final Graphics2D v5;
v5 = f68.m220();
// Draw title
v5.setColor(Color.YELLOW);
v5.setFont(new Font("Comic Sans MS", Font.BOLD, 50));
v5.fillArc(56, 92, 100, 100, 35, 270); // First pacman
v5.drawString("PACMAN", 350, 180);
v5.fillArc(780, 92, 100, 100, 35, 270);
// Draw menu options
v5.setFont(new Font("Comic Sans MS", Font.BOLD, 24));
v5.drawString("Play Game", 380, 300);
//g.drawString("Map Editor", 525, 340);
v5.drawString("Scoreboard", 380, 340);
v5.drawString("Exit", 380, 380);
if (f419.length > 0) {
v5.drawString("Current Map: " + f419[f319], 380, 600);
} else {
v5.drawString(
"No maps detected. Have you placed the maps file in the same directory as the program?",
100, 600);
}
// Draw underline cursor
v5.setColor(Color.RED);
v5.fillRect(f019, f119, 150, 5);
}
@Override
public void keyPressed(KeyEvent v6) {
switch (v6.getKeyCode()) {
case KeyEvent.VK_RIGHT:
if (f319 >= 0 && f319 < (f419.length - 1)) {
f319++;
}
break;
case KeyEvent.VK_LEFT:
if (f319 > 0 && f319 <= (f419.length - 1)) {
f319--;
}
break;
case KeyEvent.VK_DOWN:
if (f219 >= 0 && f219 < 2) {
f219++;
f119 += 38;
}
break;
case KeyEvent.VK_UP:
if (f219 > 0 && f219 <= 2) {
f219--;
f119 -= 38;
}
break;
case KeyEvent.VK_ENTER:
// Execute the appropriate state change
switch (f219) {
case 0:
// Play game
if (f419.length > 0) {
f68.m420(f419[f319]);
f68.m720(f28);
}
break;
case 1:
// Scoreboard
f68.m720(f18);
break;
case 2:
// Exit
f68.m720(f58);
break;
default:
break;
}
break;
default:
break;
}
}
}
state/StateScoreboard.java
package pacman.state;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import pacman.game.Game;
/**
* StateScoreboard is a mode of the program that allows the user to view (and
* sometimes modify) scores set in StateGame StateScoreboard is a subclass of
* State
*
* @author Ramsey Kant
*/
public class StateScoreboard extends State {
private String[] f017;
private int[] f117;
private int f217;
/**
* Class Constructor
*
* @param v0
* Reference to the Game class
*/
public StateScoreboard(Game v0) {
super(v0);
}
// Public Functions
/**
* Setup the scoreboard by loading the current score file
*
* @see State#m18()
*/
@Override
public void m18() {
// Only the top 10 scores will be displayed
f017 = new String[10];
f117 = new int[10];
f217 = 0;
// Read in the scores
// readScores();
}
/**
* Cleanup objects and write back the scores
*
* @see State#m38()
*/
@Override
public void m38() {
// saveScores();
}
/**
* Render the Scoreboard and perform any updates
*/
@Override
public void m28() {
final Graphics2D v1;
v1 = f68.m220();
// Draw title
v1.setColor(Color.YELLOW);
v1.setFont(new Font("Comic Sans MS", Font.BOLD, 72));
v1.fillArc(156, 92, 100, 100, 35, 270); // First pacman
v1.drawString("Scores", 450, 180);
v1.fillArc(960, 92, 100, 100, 35, 270);
v1.fillRect(150, 200, 910, 5);
v1.setFont(new Font("Comic Sans MS", Font.BOLD, 24));
int v2;
// Draw scores
for (v2
= 0; v2 < f017.length; v2++) {
if (f017[v2] == null) {
continue;
}
v1.drawString(f017[v2], 150, 210);
v1.drawString(f117[v2] + " ", 960, 210);
}
}
/**
* Output names and corresponding scores to the pacman.scores file
*/
public void m017() {
FileOutputStream v3;
DataOutputStream v4;
try {
v3 = new FileOutputStream("pacman.scores");
v4 = new DataOutputStream(v3);
// Write the score file magic
v4.writeUTF("RKPACSCORES");
// Write # of scores in the file, then the actual scores
v4.writeInt(f217);
int v5;
for (v5
= 0; v5 < f217; v5++) {
if (f017[v5] == null) {
break;
}
v4.writeUTF(f017[v5]);
v4.writeInt(f117[v5]);
}
v4.close();
v3.close();
} catch (final IOException v6) {
System.out.println("Failed to write score file: " + v6.getMessage());
}
}
/**
* Populate names and scores from the pacman.scores file
*/
public void m117() {
FileInputStream v7;
DataInputStream v8;
try {
v7 = new FileInputStream("pacman.scores");
v8 = new DataInputStream(v7);
// Check for the magic
if (!v8.readUTF().equals("RKPACSCORES")) {
System.out.println("Not a score file!");
return;
}
// Read in scores
f217 = v8.readInt();
if (f217 > 10) {
f217 = 10;
}
int v9;
for (v9
= 0; v9 < f217; v9++) {
f017[v9] = v8.readUTF();
f117[v9] = v8.readInt();
}
v8.close();
v7.close();
} catch (final IOException v10) {
System.out.println("Failed to read score file: " + v10.getMessage());
}
}
// Input functions
/**
* Process input on the scoreboard (exit)
*
* @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
*/
@Override
public void keyPressed(KeyEvent v11) {
switch (v11.getKeyCode()) {
case KeyEvent.VK_0:
f68.m720(f08);
break;
default:
break;
}
}
}
util/RequestedDirectionBuffer.java
package pacman.util;
import java.util.LinkedList;
/**
* This buffer is used to remember direction changes requested by the user for
* some game turns. If a direction change was requested too early (move not
* possible yet, because the crossing has not been reached) the direction change
* can be retired in the next steps. The size parameter of the constructor
* contols how long the user input will be remembered. If another direction is
* set, all previous directions will be forgotten.
*
* By default the buffer will return the neutral Direction.none direction. If
* another direction is set, the buffer will return this direction for the next
* n calls to getRequestedDirection(), where n = size. When a new direction is
* set, all previously set directions are forgotten.
*
*/
public class RequestedDirectionBuffer {
private final int f014;
private final LinkedList<Direction> f114;
public RequestedDirectionBuffer(int v0) {
super();
this.f014 = v0;
f114 = new LinkedList<Direction>();
m214(Direction.f41);
}
/**
* Get the currently requested direction.
*
* @return the currently requested direction.
*/
public Direction m014() {
final Direction v1;
v1 = f114.poll();
f114.add(Direction.f41);
return v1;
}
/**
* Set the requested direction
*
* @param v2
* the requested direction
*/
public void m114(Direction v2) {
m214(v2);
}
/**
* Fill the queue with a direction
*
* @param v3
* the direction.
*/
private void m214(Direction v3) {
f114.clear();
int v4;
for (v4 = 0; v4 < f014; v4++) {
f114.add(v3);
}
}
}