import java.awt.Color;
import java.awt.Image;
import java.util.Arrays;

/**
 * @author Biao
 * 
 *         创建一个图形类. 其大小为一个 5 x 5 的方阵，用二维数组表示.
 */
public class Shape {
    /**
     * 创建图形类的实例
     * 
     * @param id
     *        : 图形的id
     * @param x
     *        : 以Ground左上角为原点，相对于此原点的x坐标值: 向右为正，向左为负
     * @param y
     *        : 以Ground左上角为原点，相对于此原点的y坐标值: 向上为负，向下为正
     * @param data
     *        : 表示图形的二维数组
     */
    public Shape(int id, int x, int y, Color color, Image image, int[][] data) {
        this.x = x;
        this.y = y;
        this.id = id;
        this.color = color;
        this.image = image;
        this.data = data;
    }

    public int getCellValue(int offsetX, int offsetY) {
        return data[offsetY][offsetX];
    }
    
    public int getRowCount() {
        return 5;
    }
    
    public int getColumnCount() {
        return getRowCount();
    }

    public void moveLeft() {
        --x;
    }

    public void moveRight() {
        ++x;
    }

    public void moveDown() {
        ++y;
    }

    public void moveUp() {
        --y;
    }

    public void rotateLeft() {
        if (id == 0) { return; }
        RotateUtil.rotateSquareMatrix(data, RotateUtil.Direction.LEFT);
    }

    public void rotateRight() {
        if (id == 0) { return; }
        RotateUtil.rotateSquareMatrix(data, RotateUtil.Direction.RIGHT);
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    public int[][] getData() {
        return data;
    }

    public Color getColor() {
        return color;
    }
    
    public Image getImage() {
        return image;
    }

    public void showInConsole() {
        System.out.println("\n-----ID: " + id);
        for (int i = 0; i < data.length; ++i) {
            System.out.println(Arrays.toString(data[i]));
        }
    }

    private int id;
    private int x, y; // 相对于Ground的左上角(0, 0)的值
    private Color color;
    private Image image;
    private int[][] data;
}
