📄 seafox.java
字号:
// Source File Name: Seafox.java
import java.applet.Applet;
import java.applet.AudioClip;
import java.awt.*;
import java.util.Random;
public class Seafox extends Applet //采用Runnable多线程接口
implements Runnable {
int m_nKeyBuffer[];
Thread m_threadAnim;
boolean m_bInitialized;
static Random m_random = new Random();
public static int m_nMouseX;
public static int m_nMouseY;
public static boolean m_bMouseInWindow; //定义控制按钮
public static boolean m_bButtonDown;
public static boolean m_bSpacebarPressed;
final int m_nHistoryFrames = 10;
public static int m_nFrameNumber;
long m_lTime[];
public static long m_lLatestTime;
public static double m_dSecondsPerFrame;
MediaTracker m_mediaTracker;
Image m_imageLoading;
public static int m_nWindowWidth;
public static int m_nWindowHeight;
public static int m_nPlayfieldWidth;
public static int m_nPlayfieldHeight;
public static Font m_fontScorePopup = new Font("Helvetica", 1, 24);
public static final int SURFACE_HEIGHT = 60;
public static final Color SURFACE_COLOR = new Color(0, 0, 128);
public static final Color UNDERWATER_COLOR = new Color(0, 0, 64);
Image m_bufferPlayfield;
Image m_bufferSurface;
Image m_imageWater;
boolean m_bSoundEffectsOn;
AudioClip m_acBigExplosion;
AudioClip m_acLittleExplosion;
AudioClip m_acFireTorpedo;
AudioClip m_acOutOfTorpedoes;
AudioClip m_acClank;
AudioClip m_acSupplies;
AudioClip m_acShark;
AudioClip m_acSplash;
public static boolean m_bPlayBigExplosion;
public static boolean m_bPlayLittleExplosion;
public static boolean m_bPlayFireTorpedo;
public static boolean m_bPlayOutOfTorpedoes;
public static boolean m_bPlayClank;
public static boolean m_bPlaySupplies;
public static boolean m_bPlayShark;
public static boolean m_bPlaySplash;
public static final int SCOREBAR_HEIGHT = 20;
static final int SCOREBAR_BASELINE = 16;
static final int SCOREBAR_FONT_SIZE = 14;
static final int SCOREBAR_X_MARGIN = 4;
static final int SCOREBAR_ZONES = 5;
static final int SCOREBAR_MISSION_ZONE = 0;
static final int SCOREBAR_SHIPS_SUNK_ZONE = 1;
static final int SCOREBAR_SCORE_ZONE = 2;
static final int SCOREBAR_TORPEDO_ZONE = 3;
static final int SCOREBAR_FUEL_ZONE = 4;
static final Color SCOREBAR_BACKGROUND_COLOR = new Color(0, 43, 128);
static final Color SCOREBAR_CAPTION_COLOR = new Color(48, 128, 255);
static final Color SCOREBAR_VALUE_COLOR = new Color(149, 184, 255);
Image m_bufferScorebar;
Font m_fontScorebar;
int m_nScorebarZoneCaptionWidth[];
int m_nScorebarZoneDataX[];
int m_nScorebarZoneDataWidth[];
int m_nScorebarZoneValue[];
public static Player m_player = new Player(); // 定义类变量
public static VerticalTorpedo m_verticalTorpedo = new VerticalTorpedo();
public static HorizontalTorpedo m_horizontalTorpedo = new HorizontalTorpedo();
public static CapitalShip m_capitalShip[] = new CapitalShip[10];
public static HospitalShip m_hospitalShip[] = new HospitalShip[3];
public static Destroyer m_destroyer[] = new Destroyer[3];
public static DepthCharge m_depthCharge[] = new DepthCharge[3];
public static EnemySub m_enemySub[] = new EnemySub[3];
public static EnemyTorpedo m_enemyTorpedo[] = new EnemyTorpedo[3];
public static MagneticMine m_magneticMine[] = new MagneticMine[3];
public static SupplySub m_supplySub = new SupplySub();
public static Dolphin m_dolphin = new Dolphin();
public static Package m_package = new Package();
public static KillerFish m_killerFish = new KillerFish();
public static int m_nScore;
public static int m_nMission = 1;
public static int m_nSubsLeft = 3;
public static int m_nTimesPlayed;
public static boolean m_bMissionComplete;
public static boolean m_bDisplayMissionTitle;
public static boolean m_bGameOver;
Font m_fontMessage;
Color m_colorMessage;
String m_stringStart;
int m_nXstartString;
int m_nYstartString;
String m_stringOutOfFuel;
int m_nXoutOfFuel;
int m_nYoutOfFuel;
String m_stringGameOver;
int m_nXgameOver;
int m_nYgameOver;
String m_stringMissionTitle;
int m_nXmissionTitle;
int m_nYmissionTitle;
String m_stringMissionComplete;
int m_nXmissionComplete;
int m_nYmissionComplete;
String m_stringSubsLeft[];
int m_nXsubsLeft[];
int m_nYsubsLeft;
private void MissionInit() { //发射初始化
CapitalShip.m_nShipsSunk = 0;
int i = 0;
do { //随机确定商船位置
m_capitalShip[i].m_ndxImage = (m_random.nextInt() & 0x7fffffff) % 4;
m_capitalShip[i].m_nStatus = 0;
m_capitalShip[i].m_bSinkable = false;
m_capitalShip[i].m_dXoffset = ((double)i + 0.69999999999999996D * (m_random.nextDouble() - 0.5D)) * (double)CapitalShip.m_nXspacing;
} while(++i < 10);
i = 0;
do //随机确定救护位置
m_hospitalShip[i].m_dXoffset = ((double)i + 0.69999999999999996D * (m_random.nextDouble() - 0.5D)) * (double)HospitalShip.m_nXspacing;
while(++i < 3);
switch(m_nMission) {
case 1: // '\001'
Destroyer.m_nShipLimit = 0;
DepthCharge.m_nChargeLimit = 0;
EnemySub.m_nSubLimit = 0;
EnemyTorpedo.m_nTorpedoLimit = 0;
MagneticMine.m_nMineLimit = 0;
break;
case 2: // '\002'
Destroyer.m_nShipLimit = 3;
DepthCharge.m_nChargeLimit = 3;
EnemySub.m_nSubLimit = 0;
EnemyTorpedo.m_nTorpedoLimit = 0;
MagneticMine.m_nMineLimit = 0;
break;
case 3: // '\003'
Destroyer.m_nShipLimit = 3;
DepthCharge.m_nChargeLimit = 3;
EnemySub.m_nSubLimit = 3;
EnemyTorpedo.m_nTorpedoLimit = 0;
MagneticMine.m_nMineLimit = 0;
break;
case 4: // '\004'
Destroyer.m_nShipLimit = 3;
DepthCharge.m_nChargeLimit = 3;
EnemySub.m_nSubLimit = 3;
EnemyTorpedo.m_nTorpedoLimit = 3;
MagneticMine.m_nMineLimit = 0;
break;
case 5: // '\005'
Destroyer.m_nShipLimit = 3;
DepthCharge.m_nChargeLimit = 3;
EnemySub.m_nSubLimit = 3;
EnemyTorpedo.m_nTorpedoLimit = 3;
MagneticMine.m_nMineLimit = 3;
break;
}
m_stringMissionTitle = new String("Mission " + m_nMission);
m_bDisplayMissionTitle = true;
}
public void start() { //启动线程
if(m_threadAnim == null) {
m_threadAnim = new Thread(this);
m_threadAnim.start();
}
}
public void stop() { //终止线程
if(m_threadAnim != null) {
m_threadAnim.stop();
m_threadAnim = null;
}
}
public boolean keyUp(Event event, int i) {
if(i == 32)
m_bSpacebarPressed = false;
return true;
}
public boolean mouseExit(Event event, int i, int j) {
m_nMouseX = i;
m_nMouseY = j;
m_bMouseInWindow = false;
m_bButtonDown = false;
return true;
}
public boolean mouseMove(Event event, int i, int j) {
m_nMouseX = i;
m_nMouseY = j;
m_bMouseInWindow = true;
m_bButtonDown = false;
return true;
}
public Seafox() { //构造方法
m_nKeyBuffer = new int[4];
m_lTime = new long[10];
m_mediaTracker = new MediaTracker(this);
m_bSoundEffectsOn = true;
m_nScorebarZoneCaptionWidth = new int[5];
m_nScorebarZoneDataX = new int[5];
m_nScorebarZoneDataWidth = new int[5];
m_nScorebarZoneValue = new int[5];
m_fontMessage = new Font("Helvetica", 1, 20);
m_colorMessage = Color.white;
m_stringStart = new String("Click Here to Start Game");
m_stringOutOfFuel = new String("Out of Fuel");
m_stringGameOver = new String("Game Over");
m_stringMissionTitle = new String("Mission 0");
m_stringMissionComplete = new String("Mission Complete");
m_stringSubsLeft = new String[3];
m_nXsubsLeft = new int[3];
}
public boolean mouseDown(Event event, int i, int j) {
m_nMouseX = i;
m_nMouseY = j;
m_bButtonDown = true;
return true;
}
public boolean keyDown(Event event, int i) {
if(i == 32)
m_bSpacebarPressed = true;
if(i == 113 || i == 81)
m_bSoundEffectsOn = false;
if(i == 115 || i == 83)
m_bSoundEffectsOn = true;
return true;
}
public boolean mouseEnter(Event event, int i, int j) {
m_nMouseX = i;
m_nMouseY = j;
m_bMouseInWindow = true;
return true;
}
public boolean mouseDrag(Event event, int i, int j) {
m_nMouseX = i;
m_nMouseY = j;
m_bMouseInWindow = true;
return true;
}
private boolean UpdateScorebar() { // 更新成绩记录
Graphics g = m_bufferScorebar.getGraphics();
g.setFont(m_fontScorebar);
boolean flag = false;
if(m_nMission != m_nScorebarZoneValue[0]) {
flag = true; //发射数
g.setColor(SCOREBAR_BACKGROUND_COLOR);
g.fillRect(m_nScorebarZoneDataX[0], 0, m_nScorebarZoneDataWidth[0], 20);
g.setColor(SCOREBAR_VALUE_COLOR);
g.drawString(new String("" + m_nMission), m_nScorebarZoneDataX[0], 16);
m_nScorebarZoneValue[0] = m_nMission;
}
if(CapitalShip.m_nShipsSunk != m_nScorebarZoneValue[1]) {
flag = true; //击中商船数
g.setColor(SCOREBAR_BACKGROUND_COLOR);
g.fillRect(m_nScorebarZoneDataX[1], 0, m_nScorebarZoneDataWidth[1], 20);
g.setColor(SCOREBAR_VALUE_COLOR);
g.drawString(new String("" + CapitalShip.m_nShipsSunk), m_nScorebarZoneDataX[1], 16);
m_nScorebarZoneValue[1] = CapitalShip.m_nShipsSunk;
}
if(m_nScore != m_nScorebarZoneValue[2]) { //计分
flag = true;
g.setColor(SCOREBAR_BACKGROUND_COLOR);
g.fillRect(m_nScorebarZoneDataX[2], 0, m_nScorebarZoneDataWidth[2], 20);
g.setColor(SCOREBAR_VALUE_COLOR);
g.drawString(new String("" + m_nScore), m_nScorebarZoneDataX[2], 16);
m_nScorebarZoneValue[2] = m_nScore;
}
if(Player.m_nTorpedoes != m_nScorebarZoneValue[3]) {
flag = true; //剩鱼雷数
g.setColor(SCOREBAR_BACKGROUND_COLOR);
g.fillRect(m_nScorebarZoneDataX[3], 0, m_nScorebarZoneDataWidth[3], 20);
g.setColor(SCOREBAR_VALUE_COLOR);
g.drawString(new String("" + Player.m_nTorpedoes), m_nScorebarZoneDataX[3], 16);
m_nScorebarZoneValue[3] = Player.m_nTorpedoes;
}
if((int)(Player.m_dFuel + 0.5D) != m_nScorebarZoneValue[4]) {
flag = true; //燃料用量
g.setColor(SCOREBAR_BACKGROUND_COLOR);
g.fillRect(m_nScorebarZoneDataX[4], 0, m_nScorebarZoneDataWidth[4], 20);
g.setColor(SCOREBAR_VALUE_COLOR);
g.drawString(new String("" + (int)(Player.m_dFuel + 0.5D) + "%"), m_nScorebarZoneDataX[4], 16);
m_nScorebarZoneValue[4] = (int)(Player.m_dFuel + 0.5D);
}
return flag;
}
private void StartNewGame() {
m_bGameOver = false;
m_bButtonDown = false;
m_bPlayBigExplosion = false;
m_bPlayLittleExplosion = false;
m_bPlayFireTorpedo = false;
m_bPlayOutOfTorpedoes = false;
m_bPlayClank = false;
m_bPlaySupplies = false;
m_bPlaySplash = false;
m_bPlayShark = false;
m_nMission = 1;
m_nSubsLeft = 3;
m_nScore = 0;
m_nTimesPlayed++;
MissionInit();
SubInit();
}
public boolean mouseUp(Event event, int i, int j) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -