import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import javax.swing.Timer;

public class TestSection9 extends Applet implements ActionListener{
	int counter = 0;
	int counter2 = 0;
	int[] cargoX = {1, 1, 1, 1};
	int[] cargoY = {1, 1, 1, 1};
	int[] asteroidX = {1, 1, 1, 1};
	int[] asteroidY = {1, 1, 1, 1};
	int shipX=50;
	int shipY=50;
	boolean[] cargoDrawn = {true, true, true, true};
	boolean lost = false;
	Timer timer;
	Timer timer2 = new Timer(1000, this);
	
	public void init(){
		setSize(400,400);
		timer = new Timer(50, this);
		timer.start();
	}
	
	public void paint(Graphics p){
		counter++;
		
		if(counter < 50){
			shipX++;
			shipY=shipY+2;
		}
		else{
			shipX=50;
			shipY=50;
			lost = !lost;
			counter=0;
		}
		
		p.setColor(Color.BLACK);
		p.fillRect(0, 0, 400, 400);
		
		//####################################
		// CALLING AND TESTING YOUR CODE
		drawShip(shipX, shipY, p);
		
		//####################################
		// CALLING AND TESTING YOUR CODE
		isGameOver(p);
		
		
		
		if(!timer.isRunning() && counter2 < 1){
			timer2.start();
			counter2++;
			
		}
		else if(!timer.isRunning()){
			timer2.stop();
			counter2=0;
			timer.start();
		}
	}
	
	
	//------------------------------------------------------------------
	// method that draws the ship
	public void drawShip(int x, int y, Graphics p){
		//####################################
		// FILL IN YOUR CODE HERE
		//####################################
	}
	
	
	// has the game ended?  If so, stop the timer and respond appropriately.
	public void isGameOver(Graphics p){
		//####################################
		// FILL IN YOUR CODE HERE
		//####################################
	}
	
	//------------------------------------------------------------------
	// method that checks for asteroid collisions with the ship and returns true/false if the game has been lost
	public boolean gameLost(int[] x, int[] y, int shipX, int shipY){
		if(counter == 40 && lost)
			return true;
		else
			return false;
	}
	
	
	//------------------------------------------------------------------
	// method that checks for cargo collisions with the ship and returns true/false if the game has been won
	public boolean gameWon(int[] x, int[] y, boolean[] drawn, int shipX, int shipY){
		if(counter == 40 && !lost)
			return true;
		else
			return false;
	}
	
	
	//----------------------------------------------------------------------------------------------------
	// #####   RESPONSE TO USER INPUT METHODS   #######
	//----------------------------------------------------------------------------------------------------
	
	// timer went off, so repaint the window
	public void actionPerformed(ActionEvent event){
		repaint();
	}
}
