Committing historical code from 2001 with minor tweaks to make function

in maven.
This commit is contained in:
Rob 2016-09-11 11:25:08 -05:00
parent 92bdd9b4d8
commit 3bc978ed3a
99 changed files with 4305 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
/target/
/.classpath
/.project
/.settings/

BIN
doc/current/GamePlay.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

BIN
doc/original/Bomb.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 941 B

BIN
doc/original/Exit.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 895 B

BIN
doc/original/GameScreen.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

BIN
doc/original/HelpScreen.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

BIN
doc/original/Mine.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 889 B

BIN
doc/original/Mouse.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 914 B

BIN
doc/original/MouseMaze.dsk Normal file

Binary file not shown.

BIN
doc/original/Robot.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 924 B

BIN
doc/original/Skull.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 941 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

46
pom.xml Normal file
View File

@ -0,0 +1,46 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>a2geek.games</groupId>
<artifactId>mouse-maze-2001</artifactId>
<version>1.9.0-FINAL</version>
<name>Mouse Maze 2001</name>
<description>A recreation of a game developed in 1983.</description>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.shade.version>2.4.3</maven.shade.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>${maven.shade.version}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>a2geek.games.mousemaze2001.MouseMaze2001</Main-Class>
<Implementation-Title>Mouse Maze 2001</Implementation-Title>
<Implementation-Version>${project.version}</Implementation-Version>
</manifestEntries>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,308 @@
package a2geek.games.mousemaze2001;
import java.util.*;
import javax.swing.border.*;
import a2geek.games.mousemaze2001.domain.*;
import a2geek.games.mousemaze2001.images.ImageManager;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
/**
* Provides the panel used for game settings.
*
* Creation date: (10/27/01 7:32:59 PM)
* @author: <a href='mailto:greener@charter.net'>Rob Greene</a>
* @version: RJG 10/29/2001 22:40:54
*/
public class GameSettingsPanel extends JPanel implements ActionListener {
private static final String HARD = "hard";
private static final String EASY = "easy";
private static final String DEFAULT = "default";
private JSlider bombsPerLevel;
private JSlider robotRange;
private JSlider robotShotFrequency;
private JSlider robotMineFrequency;
private JCheckBox mouseShoots;
private JCheckBox robotShotDistanceFixed;
private JCheckBox animatedImages;
private JCheckBox unlimitedLevels;
private JCheckBox unlimitedLives;
private JCheckBox shieldedRobots;
private GameSettings easySettings;
private GameSettings hardSettings;
private GameSettings defaultSettings;
private GameSettings currentSettings;
/**
* GameSettingsPanel constructor comment.
*/
public GameSettingsPanel() {
super();
initializeSettings();
initializeComponents();
copyFromCurrentSettings();
}
/**
* Handle action events from buttons.
*
* Creation date: (10/27/01 7:45:27 PM)
*/
public void actionPerformed(ActionEvent actionEvent) {
String command = actionEvent.getActionCommand();
if (command != null) {
if (DEFAULT.equals(command)) {
currentSettings = new GameSettings(defaultSettings);
} else if (EASY.equals(command)) {
currentSettings = new GameSettings(easySettings);
} else if (HARD.equals(command)) {
currentSettings = new GameSettings(hardSettings);
}
copyFromCurrentSettings();
}
}
/**
* Copy the current settings values to the screen components.
*
* Creation date: (10/27/01 11:38:39 PM)
*/
public void copyFromCurrentSettings() {
bombsPerLevel.setMaximum(currentSettings.getMaxBombsPerLevel());
bombsPerLevel.setValue(currentSettings.getBombsPerLevel());
robotRange.setMaximum(currentSettings.getMaxRobotShotRange());
robotRange.setValue(currentSettings.getRobotShotRange());
robotShotDistanceFixed.setSelected(currentSettings.isFixedRobotShotRange());
robotShotFrequency.setValue(currentSettings.getRobotShootFrequency());
robotMineFrequency.setValue(currentSettings.getRobotMineFrequency());
mouseShoots.setSelected(currentSettings.isShootingMouse());
animatedImages.setSelected(currentSettings.isAnimatedImages());
unlimitedLevels.setSelected(currentSettings.isUnlimitedGameLevels());
unlimitedLives.setSelected(currentSettings.isUnlimitedLives());
shieldedRobots.setSelected(currentSettings.isShieldedRobots());
repaint();
}
/**
* Copy the current settings values from the screen components.
*
* Creation date: (10/27/01 11:38:39 PM)
*/
public void copyToCurrentSettings() {
currentSettings.setBombsPerLevel(bombsPerLevel.getValue());
currentSettings.setRobotShotRange(robotRange.getValue());
currentSettings.setFixedRobotShotRange(robotShotDistanceFixed.isSelected());
currentSettings.setRobotShootFrequency(robotShotFrequency.getValue());
currentSettings.setRobotMineFrequency(robotMineFrequency.getValue());
currentSettings.setShootingMouse(mouseShoots.isSelected());
currentSettings.setAnimatedImages(animatedImages.isSelected());
currentSettings.setUnlimitedGameLevels(unlimitedLevels.isSelected());
currentSettings.setUnlimitedLives(unlimitedLives.isSelected());
currentSettings.setShieldedRobots(shieldedRobots.isSelected());
}
/**
* Create a bordered panel.
*
* Creation date: (10/27/01 8:35:30 PM)
*/
protected JPanel createBorderedPanel(String title) {
return createBorderedPanel(title, BoxLayout.Y_AXIS);
}
/**
* Create a bordered panel.
*
* Creation date: (10/27/01 8:35:30 PM)
*/
protected JPanel createBorderedPanel(String title, int axis) {
JPanel thePanel = new JPanel();
thePanel.setLayout(new BoxLayout(thePanel, axis));
TitledBorder titledBorder = new TitledBorder(title);
titledBorder.setTitleColor(Color.black);
thePanel.setBorder(titledBorder);
return thePanel;
}
/**
* Create a standard image button.
*
* Creation date: (10/27/01 3:05:07 PM)
*/
protected JButton createImageButton(String resourceName, String commandString) {
return createImageButton(resourceName, commandString, this);
}
/**
* Create a standard image button.
*
* Creation date: (10/27/01 3:05:07 PM)
*/
protected JButton createImageButton(String resourceName, String commandString, ActionListener actionListener) {
JButton button = new JButton(new ImageIcon(ImageManager.getInstance().getImage(resourceName)));
button.setActionCommand(commandString);
button.addActionListener(actionListener);
return button;
}
/**
* Create a slider panel.
*
* Creation date: (10/27/01 8:38:48 PM)
*/
protected JSlider createSlider(int minimumValue, int maximumValue, int currentValue) {
JSlider theSlider = new JSlider(minimumValue, maximumValue, currentValue);
if (maximumValue >= 100) {
theSlider.setMinorTickSpacing(1);
theSlider.setMajorTickSpacing(10);
} else {
theSlider.setMajorTickSpacing(1);
}
theSlider.setPaintTicks(true);
theSlider.setPaintLabels(true);
theSlider.setSnapToTicks(true);
theSlider.setForeground(Color.black);
// change the foreground color of all labels (numbers)
Dictionary table = theSlider.getLabelTable();
Enumeration e = table.elements();
while (e.hasMoreElements()) {
JLabel label = (JLabel) e.nextElement();
label.setForeground(Color.black);
}
return theSlider;
}
/**
* Retrieve the current game settings.
*
* Creation date: (10/28/01 1:23:58 PM)
*/
public GameSettings getCurrentSettings() {
copyToCurrentSettings();
return currentSettings;
}
/**
* Initialize the graphical components.
*
* Creation date: (10/27/01 11:18:17 PM)
*/
protected void initializeComponents() {
GameSettings curs = currentSettings;
JPanel everything = new JPanel();
BoxLayout boxLayout = new BoxLayout(everything, BoxLayout.Y_AXIS);
everything.setLayout(boxLayout);
JPanel bombsPanel = createBorderedPanel("Bombs per level");
bombsPerLevel = createSlider(0,curs.getMaxBombsPerLevel(),curs.getBombsPerLevel());
bombsPanel.add(bombsPerLevel);
JPanel rangePanel = createBorderedPanel("Range of robot shooting");
robotRange = createSlider(1,curs.getMaxRobotShotRange(),curs.getRobotShotRange());
robotShotDistanceFixed = new JCheckBox("Robots can only shoot the maximum distance (specified above)");
robotShotDistanceFixed.setSelected(curs.isFixedRobotShotRange());
robotShotDistanceFixed.setHorizontalAlignment(JCheckBox.LEFT);
rangePanel.add(robotRange);
rangePanel.add(robotShotDistanceFixed);
JPanel freqPanel = createBorderedPanel("Robot shooting frequency (%)");
robotShotFrequency = createSlider(0,100,curs.getRobotShootFrequency());
freqPanel.add(robotShotFrequency);
JPanel minePanel = createBorderedPanel("Robot mine dropping frequency (%)");
robotMineFrequency = createSlider(0,100,curs.getRobotMineFrequency());
minePanel.add(robotMineFrequency);
JPanel settingsPanel = createBorderedPanel("Other settings");
mouseShoots = new JCheckBox("Honestly, mice can shoot. Really!");
mouseShoots.setSelected(curs.isShootingMouse());
animatedImages = new JCheckBox("Animated images");
animatedImages.setSelected(curs.isAnimatedImages());
unlimitedLevels = new JCheckBox("Unlimited levels");
unlimitedLevels.setSelected(curs.isUnlimitedGameLevels());
unlimitedLives = new JCheckBox("Unlimited lives");
unlimitedLives.setSelected(curs.isUnlimitedLives());
shieldedRobots = new JCheckBox("Are robots shielded?");
shieldedRobots.setSelected(curs.isShieldedRobots());
settingsPanel.add(mouseShoots);
settingsPanel.add(shieldedRobots);
settingsPanel.add(animatedImages);
settingsPanel.add(unlimitedLevels);
settingsPanel.add(unlimitedLives);
JPanel predefinedPanel = createBorderedPanel("Predefined game settings");
predefinedPanel.setLayout(new GridLayout(3,1));
JButton easyButton = createImageButton("EasyButton.gif", EASY);
JButton defaultButton = createImageButton("DefaultButton.gif", DEFAULT);
JButton hardButton = createImageButton("HardButton.gif", HARD);
predefinedPanel.add(easyButton);
predefinedPanel.add(defaultButton);
predefinedPanel.add(hardButton);
JPanel comboPanel = new JPanel(new GridLayout(1,2));
comboPanel.add(predefinedPanel);
comboPanel.add(settingsPanel);
everything.add(bombsPanel);
everything.add(rangePanel);
everything.add(freqPanel);
everything.add(minePanel);
everything.add(comboPanel);
// apparantly these need to be separate panels...
JPanel dividerPanel = new JPanel();
JPanel dividerPanel2 = new JPanel();
JPanel dividerPanel3 = new JPanel();
JPanel dividerPanel4 = new JPanel();
this.setLayout(new BorderLayout());
this.add(dividerPanel, BorderLayout.WEST);
this.add(dividerPanel2, BorderLayout.EAST);
this.add(dividerPanel3, BorderLayout.SOUTH);
this.add(dividerPanel4, BorderLayout.NORTH);
this.add(everything, BorderLayout.CENTER);
}
/**
* Initialize the predefined Settings.
*
* Creation date: (10/27/01 11:20:00 PM)
*/
protected void initializeSettings() {
currentSettings = new GameSettings(MazeDomain.getInstance().getGameSettings());
easySettings = new GameSettings();
easySettings.load("easy.properties");
hardSettings = new GameSettings();
hardSettings.load("hard.properties");
defaultSettings = new GameSettings();
defaultSettings.load("default.properties");
}
/**
* Set the current game settings.
*
* Creation date: (10/28/01 1:23:14 PM)
*/
public void setCurrentSettings(GameSettings gameSettings) {
currentSettings = new GameSettings(gameSettings);
copyFromCurrentSettings();
}
}

View File

@ -0,0 +1,325 @@
package a2geek.games.mousemaze2001;
import java.io.*;
import java.awt.image.*;
import java.net.*;
import java.awt.*;
import javax.swing.*;
import a2geek.games.mousemaze2001.images.*;
/**
* Insert the type's description here.
*
* Creation date: (10/16/01 10:28:58 PM)
* @author: <a href='mailto:greener@charter.net'>Rob Greene</a>
* @version: RJG 10/31/2001 22:12:32
*/
public class IntroPanel extends JPanel {
private static IntroPanel instance = new IntroPanel();
private String[] imageNames = {
"OriginalMouseMazeLogo.gif",
"OriginalMouseMazeHelp.gif",
"OriginalMouseMazeGameShot.gif",
"OriginalMouseMazeWin.gif"
};
private Image[] scaledImages;
private int ticker;
private int stage;
private String[] story = {
"A long time ago,",
"when life was much different,",
"I wrote my first game called...",
"",
"&1",
"",
"",
"This a rewrite.",
"",
"",
"The Apple ][,",
"simple graphics,",
"small computers,",
"All Gone!",
"",
"",
"The original help screen:",
"&2",
"",
"A game in progress:",
"&3",
"",
"The winners' screen:",
"&4"
};
private Image marquee;
private Thread creationThread;
/**
* IntroPanel constructor comment.
*/
protected IntroPanel() {
super();
initialize();
}
public static IntroPanel getInstance() {
return instance;
}
protected int getMaxStage() {
return 2;
}
public void incrementTicker() {
ticker++;
}
private void initialize() {
setMinimumSize(new Dimension(560,384));
setMaximumSize(new Dimension(560*2,384*2));
setPreferredSize(new Dimension(560,384));
// load original images
Image originalImages[] = new Image[imageNames.length];
ImageManager imageManager = ImageManager.getInstance();
for (int i=0; i<imageNames.length; i++) {
originalImages[i] = imageManager.getImage(imageNames[i]);
}
// create scaled images (except #0)
MediaTracker tracker = new MediaTracker(this);
scaledImages = new Image[originalImages.length];
for (int i=0; i<originalImages.length; i++) {
Image scaled = originalImages[i];
int width = scaled.getWidth(null) / 2;
if (i > 0) {
scaled = scaled.getScaledInstance(width, -1, Image.SCALE_FAST);
}
tracker.addImage(scaled, i);
scaledImages[i] = scaled;
}
try {
tracker.waitForAll();
} catch (InterruptedException ex) {
}
}
/**
* This method will layout the marquee on the given grapics context - which can be
* the screen as well as an off-screen image.
*
* Creation date: (10/19/01 11:16:17 PM)
*/
protected int layoutMarquee(Image layoutImage) {
Graphics g = layoutImage.getGraphics();
Font font = new Font(g.getFont().getFontName(), Font.BOLD, 20);
g.setFont(font);
FontMetrics metrics = g.getFontMetrics();
int fontHeight = metrics.getHeight();
int lines = story.length;
int screenHeight = layoutImage.getHeight(null);
int screenWidth = layoutImage.getWidth(null);
g.setColor(Color.black);
g.fillRect(0,0,screenWidth,screenHeight);
int y = fontHeight + 10; // just a buffer
for (int i=0; i<lines; i++) {
String line = story[i];
if (line.startsWith("&")) {
int shape = Integer.parseInt(line.substring(1))-1;
if (shape >= 0 && shape < scaledImages.length) {
Image image = scaledImages[shape];
int shapeWidth = image.getWidth(null);
int shapeHeight = image.getHeight(null);
int x = (screenWidth - shapeWidth) / 2;
int yPos = y - fontHeight+10;
g.setColor(Color.blue);
g.fillRoundRect(x-5,yPos-5,shapeWidth+10,shapeHeight+10,5,5);
g.drawImage(image,x,yPos,null);
y+= shapeHeight+10;
}
} else {
int stringWidth = metrics.stringWidth(line);
int x = (screenWidth - stringWidth) / 2;
g.setColor(Color.lightGray);
g.drawString(line, x, y);
y+= fontHeight;
}
}
return y + 10;
}
private void nextStage() {
stage++;
if (stage >= getMaxStage()) {
stage = 0;
}
resetTicker();
}
public void paint(Graphics g) {
Font oldFont = g.getFont();
int screenHeight = getHeight();
int screenWidth = getWidth();
g.setColor(Color.black);
g.fillRect(0,0,screenWidth,screenHeight);
switch (stage) {
case 0: paintMarquee(g);
break;
case 1: paintSectionTwo(g);
break;
}
g.setFont(oldFont); // not sure if this needs to be done..
}
/**
* Paint the scrolling marquee.
* The marquee image creation is placed here since the initialize method apparantly
* cannot create a Graphics object from an Image; thus the marquee cannot be rendered
* from the constructor. The marquee image itself is laid out twice - once to get the
* height (allows it to remain somewhat dynamic) and then to generate the real image.
* The rest of the logic here is just to draw the image on the physical screen.
*
* Creation date: (10/19/01 11:13:58 PM)
*/
public void paintMarquee(Graphics g) {
if (marquee == null) {
if (creationThread == null) {
creationThread = new Thread() {
public void run() {
int width = 500;
int height = 800;
Image layoutImage = createImage(width,height);
height = layoutMarquee(layoutImage);
Image marqueeTemp = createImage(width, height);
layoutMarquee(marqueeTemp);
marquee = marqueeTemp;
resetTicker();
};
};
creationThread.setDaemon(true);
creationThread.start();
}
}
int screenHeight = getHeight();
int screenWidth = getWidth();
if (marquee == null) {
String message = "Please wait...";
Font font = new Font(g.getFont().getFontName(), Font.BOLD, 20);
g.setFont(font);
FontMetrics metrics = g.getFontMetrics();
int fontHeight = metrics.getHeight();
int stringWidth = metrics.stringWidth(message);
int x = (screenWidth - stringWidth) / 2;
int y = (screenHeight - fontHeight) / 2;
g.setColor(Color.green);
g.drawString(message, x, y);
} else {
int y = screenHeight - ticker;;
int shapeWidth = marquee.getWidth(null);
int shapeHeight = marquee.getHeight(null);
int x = (screenWidth - shapeWidth) / 2;
g.drawImage(marquee,x,y,null);
y+= shapeHeight;
if (y < 0) {
nextStage();
}
}
}
public void paintSectionTwo(Graphics g) {
Font font = new Font(g.getFont().getFontName(), Font.BOLD, 20);
g.setFont(font);
g.setColor(Color.blue);
FontMetrics metrics = g.getFontMetrics();
int fontHeight = metrics.getHeight();
int fontAscent = metrics.getAscent();
int screenHeight = getHeight();
int screenWidth = getWidth();
int y = (screenHeight - fontHeight*8) / 2;
String title = "Controlling Mouse Maze";
int stringWidth = metrics.stringWidth(title);
g.drawString(title, (screenWidth - stringWidth) / 2, y);
int saveY = y;
int x;
String[] keys;
for (int z=0; z<2; z++) {
if (z == 0) {
y = saveY;
x = (screenWidth / 4);
title = "To Shoot:";
keys = new String[] { "Q", "W", "E", "A", null, "D", "Z", "X", "C" };
} else {
y = saveY;
x= (screenWidth / 2);
title = "To Move:";
keys = new String[] { "Home", "Up", "PgUp", "Left", null, "Right", "End", "Down", "PgDn" };
}
g.setColor(Color.blue);
y+= fontHeight * 2;
g.drawString(title, x, y);
y+= fontHeight;
int maxWidth = 0;
for (int i=0; i<keys.length; i++) {
String key = keys[i];
if (key != null) {
int width = metrics.stringWidth(key);
if (width > maxWidth) maxWidth = width;
}
}
int padding = 6;
for (int i=0; i<keys.length; i++) {
String key = keys[i];
if (key != null) {
int x0 = x + (i%3)*(maxWidth + padding*2);
g.setColor(new Color(0xafafaf));
g.fillRoundRect(x0-padding,y-padding,maxWidth+padding,fontHeight+padding,padding*2,padding*2);
g.setColor(Color.white);
g.drawRoundRect(x0-padding,y-padding,maxWidth+padding,fontHeight+padding,padding*2,padding*2);
g.setColor(Color.black);
int width = metrics.stringWidth(key);
x0 += (maxWidth - width) / 2;
g.drawString(key, x0-(padding/2), y+fontAscent-(padding/2));
if (i%3 == 2) {
y+= fontHeight + padding*2;
}
}
}
}
y+= fontHeight;
g.setColor(Color.blue);
title = "Press Escape to end game";
stringWidth = metrics.stringWidth(title);
g.drawString(title, (screenWidth - stringWidth) / 2, y);
y+= fontHeight;
title = "Press 'P' to pause the game";
stringWidth = metrics.stringWidth(title);
g.drawString(title, (screenWidth - stringWidth) / 2, y);
if (ticker > 1000) {
nextStage();
}
}
public void resetTicker() {
ticker= 0;
}
}

View File

@ -0,0 +1,138 @@
package a2geek.games.mousemaze2001;
import java.awt.*;
import javax.swing.*;
import a2geek.games.mousemaze2001.domain.*;
import a2geek.games.mousemaze2001.mazeobjects.*;
/**
* Insert the type's description here.
*
* Creation date: (10/11/01 10:13:35 PM)
* @author: <a href='mailto:greener@charter.net'>Rob Greene</a>
* @version: RJG 10/31/2001 22:12:32
*/
public class MazeGridPanel extends JPanel {
private int gridWidth = 14;
private int gridHeight = 9;
// the following keep an aspect ratio of 1.33333:1 for w:h
private int minCellHeight = 16;
private int minCellWidth = 15;
private int prefCellWidth = 32;
private int prefCellHeight = 30;
private int maxCellWidth = 64;
private int maxCellHeight = 60;
/**
* MazeGridPanel constructor comment.
*/
public MazeGridPanel() {
super();
initialize();
}
/**
* MazeGridPanel constructor comment.
* @param layout java.awt.LayoutManager
*/
public MazeGridPanel(java.awt.LayoutManager layout) {
super(layout);
initialize();
}
/**
* MazeGridPanel constructor comment.
* @param layout java.awt.LayoutManager
* @param isDoubleBuffered boolean
*/
public MazeGridPanel(java.awt.LayoutManager layout, boolean isDoubleBuffered) {
super(layout, isDoubleBuffered);
initialize();
}
/**
* MazeGridPanel constructor comment.
* @param isDoubleBuffered boolean
*/
public MazeGridPanel(boolean isDoubleBuffered) {
super(isDoubleBuffered);
initialize();
}
protected void initialize() {
setMinimumSize(new Dimension(gridWidth * minCellWidth, gridHeight * minCellHeight));
setMaximumSize(new Dimension(gridWidth * maxCellWidth, gridHeight * maxCellHeight));
setPreferredSize(new Dimension(gridWidth * prefCellWidth, gridHeight * prefCellHeight));
}
public void paint(Graphics g) {
//System.out.println(new java.util.Date() + " - painting screen");
int screenWidth = getWidth();
int screenHeight = getHeight();
g.setColor(Color.black);
g.fillRect(0, 0, screenWidth, screenHeight);
g.setColor(Color.white);
screenWidth -= 2;
screenHeight -= 2;
for (int x=0; x <= gridWidth; x++) {
int xPos = (screenWidth * x) / gridWidth;
g.drawLine(xPos, 0, xPos, screenHeight);
xPos++;
g.drawLine(xPos, 0, xPos, screenHeight);
}
for (int y=0; y <= gridHeight; y++) {
int yPos = (screenHeight * y) / gridHeight;
g.drawLine(0, yPos, screenWidth, yPos);
yPos++;
g.drawLine(0, yPos, screenWidth, yPos);
}
MazeDomain maze = MazeDomain.getInstance();
if (maze.getMap() == null) return;
int cellWidth = screenWidth / gridWidth - 2;
int cellHeight = screenHeight / gridHeight - 2;
for (int x=0; x<maze.getMapWidth(); x++) {
int x0 = (screenWidth * x) / gridWidth + 2;
for (int y=0; y<maze.getMapHeight(); y++) {
int y0 = (screenHeight * y) / gridHeight + 2;
MazeObject object = maze.getMazeObject(x,y);
if (object != null) {
Graphics cell = g.create(x0,y0,cellWidth+1,cellHeight+1);
if (object instanceof AnimatedRobot) {
AnimatedRobot robot = (AnimatedRobot) object;
if (robot.isAlive() == false) continue;
}
object.paint(cell);
}
}
}
String message = maze.getPauseMessage();
if (maze.isPaused()) {
//System.out.println(new java.util.Date() + " - showing message = " + message);
Font font = new Font(g.getFont().getName(), Font.BOLD, 20);
g.setFont(font);
FontMetrics metrics = g.getFontMetrics();
int fontHeight = metrics.getAscent();
int stringWidth = metrics.stringWidth(message);
int xText = (screenWidth - stringWidth) / 2;
int yText = (screenHeight - fontHeight) / 2;
int xBox = xText - 15;
int yBox = yText - 15;
int xWidth = stringWidth + 30;
int yHeight = fontHeight + 30;
g.setColor(Color.blue);
g.fillRoundRect(xBox,yBox,xWidth,yHeight,15,15);
g.setColor(Color.white);
g.drawRoundRect(xBox,yBox,xWidth,yHeight,15,15);
g.setColor(Color.white);
g.drawString(message, xText, yText + fontHeight);
}
}
}

View File

@ -0,0 +1,42 @@
package a2geek.games.mousemaze2001;
import java.awt.*;
import javax.swing.*;
import a2geek.games.mousemaze2001.domain.*;
import a2geek.games.mousemaze2001.mazeobjects.*;
/**
* Display the number of lives graphically.
*
* Creation date: (10/27/01 12:42:11 AM)
* @author: <a href='mailto:greener@charter.net'>Rob Greene</a>
* @version: RJG 10/27/2001 01:02:48
*/
public class MouseLivesPanel extends JPanel {
InvertedMouse mouse = new InvertedMouse();
/**
* MouseLivesPanel constructor comment.
*/
public MouseLivesPanel() {
super();
}
/**
* Display the number of mouse lives.
*
* Creation date: (10/27/01 12:43:13 AM)
*/
public void paint(Graphics g) {
super.paint(g);
Rectangle rect = g.getClipBounds();
int lives = MazeDomain.getInstance().getLives();
for (int i=0; i<lives; i++) {
int x = mouse.getWidth() * i;
int y = ((int)rect.getHeight() - mouse.getHeight()) / 2;
Graphics mg = g.create(x,y,mouse.getWidth(),mouse.getHeight());
mouse.paint(mg);
}
}
}

View File

@ -0,0 +1,535 @@
package a2geek.games.mousemaze2001;
import java.awt.*;
import javax.swing.*;
import a2geek.games.mousemaze2001.domain.*;
import a2geek.games.mousemaze2001.images.*;
import a2geek.games.mousemaze2001.threads.*;
import java.awt.event.*;
/**
* Mouse Maze 2001!
*
* Creation date: (10/9/01 10:02:39 PM)
* @author: <a href='mailto:greener@charter.net'>Rob Greene</a>
* @version: RJG 11/05/2001 22:35:58
*/
public class MouseMaze2001 extends JFrame implements ActionListener, KeyListener, DomainListener {
private static MouseMaze2001 instance = new MouseMaze2001();
private static final String OK = "ok";
private static final String CANCEL = "cancel";
private static final String START = "start";
private static final String QUIT = "quit";
private static final String PREFERENCES = "preferences";
private JPanel infoPanel = null;
private CardLayout infoCardPages = null;
private JPanel infoCardPanel = null;
private JPanel logoPanel = null;
private JPanel controlPanel = null;
private JPanel gameInfoPanel = null;
private JPanel gameCardPanel = null;
private MouseLivesPanel mouseLivesPanel = null;
private JLabel robotsCountLabel = null;
private JLabel levelCountLabel = null;
private IntroPanel introPanel = null;
private MazeGridPanel mazePanel = null;
private CardLayout gameCardPages = null;
private IntroThread introThread = new IntroThread();
private GameThread gameThread = new GameThread();
private RepaintThread repaintThread = null;
private JPanel preferencesControlPanel = null;
private GameSettingsPanel gameSettingsPanel = null;
private ImageManager imageManager = null;
/**
* MouseMaze2001Layout constructor comment.
*/
public MouseMaze2001() {
Package pkg = getClass().getPackage();
String title = pkg.getImplementationTitle();
if (title == null) {
title = "Mouse Maze 2001";
}
String version = pkg.getImplementationVersion();
if (version == null) {
version = "PROTOTYPE";
}
setTitle(String.format("%s - %s", title, version));
setResizable(false);
setSize(500,200);
centerWindow();
ImageManager.getInstance(); // toggle image loading
getContentPane().add(new Component() {
public void paint(Graphics g) {
String message = "Please wait, loading images...";
int screenHeight = getHeight();
int screenWidth = getWidth();
Font font = new Font(g.getFont().getFontName(), Font.BOLD, 20);
g.setFont(font);
FontMetrics metrics = g.getFontMetrics();
int fontHeight = metrics.getHeight();
int stringWidth = metrics.stringWidth(message);
int x = (screenWidth - stringWidth) / 2;
int y = (screenHeight - fontHeight) / 2 + fontHeight;
g.setColor(Color.black);
g.fillRect(0,0,screenWidth,screenHeight);
g.setColor(Color.green);
g.drawString(message, x, y);
}
});
Thread thread = new Thread() {
public void run() {
ImageManager imageManager = ImageManager.getInstance();
while (imageManager.isDoneLoading() == false) {
try {
sleep(100);
} catch (InterruptedException ex) {
}
}
layoutScreen();
}
};
thread.start();
}
/**
* Invoked when an action occurs.
*/
public void actionPerformed(ActionEvent e) {
String command = START; // default if called from elsewhere (yup, a hack)
MazeDomain domain = MazeDomain.getInstance();
if (e != null) {
command = e.getActionCommand();
}
if (START.equals(command)) {
if (introThread.isPaused()) {
gameThread.suspend();
introThread.resume();
gameCardPages.show(gameCardPanel, getPreviewPanelName());
infoCardPages.show(infoCardPanel, getPreviewPanelName());
domain.clear();
} else {
if (!gameThread.isRunning()) {
gameThread.start(); // yes, a total hack
gameThread.suspend();
domain.addDomainListener(this);
}
introThread.suspend();
gameThread.resume();
gameCardPages.show(gameCardPanel, getPlayPanelName());
infoCardPages.show(infoCardPanel, getPlayPanelName());
mazePanel.requestFocus();
domain.newGame();
if (domain.getGameSettings().isAnimatedImages()) {
AnimationThread animationThread = new AnimationThread();
animationThread.start();
}
}
} else if (PREFERENCES.equals(command)) {
infoCardPages.show(infoCardPanel, getPreferencesPanelName());
gameCardPages.show(gameCardPanel, getPreferencesPanelName());
gameSettingsPanel.setCurrentSettings(MazeDomain.getInstance().getGameSettings());
} else if (OK.equals(command)) {
domain.setGameSettings(gameSettingsPanel.getCurrentSettings());
infoCardPages.show(infoCardPanel, getPreviewPanelName());
gameCardPages.show(gameCardPanel, getPreviewPanelName());
} else if (CANCEL.equals(command)) {
infoCardPages.show(infoCardPanel, getPreviewPanelName());
gameCardPages.show(gameCardPanel, getPreviewPanelName());
}
}
/**
* Center the current window.
*
* Creation date: (10/31/01 10:02:47 PM)
*/
public void centerWindow() {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension windowSize = getSize();
Point point = new Point();
point.x = (screenSize.width - windowSize.width) / 2;
point.y = (screenSize.height - windowSize.height) / 2;
setLocation(point);
}
protected void createControlPanel() {
JButton startButton = createImageButton("StartButton.gif", START);
JButton preferencesButton = createImageButton("PreferencesButton.gif", PREFERENCES);
JPanel topButtons = new JPanel(new GridLayout(2,1));
topButtons.add(startButton);
topButtons.add(preferencesButton);
JButton quitButton = createImageButton("QuitButton.gif", QUIT, new WindowCloseAdapter());
controlPanel = new JPanel(new BorderLayout());
controlPanel.add(topButtons, BorderLayout.NORTH);
controlPanel.add(quitButton, BorderLayout.SOUTH);
controlPanel.setBackground(Color.white);
}
protected void createGameInfoPanel() {
JLabel aHackForTheDamnFontName = new JLabel();
String theDamnFontName = aHackForTheDamnFontName.getFont().getName();
Font font = new Font(theDamnFontName, Font.BOLD, 20);
JLabel miceText = new JLabel("Mice:");
miceText.setFont(font);
miceText.setForeground(Color.blue);
JLabel levelText = new JLabel("Level:");
levelText.setFont(font);
levelText.setForeground(Color.blue);
JLabel robotsText = new JLabel("Robots:");
robotsText.setFont(font);
robotsText.setForeground(Color.blue);
mouseLivesPanel = new MouseLivesPanel();
mouseLivesPanel.setBackground(Color.white);
levelCountLabel = new JLabel("0");
levelCountLabel.setFont(font);
levelCountLabel.setForeground(Color.blue);
robotsCountLabel = new JLabel("0");
robotsCountLabel.setFont(font);
robotsCountLabel.setForeground(Color.blue);
gameInfoPanel = new JPanel(new GridLayout(3,2));
gameInfoPanel.add(miceText);
gameInfoPanel.add(mouseLivesPanel);
gameInfoPanel.add(levelText);
gameInfoPanel.add(levelCountLabel);
gameInfoPanel.add(robotsText);
gameInfoPanel.add(robotsCountLabel);
gameInfoPanel.setBackground(Color.white);
}
/**
* Create a standard image button.
*
* Creation date: (10/27/01 3:05:07 PM)
*/
protected JButton createImageButton(String resourceName, String commandString) {
return createImageButton(resourceName, commandString, this);
}
/**
* Create a standard image button.
*
* Creation date: (10/27/01 3:05:07 PM)
*/
protected JButton createImageButton(String resourceName, String commandString, ActionListener actionListener) {
JButton button = new JButton(new ImageIcon(imageManager.getImage(resourceName)));
button.setActionCommand(commandString);
button.setBackground(Color.white);
button.addActionListener(actionListener);
return button;
}
protected void createInfoPanel() {
createLogoPanel();
createControlPanel();
createGameInfoPanel();
createPreferencesControlPanel();
infoCardPages = new CardLayout();
infoCardPanel = new JPanel(infoCardPages);
infoCardPanel.add(getPreviewPanelName(), controlPanel);
infoCardPanel.add(getPlayPanelName(), gameInfoPanel);
infoCardPanel.add(getPreferencesPanelName(), preferencesControlPanel);
JPanel nestedPanel = new JPanel(new BorderLayout());
nestedPanel.setBackground(Color.white);
nestedPanel.add(logoPanel, BorderLayout.NORTH);
nestedPanel.add(infoCardPanel, BorderLayout.CENTER);
// apparantly these need to be separate panels...
JPanel dividerPanel = new JPanel();
dividerPanel.setBackground(Color.white);
JPanel dividerPanel2 = new JPanel();
dividerPanel2.setBackground(Color.white);
JPanel dividerPanel3 = new JPanel();
dividerPanel3.setBackground(Color.white);
JPanel dividerPanel4 = new JPanel();
dividerPanel4.setBackground(Color.white);
Dimension size = new Dimension(logoPanel.getWidth(), -1);
infoPanel = new JPanel(new BorderLayout());
infoPanel.setMaximumSize(size);
infoPanel.add(dividerPanel, BorderLayout.WEST);
infoPanel.add(dividerPanel2, BorderLayout.EAST);
infoPanel.add(dividerPanel3, BorderLayout.SOUTH);
infoPanel.add(dividerPanel4, BorderLayout.NORTH);
infoPanel.add(nestedPanel, BorderLayout.CENTER);
}
protected void createLogoPanel() {
logoPanel = new JPanel(new FlowLayout());
ImageCanvas logo = new ImageCanvas("MouseMazeLogo.gif");
logo.setColor(Color.white);
logoPanel.add(logo);
logoPanel.setBackground(Color.white);
}
protected void createPreferencesControlPanel() {
JButton okButton = createImageButton("OkButton.gif", OK);
JButton cancelButton = createImageButton("CancelButton.gif", CANCEL);
preferencesControlPanel = new JPanel(new BorderLayout());
preferencesControlPanel.add(okButton, BorderLayout.NORTH);
preferencesControlPanel.add(cancelButton, BorderLayout.SOUTH);
preferencesControlPanel.setBackground(Color.white);
}
/**
* Act upon domain changed events.
*
* Creation date: (10/22/01 10:06:09 PM)
*/
public void domainChanged(DomainEvent domainEvent) {
String event = domainEvent.getEvent();
MazeDomain domain = MazeDomain.getInstance();
if ("terminate".equals(event)) {
actionPerformed(null); // cheap game over
}
if ("robotShot".equals(event) || "newGame".equals(event)) {
robotsCountLabel.setText(Integer.toString(domain.getKills()));
robotsCountLabel.repaint();
}
if ("mouseKilled".equals(event)) {
mouseLivesPanel.repaint();
GameDelayThread thread = new GameDelayThread("Ouch!",500);
thread.start();
}
if ("level".equals(event)) {
//GameDelayThread thread = new GameDelayThread("Welcome to level " + domain.getLevel() + "!",1000);
//thread.start();
levelCountLabel.setText(Integer.toString(domain.getLevel()));
levelCountLabel.repaint();
}
if ("newGame".equals(event)) {
GameDelayThread thread = new GameDelayThread("Good Luck!",500);
thread.start();
levelCountLabel.setText(Integer.toString(domain.getLevel()));
levelCountLabel.repaint();
mouseLivesPanel.repaint();
}
if ("gameOver".equals(event)) {
GameDelayThread thread = new GameDelayThread("Game Over",2000);
thread.start();
mouseLivesPanel.repaint();
} else if ("gameWon".equals(event)) {
GameDelayThread thread = new GameDelayThread("You have won Mouse Maze!",3000);
thread.start();
}
repaintNeeded();
}
public static MouseMaze2001 getInstance() {
return instance;
}
protected String getPlayPanelName() {
return "play";
}
protected String getPreferencesPanelName() {
return "preferences";
}
protected String getPreviewPanelName() {
return "preview";
}
/**
* Invoked when a key has been pressed.
*/
public void keyPressed(KeyEvent e) {
switch (e