/** * @(#)EnemyShips.java 1.0.1 98/12/04 *
* Copyright (C) 1998 David E. Wexler *
* This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. See * license.txt for a full copy of the GNU GPL. *
* This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * USA. *
* To Contact the author send e-mail to vagabond@netdragon.com or send * snailmail to: 511 Bobcat Ct, Punta Gorda, FL 3398. */ import java.applet.Applet; import java.awt.*; import java.io.*; import java.lang.*; import java.net.*; import java.util.*; /** * HighScores - Calls a CGI Script that handles new high scores and * returns Data to be displayed. *
* Sends a request to
* /cgi-bin/high.pl?file=$file&name=$name&s=$score&key=$key
* where $file = getParameter("file"), $name = getParamter("name"),
* $s = your score, and $key = a static variable.
*
*
* @author David Wexler (vagabond@netdragons.com) * @version 1.0.1 * @since Nelzan1.0.1 */ public class HighScores { // A key to be transimited, for security reasons. private static final String key = "ZZZZZZZZZZZZZZZZ"; /** * String Array to hold information on how to play the game. */ String[] instrcut = { "Arrows - Move", "Num Pad - Move", "a = Use Laser", "s = Use Dual Laser", "d = Use Wave", "f = Use Arrow", "space = fire", "p = Pause" }; /** * String Array to hold the top 5 high scores */ String[] highScore = new String[5]; /** * Instance of Applet for callbacks. */ Applet comp; /** * URL we are going to connecte to, saved here in case we need to recover. */ URL dataFile; Font font = new Font("Helvetica", Font.BOLD, 16); FontMetrics fontSize; /** * Creates and instance of HighScores. * * @param c Instance of an Applet, for call backs. */ HighScores(Applet c) { comp = c; fontSize = comp.getFontMetrics(font); } /** * Opens a CGI script with the propper data and downloads the new high * scores. *
* Sends a request to
* /cgi-bin/high.pl?file=$file&name=$name&s=$score&key=$key
* where $file = getParameter("file"), $name = getParamter("name"),
* $s = your score, and $key = a static variable.
*
* @param s Your Score.
*/
public void sendHigh(int s) {
String url = comp.getParameter("host") + "/cgi-bin/high.pl?file=" +
comp.getParameter("file") + "&name=" + comp.getParameter("name") +
"&s=" + s + "&key=" + key;
try {
this.dataFile = new URL(url);
} catch ( MalformedURLException e) {
System.out.println("Bad URL: " + url);
}
String line; // Line Buffer
int c = 0;
try {
URLConnection conn = this.dataFile.openConnection();
conn.connect();
DataInputStream data = new DataInputStream(new BufferedInputStream(conn.getInputStream()));
while((line = data.readLine()) != null) {
highScore[c++] = line;
}
} catch (IOException e) {
System.out.println("IO Error:" + e.getMessage());
}
}
/**
* Paints the data stored in highScore[].
*
* @param g The Graphics to draw to.
*/
public void paint(Graphics g) {
g.setColor(Color.black);
g.drawString("High Scores", 301 - fontSize.stringWidth("High Scores")/2, 131);
g.drawLine(211, 136, 391, 136);
g.setColor(Color.white);
g.drawString("High Scores", 300 - fontSize.stringWidth("High Scores")/2, 130);
g.drawLine(210, 135, 390, 135);
for (int i = 0; i < 5; i++) {
g.setColor(Color.black);
g.drawString(highScore[i], 301 - fontSize.stringWidth(highScore[i])/2, 161+(i*15));
g.setColor(Color.white);
g.drawString(highScore[i], 300 - fontSize.stringWidth(highScore[i])/2, 160+(i*15));
}
}
/**
* Paints the data stored in instrcut[].
*
* @param g The Graphics to draw to.
*/
public void paintInstructions(Graphics g) {
g.setColor(Color.black);
g.drawString("Instructions", 301 - fontSize.stringWidth("Instructions")/2, 111);
g.drawLine(211, 116, 391, 116);
g.setColor(Color.white);
g.drawString("Instructions", 300 - fontSize.stringWidth("High Scores")/2, 110);
g.drawLine(210, 115, 390, 115);
for (int i = 0; i < 8; i++) {
g.setColor(Color.black);
g.drawString(instrcut[i], 301 - fontSize.stringWidth(instrcut[i])/2, 136+(i*15));
g.setColor(Color.white);
g.drawString(instrcut[i], 300 - fontSize.stringWidth(instrcut[i])/2, 135+(i*15));
}
}
}