/* @(#)Sawyer_Checkers.java      October 28, 2005*/


import edu.neu.ccs.*;
import edu.neu.ccs.gui.*;
import edu.neu.ccs.codec.*;
import edu.neu.ccs.console.*;
import edu.neu.ccs.filter.*;
import edu.neu.ccs.jpf.*;
import edu.neu.ccs.parser.*;
import edu.neu.ccs.pedagogy.*;
import edu.neu.ccs.quick.*;
import edu.neu.ccs.util.*;


import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.awt.font.*;
import java.awt.image.*;
import javax.swing.*;
import javax.swing.border.*;
import java.io.*;
import java.util.*;
import java.math.*;
import java.beans.*;
import java.lang.reflect.*;
import java.net.URL;
import java.util.regex.*;
import java.text.ParseException;

/*

Brian Sawyer
Honors Seminar
Experiments


--Overall purpose is to eventually design a program for playing checkers (Sawyer_Checkers.java)--

1. to create a 64 tile grid using code from TicTacToe.java

*Completed*       (realy cool visual effect occuring in between tiles!)

Questions and Issues:

What is the purpose of the paintable sequence and paintable component?

Don't completely understand what's happening within makeTiles:
              
                tiles[row][col].move(x, y);    ?????????               

                sequence.appendPaintable(tiles[row][col]); ????????

3.  To have the colors of the tiles alternate between red and black and get rid of the gap between tiles
                
*SUCCESS*

4.  To place a piece on to the board

*SUCCESS*

5.  To place a red piece on every tile in the first two rows.

*SUCCESS*

6.  To place a red piece on every other tile in the first three rows.

*SUCCESS*

7.  To place a black piece on every other tile in the last three rows.

*SUCCESS* 

*/

public class Sawyer_Checkers 
        extends DisplayPanel
{


        /** The size of each tile. */
        public static final int blockSize = 50;
        
        /** The 64 tiles on the game board in a 8x8 array. */
    private TileBox[][] tiles = new TileBox[8][8];
    
    /** The paintable sequence with the 9 tiles on the game board. */
    private PaintableSequence sequence = new PaintableSequence();
    
    /** The game board. */
    private PaintableComponent board = new PaintableComponent(sequence);
    
    /** The bounds of a block. */
    private static final XRect bounds =
        new XRect(0, 0, blockSize, blockSize);
    
    /** The blank tile. */
    private Paintable blank = null;
    
    /** The piece. */
    private XCircle piece =
        new XCircle((blockSize / 2), (blockSize / 2), (blockSize / 2));
    
    /** The red piece. */
    private Paintable redPiece =
                new ShapePaintable(piece, PaintMode.FILL, Color.red);
    
    /** The black piece. */
    private Paintable blackPiece =
        new ShapePaintable(piece, PaintMode.FILL, Color.black);
    
    /** The contents of the main panel in the GUI. */
    private Object[] mainStuff = {board};
    
    /** The main panel in the GUI. */    
    private TablePanel mainPanel =
        new TablePanel(
            mainStuff, VERTICAL, CENTER);
    
    /** The constructor. */
    public Sawyer_Checkers() {
        makeBlank();
        makeTiles();
        placeRedPieces();
        placeBlackPieces();
        
        add(mainPanel);
        
        frame ("Checkers");
    }
    
    /** Makes the blank block. */
    private void makeBlank() {
        blank = new ShapePaintable();
        blank.setDefaultBounds2D(bounds);
    }
       
    private void makeTiles() {
        int spacing = blockSize;
                
        for (int row = 0; row < 8; row++)
            for (int col = 0; col < 8; col++) {
                tiles[row][col] = new TileBox(blank);
                
                if ((row + col) % 2 == 0) {
                        tiles[row][col].setBackgroundPaint(Colors.cornsilk);
                }
                else {
                        tiles[row][col].setBackgroundPaint(Colors.forestgreen);
                }
                
                int x = spacing * col;
                int y = spacing * row;
                
                tiles[row][col].move(x, y);
                
                sequence.appendPaintable(tiles[row][col]);
            }
    }
    
    private void placeRedPieces() {
                        
        for (int row = 0; row < 3; row++)
                for (int col = 0; col < 8; col++) {
                        
                        if ((row + col) % 2 == 1) {
                        tiles[row][col].setPaintable(redPiece);
                        }
                }
    }
    
    private void placeBlackPieces() {
                
        for (int row = 5; row < 8; row++)
                for (int col = 0; col < 8; col++) {
                        
                        if ((row + col) % 2 == 1) {
                        tiles[row][col].setPaintable(blackPiece);
                        }
                }
    }
    
        public static void main(String[] args) {
                new Sawyer_Checkers();
        }
}
