import java.awt.*; abstract class Shape { int curX = 5, curY = 10; Color color; World world; int coords[][]; Shape(World world) { this.world = world; } void drawSquare(Graphics g, int x, int y) { g.setColor(color); g.fillRect(x + 1, y + 1, world.squareWidth() - 2, world.squareHeight() - 2); g.setColor(color.brighter()); g.drawLine(x, y + world.squareHeight() - 1, x, y); g.drawLine(x, y, x + world.squareWidth() - 1, y); g.setColor(color.darker()); g.drawLine(x + 1, y + world.squareHeight() - 1, x + world.squareWidth() - 1, y + world.squareHeight() - 1); g.drawLine(x + world.squareWidth() - 1, y + world.squareHeight() - 1, x + world.squareWidth() - 1, y + 1); } void draw(Graphics g) { Dimension size = world.getSize(); int boardTop = (int) size.getHeight() - world.BoardHeight * world.squareHeight(); for (int i = 0; i < 4; ++i) { int x = curX + this.x(i); int y = curY - this.y(i); drawSquare(g, 0 + x * world.squareWidth(), boardTop + (world.BoardHeight - y - 1) * world.squareHeight()); } } private void setX(int index, int x) { coords[index][0] = x; } private void setY(int index, int y) { coords[index][1] = y; } public int x(int index) { return coords[index][0]; } public int y(int index) { return coords[index][1]; } public int minX() { int m = coords[0][0]; for (int i=0; i < 4; i++) { m = Math.min(m, coords[i][0]); } return m; } public int minY() { int m = coords[0][1]; for (int i=0; i < 4; i++) { m = Math.min(m, coords[i][1]); } return m; } boolean tryMove(int newX, int newY) { // for (int i = 0; i < 4; ++i) { // int x = newX + this.x(i); // int y = newY - this.y(i); // if (x < 0 || x >= world.BoardWidth || y < 0 || y >= world.BoardHeight) // return false; // if (world.shapeAt(x, y) != null && ! (world.shapeAt(x, y) instanceof NoShape)) // return false; // } this.curX = newX; this.curY = newY; world.repaint(); return true; } }