import java.applet.*; import java.awt.*; ///////////////////////////////////////////////////////////////// public class GameManager extends Applet implements Runnable { // animation variables static final int REFRESH_RATE = 80; // in ms Thread animation; Graphics offscreen; Image image; // game variables used when playing static final int UFO_VALUE = 130; // 130 points static final int MAX_LANDED = 5; // at most 5 aliens // can land static final int MAX_LEVEL = 9; // static final int MAX_ENERGY = 113; // private int score; private int numLanded; // num of aliens landed Image ufoImages[] = new Image[6]; // 6 ufo Images Image attackImages[] = new Image[6]; // 6 attack Images Image explodeImages[] = new Image[4];// 4 explode Images Image gunImage; // gun image GunManager gm; // refers to gun manager UFOManager um; // refers to ufo manager // state of game private boolean playing; // if game playing private int screen; // which screen to show static final int INTRO = 0; // intro screen static final int GAME_OVER = 1; // game over screen AudioClip expsound; // explosion sound // fonts Font smallFont = new Font("Helvetica",Font.BOLD,12); Font mediumFont = new Font("Helvetica",Font.BOLD,14); Font bigFont = new Font("Helvetica",Font.BOLD,18); FontMetrics fm; // use to center string int width, height; // applet dimensions // strings String scoreString = "Score: "; String ufoLandedString = "UFOs Landed: "; String gameOverString = " GAME OVER "; String clickString = "Shift-Click to Continue"; String alienLandingString = "Alien Landing"; int stringWidth; String introString[] = new String[8]; public void init() { showStatus("Loading Images -- WAIT!"); setBackground(Color.black); // applet background width = bounds().width; // set applet dimensions height = bounds().height; loadImages(); try { expsound = getAudioClip(getCodeBase(),"explosion.au"); } catch (Exception e) { } // expsound.loop(); um = new UFOManager(2,MAX_LEVEL,width,height,ufoImages, attackImages,explodeImages, this,expsound); gm = new GunManager(MAX_ENERGY,5,width,height,gunImage, um.getUFO(), this); um.initialize(gm); // initialize gun parameters playing = false; // not playing screen = INTRO; // show intro screen image = createImage(width,height); // make offscreen buffer offscreen = image.getGraphics(); offscreen.setFont(bigFont); // font for intro fm = offscreen.getFontMetrics(bigFont); // font metrics stringWidth = fm.stringWidth(alienLandingString); introString[0] = "You are Humanity's last hope!"; introString[1] = "Destroy the green Alien Landers"; introString[2] = "by using the Mouse to Move"; introString[3] = "your Missile Launcher. Click"; introString[4] = "to Fire Missile. If 5 Aliens"; introString[5] = "Land, or Energy Runs Out,"; introString[6] = "Humans will be Eaten Alive!"; introString[7] = "Click to start Game"; } // load all images used in game public void loadImages() { MediaTracker t = new MediaTracker(this); gunImage = getImage(getCodeBase(),"image/gun.gif"); t.addImage(gunImage,0); for (int i=0; i