/**
 * @(#)Chess.java
 *
 * Sample Applet application
 *
 * @author 
 * @version 1.00 04/09/27
 */
 
import java.awt.*;
import java.applet.*;

public class Chess extends Applet implements  MouseListener{
	
	private Image[] wPieces;
	private Image[] bPieces; 
	private int[][] board;
	
	public void init() 
	{
		//Initialize white pieces
		wPieces = new Image[7];
		for (int i=1; i<7; i++)
			wPieces[i] = getImage(getCodeBase(), "w"+(i-1)+".GIF");
		//Initialize black pieces
		bPieces = new Image[7];
		for (int i=1; i<7; i++)
			bPieces[i] = getImage(getCodeBase(), "b"+(i-1)+".GIF");
		
		//Initialize Board
		board=new int[8][8];
		for (int i=0;i<8;i++)
		{
			board[i][1]=1;
			board[i][6]=-1;
		}
		board[0][0]=4;
		board[1][0]=2;
		board[2][0]=3;
		board[3][0]=5;
		board[4][0]=6;
		board[5][0]=3;
		board[6][0]=2;
		board[7][0]=4;
		board[0][7]=-4;
		board[1][7]=-2;
		board[2][7]=-3;
		board[3][7]=-5;
		board[4][7]=-6;
		board[5][7]=-3;
		board[6][7]=-2;
		board[7][7]=-4;

		//background=white
		setBackground(Color.white);
		
		addMouseListener(this);
	}

	public void paint(Graphics g) 
	{
		//Draws board
		g.setColor(Color.gray);
		for (int i=0; i<8; i++)
			for (int j=0; j<8; j++)
				if ((j-i) % 2 != 0)
					g.fillRect(i*40,j*40,40,40);
		
		//pieces
		for (int i=0; i<8; i++)
			for (int j=0; j<8; j++)
			{
				if (board[i][j] < 0)
					g.drawImage(bPieces[Math.abs(board[i][j])],i*40,j*40, this);
				if (board[i][j] > 0)
					g.drawImage(wPieces[(board[i][j])],i*40,j*40, this);
			}
	}
	
	public void mouseClicked(MouseEvent e)
	{
		
	}
	
	public void mousePressed(MouseEvent e) {}
	public void mouseReleased(MouseEvent e) {}
	public void mouseEntered(MouseEvent e) {}
	public void mouseExited(MouseEvent e) {}		
}
