import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

//import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;


/**
 *
 */
public class SpaceInvaders extends JFrame implements Runnable {


    public static int WIDTH  = 600;//The width of the frame
    public static int HEIGHT = 400;//The height of the frame

    private int gameSpeed = 100;//Try 500

    AlienArmy army = null;

    Ship ship = null;

    private boolean paused = false;

    private int score = 0;

    Graphics offscreen_high;
    BufferedImage offscreen;

    Image backGroundImage = null;
    Image alienImage = null;    
    

    /**
     * This is called a constructor. 
     */
    public SpaceInvaders(String frameTitle) {
        super(frameTitle);

	//backGroundImage = new javax.swing.ImageIcon("red_band.gif").getImage();
	backGroundImage = new javax.swing.ImageIcon("back3.jpg").getImage();

	alienImage = new javax.swing.ImageIcon("alien.jpg").getImage();	

	//Create the ship to fight off the invading army!
	...

	//Create the alien army
	...

	//The ship will be controlled by the mouse
	...
	//WE also want mouse movement not just mouse clicks
	...

	...
 


	...
    }

    /**
     * As you move your mouse on and off the screen we want to pause
     * the game.
     */
    public void pauseGame(boolean state) {
        ...
    }

    /**
     * Kill an alien and get 5 points!
     */
    public void hitAlienScore() { 
	//Add 5 to the score
        ...
    }

    /**
     * Get shot and loose 20 points!
     */
    public void shotShip() {
        ...
    }

    /**
     *
     */
    public void startGame() {
        //These two lines may look confusing but basically they start the 
	//game process, i.e. update the display screen every 500ms.
        ...
    }



    /**
     *
     */
    public void paint(Graphics g) {
        ...
    }

    public void update(Graphics g) {
        paint(g);
    } 
    

    
    /**
     *
     */
    public void moveAliens() {
        ...
    }

    /**
     *
     */
    public void run() {
	int count = 0;
        while(true) {
            try {
                Thread.sleep(gameSpeed);
            } catch(InterruptedException ie) {
                //Ignore this exception
            }
	    //If the game is currently running, move the aliens
	    if (!paused) {
		if (count >= 5) {
	            moveAliens();
		    count = 0;
		}
	    }
	    repaint();//Update the screen
	    count ++;

	}
    }

    /**
     * Get a reference to the alien army
     */
    public AlienArmy getAlienArmy() {
        return army;
    }

    /**
     * This is the program entry point
     */
    public static void main(String []args) {
        SpaceInvaders invaders = new SpaceInvaders("Space Invaders");
    }

}
